diff options
author | halcanary@google.com <halcanary@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-06 00:45:59 +0000 |
---|---|---|
committer | halcanary@google.com <halcanary@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-06 00:45:59 +0000 |
commit | 915f61abf2f0e5ad93f520b8efaa3394cc564ba8 (patch) | |
tree | 5f83216be97d65bf4d821c5c4214918f6c2c0ab1 /skia | |
parent | 59ca4da2ee9cf71249571594d4dbd68cc79effd0 (diff) | |
download | chromium_src-915f61abf2f0e5ad93f520b8efaa3394cc564ba8.zip chromium_src-915f61abf2f0e5ad93f520b8efaa3394cc564ba8.tar.gz chromium_src-915f61abf2f0e5ad93f520b8efaa3394cc564ba8.tar.bz2 |
Use bitmap.installPixels() for BitmapPlatformDevice
Replace
bitmap.setConfig(...);bitmap.setPixelRef(SkMallocPixelRef::NewWithProc(...))
with the much simpler
bitmap.installPixels(...).
Motivations: We wish to remove code refering to SkPixelRefs,
hiding this Skia implementation detail from the Skia clients.
See: https://codereview.chromium.org/151723002
Review URL: https://codereview.chromium.org/146693004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249185 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r-- | skia/ext/bitmap_platform_device_cairo.cc | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/skia/ext/bitmap_platform_device_cairo.cc b/skia/ext/bitmap_platform_device_cairo.cc index 3fc4a31..1608354 100644 --- a/skia/ext/bitmap_platform_device_cairo.cc +++ b/skia/ext/bitmap_platform_device_cairo.cc @@ -4,7 +4,6 @@ #include "skia/ext/bitmap_platform_device_cairo.h" #include "skia/ext/platform_canvas.h" -#include "third_party/skia/include/core/SkMallocPixelRef.h" #if defined(OS_OPENBSD) #include <cairo.h> @@ -17,30 +16,28 @@ namespace skia { namespace { void CairoSurfaceReleaseProc(void*, void* context) { - if (context) - cairo_surface_destroy(static_cast<cairo_surface_t*>(context)); + SkASSERT(context); + cairo_surface_destroy(static_cast<cairo_surface_t*>(context)); } -// Returns a SkPixelRef that is backed by a Cairo surface. The -// SkPixelRef takes ownership of the passed-in surface and will call +// Back the destination bitmap by a Cairo surface. The bitmap's +// pixelRef takes ownership of the passed-in surface and will call // cairo_surface_destroy() upon destruction. -SkPixelRef* CreateCairoSurfacePixelRef(cairo_surface_t* surface, - bool is_opaque) { +bool InstallCairoSurfacePixels(SkBitmap* dst, + cairo_surface_t* surface, + bool is_opaque) { + SkASSERT(dst); if (!surface) { - return NULL; + return false; } - SkImageInfo info = { - cairo_image_surface_get_width(surface), - cairo_image_surface_get_height(surface), - kPMColor_SkColorType, - is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType - }; - return SkMallocPixelRef::NewWithProc(info, - cairo_image_surface_get_stride(surface), - NULL, - cairo_image_surface_get_data(surface), - &CairoSurfaceReleaseProc, - static_cast<void*>(surface)); + SkImageInfo info + = SkImageInfo::MakeN32Premul(cairo_image_surface_get_width(surface), + cairo_image_surface_get_height(surface)); + return dst->installPixels(info, + cairo_image_surface_get_data(surface), + cairo_image_surface_get_stride(surface), + &CairoSurfaceReleaseProc, + static_cast<void*>(surface)); } void LoadMatrixToContext(cairo_t* context, const SkMatrix& matrix) { @@ -102,11 +99,10 @@ BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, return NULL; } - RefPtr<SkPixelRef> pixel_ref = AdoptRef(CreateCairoSurfacePixelRef(surface, - is_opaque)); SkBitmap bitmap; - bitmap.setConfig(pixel_ref->info(), cairo_image_surface_get_stride(surface)); - bitmap.setPixelRef(pixel_ref.get()); + if (!InstallCairoSurfacePixels(&bitmap, surface, is_opaque)) { + return NULL; + } // The device object will take ownership of the graphics context. return new BitmapPlatformDevice(bitmap, surface); @@ -220,10 +216,7 @@ bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { cairo_surface_destroy(surf); return false; } - RefPtr<SkPixelRef> pixel_ref = AdoptRef(CreateCairoSurfacePixelRef(surf, is_opaque)); - bitmap_.setConfig(pixel_ref->info(), stride); - bitmap_.setPixelRef(pixel_ref.get()); - return true; + return InstallCairoSurfacePixels(&bitmap_, surf, is_opaque); } } // namespace skia |