X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fskia%2Fext%2Fbitmap_platform_device_mac.cc;h=259dc5926f2268f8442ef947eb80cbaca55eb973;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=8525cd374d724a8563bdcc488b368a49bc37f16a;hpb=4b53d56b8a1db20d4089f6d4f37126d43f907125;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/skia/ext/bitmap_platform_device_mac.cc b/src/skia/ext/bitmap_platform_device_mac.cc index 8525cd3..259dc59 100644 --- a/src/skia/ext/bitmap_platform_device_mac.cc +++ b/src/skia/ext/bitmap_platform_device_mac.cc @@ -9,7 +9,7 @@ #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" @@ -57,37 +57,13 @@ static CGContextRef CGContextForData(void* data, int width, int height) { } // 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; @@ -95,7 +71,7 @@ void BitmapPlatformDevice::BitmapPlatformDeviceData::SetMatrixClip( config_dirty_ = true; } -void BitmapPlatformDevice::BitmapPlatformDeviceData::LoadConfig() { +void BitmapPlatformDevice::LoadConfig() { if (!config_dirty_ || !bitmap_context_) return; // Nothing to do. config_dirty_ = false; @@ -156,8 +132,7 @@ BitmapPlatformDevice* BitmapPlatformDevice::Create(CGContextRef context, } 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. @@ -171,7 +146,7 @@ BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, 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; } @@ -196,37 +171,53 @@ BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data, // 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& 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; @@ -244,7 +235,7 @@ void BitmapPlatformDevice::DrawToNativeContext(CGContextRef context, int x, CGImageRelease(image); if (created_dc) - data_->ReleaseBitmapContext(); + ReleaseBitmapContext(); } SkBaseDevice* BitmapPlatformDevice::onCreateCompatibleDevice(