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
This commit is contained in:
@@ -41,11 +41,7 @@ class BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinuxData
|
|||||||
// required so that we can call the base class' constructor with the pixel
|
// required so that we can call the base class' constructor with the pixel
|
||||||
// data.
|
// data.
|
||||||
BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create(
|
BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create(
|
||||||
int width, int height, bool is_opaque) {
|
int width, int height, bool is_opaque, cairo_surface_t* surface) {
|
||||||
cairo_surface_t* surface =
|
|
||||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
|
||||||
width, height);
|
|
||||||
|
|
||||||
SkBitmap bitmap;
|
SkBitmap bitmap;
|
||||||
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height,
|
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height,
|
||||||
cairo_image_surface_get_stride(surface));
|
cairo_image_surface_get_stride(surface));
|
||||||
@@ -63,6 +59,24 @@ BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create(
|
|||||||
(bitmap, new BitmapPlatformDeviceLinuxData(surface));
|
(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
|
// 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.
|
// data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
|
||||||
BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(
|
BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(
|
||||||
|
@@ -62,6 +62,11 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
|
|||||||
/// Static constructor. I don't understand this, it's just a copy of the mac
|
/// Static constructor. I don't understand this, it's just a copy of the mac
|
||||||
static BitmapPlatformDeviceLinux* Create(int width, int height,
|
static BitmapPlatformDeviceLinux* Create(int width, int height,
|
||||||
bool is_opaque);
|
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;
|
// Create a BitmapPlatformDeviceLinux from an already constructed bitmap;
|
||||||
// you should probably be using Create(). This may become private later if
|
// you should probably be using Create(). This may become private later if
|
||||||
|
@@ -8,6 +8,8 @@
|
|||||||
#include "skia/ext/bitmap_platform_device_linux.h"
|
#include "skia/ext/bitmap_platform_device_linux.h"
|
||||||
#include "SkTypes.h"
|
#include "SkTypes.h"
|
||||||
|
|
||||||
|
#include <cairo/cairo.h>
|
||||||
|
|
||||||
namespace skia {
|
namespace skia {
|
||||||
|
|
||||||
PlatformCanvasLinux::PlatformCanvasLinux() : SkCanvas() {
|
PlatformCanvasLinux::PlatformCanvasLinux() : SkCanvas() {
|
||||||
@@ -52,4 +54,9 @@ SkDevice* PlatformCanvasLinux::createPlatformDevice(int width,
|
|||||||
return BitmapPlatformDeviceLinux::Create(width, height, is_opaque);
|
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
|
} // namespace skia
|
||||||
|
@@ -5,6 +5,8 @@
|
|||||||
#ifndef SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
|
#ifndef SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
|
||||||
#define SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
|
#define SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "skia/ext/platform_device_linux.h"
|
#include "skia/ext/platform_device_linux.h"
|
||||||
|
|
||||||
namespace skia {
|
namespace skia {
|
||||||
@@ -21,6 +23,9 @@ class PlatformCanvasLinux : public SkCanvas {
|
|||||||
// If you use the version with no arguments, you MUST call initialize()
|
// If you use the version with no arguments, you MUST call initialize()
|
||||||
PlatformCanvasLinux();
|
PlatformCanvasLinux();
|
||||||
PlatformCanvasLinux(int width, int height, bool is_opaque);
|
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();
|
virtual ~PlatformCanvasLinux();
|
||||||
|
|
||||||
// For two-part init, call if you use the no-argument constructor above
|
// 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.
|
// a Linux version is added for compatibility.
|
||||||
PlatformDeviceLinux& getTopPlatformDevice() const;
|
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:
|
protected:
|
||||||
// Creates a device store for use by the canvas. We override this so that
|
// 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
|
// the device is always our own so we know that we can use GDI operations
|
||||||
|
Reference in New Issue
Block a user