Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "gfxQuartzImageSurface.h" |
michael@0 | 7 | #include "gfxImageSurface.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "cairo-quartz-image.h" |
michael@0 | 10 | |
michael@0 | 11 | gfxQuartzImageSurface::gfxQuartzImageSurface(gfxImageSurface *imageSurface) |
michael@0 | 12 | { |
michael@0 | 13 | if (imageSurface->CairoSurface() == nullptr) |
michael@0 | 14 | return; |
michael@0 | 15 | |
michael@0 | 16 | cairo_surface_t *surf = cairo_quartz_image_surface_create (imageSurface->CairoSurface()); |
michael@0 | 17 | Init (surf); |
michael@0 | 18 | mSize = ComputeSize(); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | gfxQuartzImageSurface::gfxQuartzImageSurface(cairo_surface_t *csurf) |
michael@0 | 22 | { |
michael@0 | 23 | Init (csurf, true); |
michael@0 | 24 | mSize = ComputeSize(); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | gfxQuartzImageSurface::~gfxQuartzImageSurface() |
michael@0 | 28 | { |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | gfxIntSize |
michael@0 | 32 | gfxQuartzImageSurface::ComputeSize() |
michael@0 | 33 | { |
michael@0 | 34 | if (mSurfaceValid) { |
michael@0 | 35 | cairo_surface_t* isurf = cairo_quartz_image_surface_get_image(mSurface); |
michael@0 | 36 | if (isurf) { |
michael@0 | 37 | return gfxIntSize(cairo_image_surface_get_width(isurf), |
michael@0 | 38 | cairo_image_surface_get_height(isurf)); |
michael@0 | 39 | } |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | // If we reach here then something went wrong. Just use the same default |
michael@0 | 43 | // value as gfxASurface::GetSize. |
michael@0 | 44 | return gfxIntSize(-1, -1); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | int32_t |
michael@0 | 48 | gfxQuartzImageSurface::KnownMemoryUsed() |
michael@0 | 49 | { |
michael@0 | 50 | // This surface doesn't own any memory itself, but we want to report here the |
michael@0 | 51 | // amount of memory that the surface it wraps uses. |
michael@0 | 52 | nsRefPtr<gfxImageSurface> imgSurface = GetAsImageSurface(); |
michael@0 | 53 | if (imgSurface) |
michael@0 | 54 | return imgSurface->KnownMemoryUsed(); |
michael@0 | 55 | return 0; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | already_AddRefed<gfxImageSurface> |
michael@0 | 59 | gfxQuartzImageSurface::GetAsImageSurface() |
michael@0 | 60 | { |
michael@0 | 61 | if (!mSurfaceValid) |
michael@0 | 62 | return nullptr; |
michael@0 | 63 | |
michael@0 | 64 | cairo_surface_t *isurf = cairo_quartz_image_surface_get_image (CairoSurface()); |
michael@0 | 65 | if (!isurf) { |
michael@0 | 66 | NS_WARNING ("Couldn't obtain an image surface from a QuartzImageSurface?!"); |
michael@0 | 67 | return nullptr; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | nsRefPtr<gfxImageSurface> result = gfxASurface::Wrap(isurf).downcast<gfxImageSurface>(); |
michael@0 | 71 | result->SetOpaqueRect(GetOpaqueRect()); |
michael@0 | 72 | |
michael@0 | 73 | return result.forget(); |
michael@0 | 74 | } |