| Index: skia/ext/bitmap_platform_device_mac.cc
|
| diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc
|
| index e1df85e6807b7f5a4875386c4816dd6ac413766a..06a41390b5db0dc44810b7a373df9537238a49bf 100644
|
| --- a/skia/ext/bitmap_platform_device_mac.cc
|
| +++ b/skia/ext/bitmap_platform_device_mac.cc
|
| @@ -15,7 +15,7 @@
|
| #include "skia/ext/skia_utils_mac.h"
|
| #include "third_party/skia/include/core/SkMatrix.h"
|
| #include "third_party/skia/include/core/SkPath.h"
|
| -#include "third_party/skia/include/core/SkRegion.h"
|
| +#include "third_party/skia/include/core/SkRect.h"
|
| #include "third_party/skia/include/core/SkTypes.h"
|
|
|
| namespace skia {
|
| @@ -77,14 +77,6 @@ void BitmapPlatformDevice::ReleaseBitmapContext() {
|
| bitmap_context_ = NULL;
|
| }
|
|
|
| -void BitmapPlatformDevice::SetMatrixClip(
|
| - const SkMatrix& transform,
|
| - const SkRegion& region) {
|
| - transform_ = transform;
|
| - clip_region_ = region;
|
| - config_dirty_ = true;
|
| -}
|
| -
|
| // Loads the specified Skia transform into the device context
|
| static void LoadTransformToCGContext(CGContextRef context,
|
| const SkMatrix& matrix) {
|
| @@ -118,49 +110,29 @@ static void LoadTransformToCGContext(CGContextRef context,
|
| CGContextConcatCTM(context, cg_matrix);
|
| }
|
|
|
| -// Loads a SkRegion into the CG context.
|
| static void LoadClippingRegionToCGContext(CGContextRef context,
|
| - const SkRegion& region,
|
| + const SkIRect& clip_bounds,
|
| const SkMatrix& transformation) {
|
| - if (region.isEmpty()) {
|
| - // region can be empty, in which case everything will be clipped.
|
| - SkRect rect;
|
| - rect.setEmpty();
|
| - CGContextClipToRect(context, skia::SkRectToCGRect(rect));
|
| - } else if (region.isRect()) {
|
| - // CoreGraphics applies the current transform to clip rects, which is
|
| - // unwanted. Inverse-transform the rect before sending it to CG. This only
|
| - // works for translations and scaling, but not for rotations (but the
|
| - // viewport is never rotated anyway).
|
| - SkMatrix t;
|
| - bool did_invert = transformation.invert(&t);
|
| - if (!did_invert)
|
| - t.reset();
|
| - // Do the transformation.
|
| - SkRect rect;
|
| - rect.set(region.getBounds());
|
| - t.mapRect(&rect);
|
| - SkIRect irect;
|
| - rect.round(&irect);
|
| - CGContextClipToRect(context, skia::SkIRectToCGRect(irect));
|
| - } else {
|
| - // It is complex.
|
| - SkPath path;
|
| - region.getBoundaryPath(&path);
|
| - // Clip. Note that windows clipping regions are not affected by the
|
| - // transform so apply it manually.
|
| - path.transform(transformation);
|
| - // TODO(playmobil): Implement.
|
| - SkASSERT(false);
|
| - // LoadPathToDC(context, path);
|
| - // hrgn = PathToRegion(context);
|
| - }
|
| + // CoreGraphics applies the current transform to clip rects, which is
|
| + // unwanted. Inverse-transform the rect before sending it to CG. This only
|
| + // works for translations and scaling, but not for rotations (but the
|
| + // viewport is never rotated anyway).
|
| + SkMatrix t;
|
| + bool did_invert = transformation.invert(&t);
|
| + if (!did_invert)
|
| + t.reset();
|
| +
|
| + SkRect rect = SkRect::Make(clip_bounds);
|
| + t.mapRect(&rect);
|
| + SkIRect irect;
|
| + rect.round(&irect);
|
| + CGContextClipToRect(context, skia::SkIRectToCGRect(irect));
|
| }
|
|
|
| -void BitmapPlatformDevice::LoadConfig() {
|
| - if (!config_dirty_ || !bitmap_context_)
|
| +void BitmapPlatformDevice::LoadConfig(const SkMatrix& transform,
|
| + const SkIRect& clip_bounds) {
|
| + if (!bitmap_context_)
|
| return; // Nothing to do.
|
| - config_dirty_ = false;
|
|
|
| // We must restore and then save the state of the graphics context since the
|
| // calls to Load the clipping region to the context are strictly cummulative,
|
| @@ -170,8 +142,8 @@ void BitmapPlatformDevice::LoadConfig() {
|
| // calls in LoadClippingRegionToCGContext() with an image mask instead.
|
| CGContextRestoreGState(bitmap_context_);
|
| CGContextSaveGState(bitmap_context_);
|
| - LoadTransformToCGContext(bitmap_context_, transform_);
|
| - LoadClippingRegionToCGContext(bitmap_context_, clip_region_, transform_);
|
| + LoadTransformToCGContext(bitmap_context_, transform);
|
| + LoadClippingRegionToCGContext(bitmap_context_, clip_bounds, transform);
|
| }
|
|
|
|
|
| @@ -252,9 +224,7 @@ BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data,
|
| BitmapPlatformDevice::BitmapPlatformDevice(
|
| CGContextRef context, const SkBitmap& bitmap)
|
| : SkBitmapDevice(bitmap),
|
| - bitmap_context_(context),
|
| - config_dirty_(true), // Want to load the config next time.
|
| - transform_(SkMatrix::I()) {
|
| + bitmap_context_(context) {
|
| SetPlatformDevice(this, this);
|
| SkASSERT(bitmap_context_);
|
| // Initialize the clip region to the entire bitmap.
|
| @@ -263,7 +233,6 @@ BitmapPlatformDevice::BitmapPlatformDevice(
|
| 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().
|
| @@ -275,17 +244,12 @@ BitmapPlatformDevice::~BitmapPlatformDevice() {
|
| CGContextRelease(bitmap_context_);
|
| }
|
|
|
| -CGContextRef BitmapPlatformDevice::GetBitmapContext() {
|
| - LoadConfig();
|
| +CGContextRef BitmapPlatformDevice::GetBitmapContext(const SkMatrix& transform,
|
| + const SkIRect& clip_bounds) {
|
| + LoadConfig(transform, clip_bounds);
|
| return bitmap_context_;
|
| }
|
|
|
| -void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform,
|
| - const SkRegion& region,
|
| - const SkClipStack&) {
|
| - SetMatrixClip(transform, region);
|
| -}
|
| -
|
| SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const CreateInfo& cinfo,
|
| const SkPaint*) {
|
| const SkImageInfo& info = cinfo.fInfo;
|
|
|