diff options
author | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-31 18:15:09 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-31 18:15:09 +0000 |
commit | 6a736e9e6db9c688a1c0ddbb1a56bd9d4785a0ea (patch) | |
tree | 9538533f08a7b8ac719a97791083ab88088177c4 /skia | |
parent | cb90452a7ce186deb3257ca73ec169d3a91f8f36 (diff) | |
download | chromium_src-6a736e9e6db9c688a1c0ddbb1a56bd9d4785a0ea.zip chromium_src-6a736e9e6db9c688a1c0ddbb1a56bd9d4785a0ea.tar.gz chromium_src-6a736e9e6db9c688a1c0ddbb1a56bd9d4785a0ea.tar.bz2 |
implement MakeOpaque at the canvas level, respecting matrix and clip
Review URL: http://codereview.chromium.org/7799023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99009 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r-- | skia/ext/bitmap_platform_device.cc | 62 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_linux.h | 2 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_mac.h | 1 | ||||
-rw-r--r-- | skia/ext/bitmap_platform_device_win.h | 1 | ||||
-rw-r--r-- | skia/ext/platform_canvas.cc | 19 | ||||
-rw-r--r-- | skia/ext/platform_device.h | 3 |
6 files changed, 16 insertions, 72 deletions
diff --git a/skia/ext/bitmap_platform_device.cc b/skia/ext/bitmap_platform_device.cc index 05037c6..91b419a 100644 --- a/skia/ext/bitmap_platform_device.cc +++ b/skia/ext/bitmap_platform_device.cc @@ -7,65 +7,3 @@ #include "skia/ext/bitmap_platform_device_data.h" #include "third_party/skia/include/core/SkUtils.h" -namespace { - -// Constrains position and size to fit within available_size. If |size| is -1, -// all the available_size is used. Returns false if the position is out of -// available_size. -bool Constrain(int available_size, int* position, int *size) { - if (*size < -2) - return false; - - if (*position < 0) { - if (*size != -1) - *size += *position; - *position = 0; - } - if (*size == 0 || *position >= available_size) - return false; - - if (*size > 0) { - int overflow = (*position + *size) - available_size; - if (overflow > 0) { - *size -= overflow; - } - } else { - // Fill up available size. - *size = available_size - *position; - } - return true; -} - -} // namespace - -namespace skia { - -void BitmapPlatformDevice::MakeOpaque(int x, int y, int width, int height) { - const SkBitmap& bitmap = accessBitmap(true); - SkASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config); - - // FIXME(brettw): This is kind of lame, we shouldn't be dealing with - // transforms at this level. Probably there should be a PlatformCanvas - // function that does the transform (using the actual transform not just the - // translation) and calls us with the transformed rect. - const SkMatrix& matrix = data_->transform(); - int bitmap_start_x = SkScalarRound(matrix.getTranslateX()) + x; - int bitmap_start_y = SkScalarRound(matrix.getTranslateY()) + y; - - if (Constrain(bitmap.width(), &bitmap_start_x, &width) && - Constrain(bitmap.height(), &bitmap_start_y, &height)) { - SkAutoLockPixels lock(bitmap); - SkASSERT(bitmap.rowBytes() % sizeof(uint32_t) == 0u); - size_t row_words = bitmap.rowBytes() / sizeof(uint32_t); - // Set data to the first pixel to be modified. - uint32_t* data = bitmap.getAddr32(0, 0) + (bitmap_start_y * row_words) + - bitmap_start_x; - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) - data[j] |= (0xFF << SK_A32_SHIFT); - data += row_words; - } - } -} - -} diff --git a/skia/ext/bitmap_platform_device_linux.h b/skia/ext/bitmap_platform_device_linux.h index 57c12ce..80f4793 100644 --- a/skia/ext/bitmap_platform_device_linux.h +++ b/skia/ext/bitmap_platform_device_linux.h @@ -77,8 +77,6 @@ class BitmapPlatformDevice : public PlatformDevice, public SkDevice { static BitmapPlatformDevice* Create(int width, int height, bool is_opaque, uint8_t* data); - virtual void MakeOpaque(int x, int y, int width, int height) OVERRIDE; - // Overridden from SkDevice: virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, const SkClipStack&) OVERRIDE; diff --git a/skia/ext/bitmap_platform_device_mac.h b/skia/ext/bitmap_platform_device_mac.h index da14528..baa99ad 100644 --- a/skia/ext/bitmap_platform_device_mac.h +++ b/skia/ext/bitmap_platform_device_mac.h @@ -44,7 +44,6 @@ class BitmapPlatformDevice : public PlatformDevice, public SkDevice { virtual CGContextRef GetBitmapContext(); virtual void DrawToNativeContext(CGContextRef context, int x, int y, const CGRect* src_rect) OVERRIDE; - virtual void MakeOpaque(int x, int y, int width, int height) OVERRIDE; // SkDevice overrides virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region, diff --git a/skia/ext/bitmap_platform_device_win.h b/skia/ext/bitmap_platform_device_win.h index 5a5e466..a5415c9 100644 --- a/skia/ext/bitmap_platform_device_win.h +++ b/skia/ext/bitmap_platform_device_win.h @@ -52,7 +52,6 @@ class SK_API BitmapPlatformDevice : public PlatformDevice, public SkDevice { virtual void DrawToNativeContext(HDC dc, int x, int y, const RECT* src_rect) OVERRIDE; - virtual void MakeOpaque(int x, int y, int width, int height) OVERRIDE; // Loads the given transform and clipping region into the HDC. This is // overridden from SkDevice. diff --git a/skia/ext/platform_canvas.cc b/skia/ext/platform_canvas.cc index 279af45..f4510744 100644 --- a/skia/ext/platform_canvas.cc +++ b/skia/ext/platform_canvas.cc @@ -76,10 +76,23 @@ void DrawToNativeContext(SkCanvas* canvas, PlatformSurface context, int x, platform_device->DrawToNativeContext(context, x, y, src_rect); } +static SkPMColor MakeOpaqueXfermodeProc(SkPMColor src, SkPMColor dst) { + return dst | (0xFF << SK_A32_SHIFT); +} + void MakeOpaque(SkCanvas* canvas, int x, int y, int width, int height) { - PlatformDevice* platform_device = GetPlatformDevice(GetTopDevice(*canvas)); - if (platform_device) - platform_device->MakeOpaque(x, y, width, height); + if (width <= 0 || height <= 0) + return; + + SkRect rect; + rect.setXYWH(SkIntToScalar(x), SkIntToScalar(y), + SkIntToScalar(width), SkIntToScalar(height)); + SkPaint paint; + // so we don't draw anything on a device that ignores xfermodes + paint.setColor(0); + // install our custom mode + paint.setXfermode(new SkProcXfermode(MakeOpaqueXfermodeProc))->unref(); + canvas->drawRect(rect, paint); } } // namespace skia diff --git a/skia/ext/platform_device.h b/skia/ext/platform_device.h index 55ef1f8..2e441be 100644 --- a/skia/ext/platform_device.h +++ b/skia/ext/platform_device.h @@ -109,9 +109,6 @@ class SK_API PlatformDevice { virtual void DrawToNativeContext(PlatformSurface surface, int x, int y, const PlatformRect* src_rect) = 0; - // Sets the opacity of each pixel in the specified region to be opaque. - virtual void MakeOpaque(int x, int y, int width, int height) { } - // Returns if GDI is allowed to render text to this device. virtual bool IsNativeFontRenderingAllowed(); |