This source file includes following definitions.
- Create
- CreateAndClear
- Create
- onCreateDevice
- BeginPlatformPaint
- DrawToNativeContext
- CreatePlatformCanvas
- Allocate
#include "skia/ext/bitmap_platform_device_skia.h"
#include "skia/ext/platform_canvas.h"
namespace skia {
BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
bool is_opaque) {
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0,
is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
if (bitmap.allocPixels()) {
if (!is_opaque)
bitmap.eraseARGB(0, 0, 0, 0);
return new BitmapPlatformDevice(bitmap);
}
return NULL;
}
BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width,
int height,
bool is_opaque) {
BitmapPlatformDevice* device = Create(width, height, is_opaque);
if (!is_opaque)
device->clear(0);
return device;
}
BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
bool is_opaque,
uint8_t* data) {
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0,
is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
if (data)
bitmap.setPixels(data);
else if (!bitmap.allocPixels())
return NULL;
return new BitmapPlatformDevice(bitmap);
}
BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap)
: SkBitmapDevice(bitmap) {
SetPlatformDevice(this, this);
}
BitmapPlatformDevice::~BitmapPlatformDevice() {
}
SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const SkImageInfo& info,
Usage ) {
SkASSERT(info.colorType() == kPMColor_SkColorType);
return BitmapPlatformDevice::Create(info.width(), info.height(),
info.isOpaque());
}
PlatformSurface BitmapPlatformDevice::BeginPlatformPaint() {
return accessBitmap(true).getPixels();
}
void BitmapPlatformDevice::DrawToNativeContext(
PlatformSurface surface, int x, int y, const PlatformRect* src_rect) {
SkASSERT(false);
}
SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque,
uint8_t* data, OnFailureType failureType) {
skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef(
BitmapPlatformDevice::Create(width, height, is_opaque, data));
return CreateCanvas(dev, failureType);
}
PlatformBitmap::~PlatformBitmap() {
}
bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) {
bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0,
is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
if (!bitmap_.allocPixels())
return false;
surface_ = bitmap_.getPixels();
return true;
}
}