#include "base/mac/mac_util.h"
#include "base/memory/ref_counted.h"
-#include "skia/ext/bitmap_platform_device_data.h"
+#include "skia/ext/bitmap_platform_device.h"
#include "skia/ext/platform_canvas.h"
#include "skia/ext/skia_utils_mac.h"
#include "third_party/skia/include/core/SkMatrix.h"
} // namespace
-BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData(
- CGContextRef bitmap)
- : bitmap_context_(bitmap),
- config_dirty_(true), // Want to load the config next time.
- transform_(SkMatrix::I()) {
- SkASSERT(bitmap_context_);
- // Initialize the clip region to the entire bitmap.
-
- SkIRect rect;
- rect.set(0, 0,
- CGBitmapContextGetWidth(bitmap_context_),
- CGBitmapContextGetHeight(bitmap_context_));
- clip_region_ = SkRegion(rect);
- CGContextRetain(bitmap_context_);
- // We must save the state once so that we can use the restore/save trick
- // in LoadConfig().
- CGContextSaveGState(bitmap_context_);
-}
-
-BitmapPlatformDevice::BitmapPlatformDeviceData::~BitmapPlatformDeviceData() {
- if (bitmap_context_)
- CGContextRelease(bitmap_context_);
-}
-
-void BitmapPlatformDevice::BitmapPlatformDeviceData::ReleaseBitmapContext() {
+void BitmapPlatformDevice::ReleaseBitmapContext() {
SkASSERT(bitmap_context_);
CGContextRelease(bitmap_context_);
bitmap_context_ = NULL;
}
-void BitmapPlatformDevice::BitmapPlatformDeviceData::SetMatrixClip(
+void BitmapPlatformDevice::SetMatrixClip(
const SkMatrix& transform,
const SkRegion& region) {
transform_ = transform;
config_dirty_ = true;
}
-void BitmapPlatformDevice::BitmapPlatformDeviceData::LoadConfig() {
+void BitmapPlatformDevice::LoadConfig() {
if (!config_dirty_ || !bitmap_context_)
return; // Nothing to do.
config_dirty_ = false;
} else
CGContextRetain(context);
- BitmapPlatformDevice* rv = new BitmapPlatformDevice(
- skia::AdoptRef(new BitmapPlatformDeviceData(context)), bitmap);
+ BitmapPlatformDevice* rv = new BitmapPlatformDevice(context, bitmap);
// The device object took ownership of the graphics context with its own
// CGContextRetain call.
bool is_opaque) {
BitmapPlatformDevice* device = Create(NULL, width, height, is_opaque);
if (!is_opaque)
- device->accessBitmap(true).eraseARGB(0, 0, 0, 0);
+ device->clear(0);
return device;
}
// The device will own the bitmap, which corresponds to also owning the pixel
// data. Therefore, we do not transfer ownership to the SkBitmapDevice's bitmap.
BitmapPlatformDevice::BitmapPlatformDevice(
- const skia::RefPtr<BitmapPlatformDeviceData>& data, const SkBitmap& bitmap)
+ CGContextRef context, const SkBitmap& bitmap)
: SkBitmapDevice(bitmap),
- data_(data) {
+ bitmap_context_(context),
+ config_dirty_(true), // Want to load the config next time.
+ transform_(SkMatrix::I()) {
SetPlatformDevice(this, this);
+ SkASSERT(bitmap_context_);
+ // Initialize the clip region to the entire bitmap.
+
+ SkIRect rect;
+ rect.set(0, 0,
+ CGBitmapContextGetWidth(bitmap_context_),
+ CGBitmapContextGetHeight(bitmap_context_));
+ clip_region_ = SkRegion(rect);
+ CGContextRetain(bitmap_context_);
+ // We must save the state once so that we can use the restore/save trick
+ // in LoadConfig().
+ CGContextSaveGState(bitmap_context_);
}
BitmapPlatformDevice::~BitmapPlatformDevice() {
+ if (bitmap_context_)
+ CGContextRelease(bitmap_context_);
}
CGContextRef BitmapPlatformDevice::GetBitmapContext() {
- data_->LoadConfig();
- return data_->bitmap_context();
+ LoadConfig();
+ return bitmap_context_;
}
void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform,
const SkRegion& region,
const SkClipStack&) {
- data_->SetMatrixClip(transform, region);
+ SetMatrixClip(transform, region);
}
void BitmapPlatformDevice::DrawToNativeContext(CGContextRef context, int x,
int y, const CGRect* src_rect) {
bool created_dc = false;
- if (!data_->bitmap_context()) {
+ if (!bitmap_context_) {
created_dc = true;
GetBitmapContext();
}
// this should not make a copy of the bits, since we're not doing
// anything to trigger copy on write
- CGImageRef image = CGBitmapContextCreateImage(data_->bitmap_context());
+ CGImageRef image = CGBitmapContextCreateImage(bitmap_context_);
CGRect bounds;
bounds.origin.x = x;
bounds.origin.y = y;
CGImageRelease(image);
if (created_dc)
- data_->ReleaseBitmapContext();
+ ReleaseBitmapContext();
}
SkBaseDevice* BitmapPlatformDevice::onCreateCompatibleDevice(