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