gfx/thebes/gfxQuartzImageSurface.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     6 #include "gfxQuartzImageSurface.h"
     7 #include "gfxImageSurface.h"
     9 #include "cairo-quartz-image.h"
    11 gfxQuartzImageSurface::gfxQuartzImageSurface(gfxImageSurface *imageSurface)
    12 {
    13     if (imageSurface->CairoSurface() == nullptr)
    14         return;
    16     cairo_surface_t *surf = cairo_quartz_image_surface_create (imageSurface->CairoSurface());
    17     Init (surf);
    18     mSize = ComputeSize();
    19 }
    21 gfxQuartzImageSurface::gfxQuartzImageSurface(cairo_surface_t *csurf)
    22 {
    23     Init (csurf, true);
    24     mSize = ComputeSize();
    25 }
    27 gfxQuartzImageSurface::~gfxQuartzImageSurface()
    28 {
    29 }
    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   }
    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 }
    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 }
    58 already_AddRefed<gfxImageSurface>
    59 gfxQuartzImageSurface::GetAsImageSurface()
    60 {
    61     if (!mSurfaceValid)
    62         return nullptr;
    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     }
    70     nsRefPtr<gfxImageSurface> result = gfxASurface::Wrap(isurf).downcast<gfxImageSurface>();
    71     result->SetOpaqueRect(GetOpaqueRect());
    73     return result.forget();
    74 }

mercurial