gfx/thebes/gfxQuartzImageSurface.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxQuartzImageSurface.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "gfxQuartzImageSurface.h"
    1.10 +#include "gfxImageSurface.h"
    1.11 +
    1.12 +#include "cairo-quartz-image.h"
    1.13 +
    1.14 +gfxQuartzImageSurface::gfxQuartzImageSurface(gfxImageSurface *imageSurface)
    1.15 +{
    1.16 +    if (imageSurface->CairoSurface() == nullptr)
    1.17 +        return;
    1.18 +
    1.19 +    cairo_surface_t *surf = cairo_quartz_image_surface_create (imageSurface->CairoSurface());
    1.20 +    Init (surf);
    1.21 +    mSize = ComputeSize();
    1.22 +}
    1.23 +
    1.24 +gfxQuartzImageSurface::gfxQuartzImageSurface(cairo_surface_t *csurf)
    1.25 +{
    1.26 +    Init (csurf, true);
    1.27 +    mSize = ComputeSize();
    1.28 +}
    1.29 +
    1.30 +gfxQuartzImageSurface::~gfxQuartzImageSurface()
    1.31 +{
    1.32 +}
    1.33 +
    1.34 +gfxIntSize
    1.35 +gfxQuartzImageSurface::ComputeSize()
    1.36 +{
    1.37 +  if (mSurfaceValid) {
    1.38 +    cairo_surface_t* isurf = cairo_quartz_image_surface_get_image(mSurface);
    1.39 +    if (isurf) {
    1.40 +      return gfxIntSize(cairo_image_surface_get_width(isurf),
    1.41 +                        cairo_image_surface_get_height(isurf));
    1.42 +    }
    1.43 +  }
    1.44 +
    1.45 +  // If we reach here then something went wrong. Just use the same default
    1.46 +  // value as gfxASurface::GetSize.
    1.47 +  return gfxIntSize(-1, -1);
    1.48 +}
    1.49 +
    1.50 +int32_t
    1.51 +gfxQuartzImageSurface::KnownMemoryUsed()
    1.52 +{
    1.53 +  // This surface doesn't own any memory itself, but we want to report here the
    1.54 +  // amount of memory that the surface it wraps uses.
    1.55 +  nsRefPtr<gfxImageSurface> imgSurface = GetAsImageSurface();
    1.56 +  if (imgSurface)
    1.57 +    return imgSurface->KnownMemoryUsed();
    1.58 +  return 0;
    1.59 +}
    1.60 +
    1.61 +already_AddRefed<gfxImageSurface>
    1.62 +gfxQuartzImageSurface::GetAsImageSurface()
    1.63 +{
    1.64 +    if (!mSurfaceValid)
    1.65 +        return nullptr;
    1.66 +
    1.67 +    cairo_surface_t *isurf = cairo_quartz_image_surface_get_image (CairoSurface());
    1.68 +    if (!isurf) {
    1.69 +        NS_WARNING ("Couldn't obtain an image surface from a QuartzImageSurface?!");
    1.70 +        return nullptr;
    1.71 +    }
    1.72 +
    1.73 +    nsRefPtr<gfxImageSurface> result = gfxASurface::Wrap(isurf).downcast<gfxImageSurface>();
    1.74 +    result->SetOpaqueRect(GetOpaqueRect());
    1.75 +
    1.76 +    return result.forget();
    1.77 +}

mercurial