diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-22 20:20:39 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-22 20:20:39 +0000 |
commit | b49a99cebf7966e4de7a8357b5a759d97ad8e226 (patch) | |
tree | 96db3c4337c0a7433982b195915816878b418526 /skia/ext | |
parent | 67be397e2883b7c03073d8e04a22c4a10e07e0a7 (diff) | |
download | chromium_src-b49a99cebf7966e4de7a8357b5a759d97ad8e226.zip chromium_src-b49a99cebf7966e4de7a8357b5a759d97ad8e226.tar.gz chromium_src-b49a99cebf7966e4de7a8357b5a759d97ad8e226.tar.bz2 |
Linux Skia: add an option to build a canvas from a provided memory buffer
Review URL: http://codereview.chromium.org/18678
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8503 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext')
-rw-r--r-- | skia/ext/bitmap_platform_device_linux.cc | 24 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_linux.h | 5 | ||||
-rw-r--r-- | skia/ext/platform_canvas_linux.cc | 7 | ||||
-rw-r--r-- | skia/ext/platform_canvas_linux.h | 10 |
4 files changed, 41 insertions, 5 deletions
diff --git a/skia/ext/bitmap_platform_device_linux.cc b/skia/ext/bitmap_platform_device_linux.cc index 6f7277e..f6a0e6d 100644 --- a/skia/ext/bitmap_platform_device_linux.cc +++ b/skia/ext/bitmap_platform_device_linux.cc @@ -41,11 +41,7 @@ class BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinuxData // required so that we can call the base class' constructor with the pixel // data. BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( - int width, int height, bool is_opaque) { - cairo_surface_t* surface = - cairo_image_surface_create(CAIRO_FORMAT_ARGB32, - width, height); - + int width, int height, bool is_opaque, cairo_surface_t* surface) { SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, cairo_image_surface_get_stride(surface)); @@ -63,6 +59,24 @@ BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( (bitmap, new BitmapPlatformDeviceLinuxData(surface)); } +BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( + int width, int height, bool is_opaque) { + cairo_surface_t* surface = + cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + width, height); + + return Create(width, height, is_opaque, surface); +} + +BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create( + int width, int height, bool is_opaque, uint8_t* data) { + cairo_surface_t* surface = cairo_image_surface_create_for_data( + data, CAIRO_FORMAT_ARGB32, width, height, + cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width)); + + return Create(width, height, is_opaque, surface); +} + // The device will own the bitmap, which corresponds to also owning the pixel // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( diff --git a/skia/ext/bitmap_platform_device_linux.h b/skia/ext/bitmap_platform_device_linux.h index b4f0c1bc..cfc72e2 100644 --- a/skia/ext/bitmap_platform_device_linux.h +++ b/skia/ext/bitmap_platform_device_linux.h @@ -62,6 +62,11 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux { /// Static constructor. I don't understand this, it's just a copy of the mac static BitmapPlatformDeviceLinux* Create(int width, int height, bool is_opaque); + static BitmapPlatformDeviceLinux* Create(int width, int height, + bool is_opaque, uint8_t* data); + static BitmapPlatformDeviceLinux* Create(int width, int height, + bool is_opaque, + cairo_surface_t* surface); // Create a BitmapPlatformDeviceLinux from an already constructed bitmap; // you should probably be using Create(). This may become private later if diff --git a/skia/ext/platform_canvas_linux.cc b/skia/ext/platform_canvas_linux.cc index 5c14707..d436fd7 100644 --- a/skia/ext/platform_canvas_linux.cc +++ b/skia/ext/platform_canvas_linux.cc @@ -8,6 +8,8 @@ #include "skia/ext/bitmap_platform_device_linux.h" #include "SkTypes.h" +#include <cairo/cairo.h> + namespace skia { PlatformCanvasLinux::PlatformCanvasLinux() : SkCanvas() { @@ -52,4 +54,9 @@ SkDevice* PlatformCanvasLinux::createPlatformDevice(int width, return BitmapPlatformDeviceLinux::Create(width, height, is_opaque); } +// static +size_t PlatformCanvasLinux::StrideForWidth(unsigned width) { + return cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); +} + } // namespace skia diff --git a/skia/ext/platform_canvas_linux.h b/skia/ext/platform_canvas_linux.h index 1a5afe7..5782284 100644 --- a/skia/ext/platform_canvas_linux.h +++ b/skia/ext/platform_canvas_linux.h @@ -5,6 +5,8 @@ #ifndef SKIA_EXT_PLATFORM_CANVAS_LINUX_H_ #define SKIA_EXT_PLATFORM_CANVAS_LINUX_H_ +#include <unistd.h> + #include "skia/ext/platform_device_linux.h" namespace skia { @@ -21,6 +23,9 @@ class PlatformCanvasLinux : public SkCanvas { // If you use the version with no arguments, you MUST call initialize() PlatformCanvasLinux(); PlatformCanvasLinux(int width, int height, bool is_opaque); + // Construct a canvas from the given memory region. The memory is not cleared + // first. @data must be, at least, @height * StrideForWidth(@width) bytes. + PlatformCanvasLinux(int width, int height, bool is_opaque, uint8_t* data); virtual ~PlatformCanvasLinux(); // For two-part init, call if you use the no-argument constructor above @@ -31,6 +36,11 @@ class PlatformCanvasLinux : public SkCanvas { // a Linux version is added for compatibility. PlatformDeviceLinux& getTopPlatformDevice() const; + // Return the stride (length of a line in bytes) for the given width. Because + // we use 32-bits per pixel, this will be roughly 4*width. However, for + // alignment reasons we may wish to increase that. + static size_t StrideForWidth(unsigned width); + protected: // Creates a device store for use by the canvas. We override this so that // the device is always our own so we know that we can use GDI operations |