michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "gfxQuartzImageSurface.h" michael@0: #include "gfxImageSurface.h" michael@0: michael@0: #include "cairo-quartz-image.h" michael@0: michael@0: gfxQuartzImageSurface::gfxQuartzImageSurface(gfxImageSurface *imageSurface) michael@0: { michael@0: if (imageSurface->CairoSurface() == nullptr) michael@0: return; michael@0: michael@0: cairo_surface_t *surf = cairo_quartz_image_surface_create (imageSurface->CairoSurface()); michael@0: Init (surf); michael@0: mSize = ComputeSize(); michael@0: } michael@0: michael@0: gfxQuartzImageSurface::gfxQuartzImageSurface(cairo_surface_t *csurf) michael@0: { michael@0: Init (csurf, true); michael@0: mSize = ComputeSize(); michael@0: } michael@0: michael@0: gfxQuartzImageSurface::~gfxQuartzImageSurface() michael@0: { michael@0: } michael@0: michael@0: gfxIntSize michael@0: gfxQuartzImageSurface::ComputeSize() michael@0: { michael@0: if (mSurfaceValid) { michael@0: cairo_surface_t* isurf = cairo_quartz_image_surface_get_image(mSurface); michael@0: if (isurf) { michael@0: return gfxIntSize(cairo_image_surface_get_width(isurf), michael@0: cairo_image_surface_get_height(isurf)); michael@0: } michael@0: } michael@0: michael@0: // If we reach here then something went wrong. Just use the same default michael@0: // value as gfxASurface::GetSize. michael@0: return gfxIntSize(-1, -1); michael@0: } michael@0: michael@0: int32_t michael@0: gfxQuartzImageSurface::KnownMemoryUsed() michael@0: { michael@0: // This surface doesn't own any memory itself, but we want to report here the michael@0: // amount of memory that the surface it wraps uses. michael@0: nsRefPtr imgSurface = GetAsImageSurface(); michael@0: if (imgSurface) michael@0: return imgSurface->KnownMemoryUsed(); michael@0: return 0; michael@0: } michael@0: michael@0: already_AddRefed michael@0: gfxQuartzImageSurface::GetAsImageSurface() michael@0: { michael@0: if (!mSurfaceValid) michael@0: return nullptr; michael@0: michael@0: cairo_surface_t *isurf = cairo_quartz_image_surface_get_image (CairoSurface()); michael@0: if (!isurf) { michael@0: NS_WARNING ("Couldn't obtain an image surface from a QuartzImageSurface?!"); michael@0: return nullptr; michael@0: } michael@0: michael@0: nsRefPtr result = gfxASurface::Wrap(isurf).downcast(); michael@0: result->SetOpaqueRect(GetOpaqueRect()); michael@0: michael@0: return result.forget(); michael@0: }