summaryrefslogtreecommitdiffstats
path: root/skia/ext
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-02 00:01:47 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-02 00:01:47 +0000
commit56164f0194e23d5df428bcfa278556cf96ed639a (patch)
treed52597fb318936393db91d2ad14972ab74443639 /skia/ext
parentaa82299b37136a5de8a842d35eb893be6eb995f8 (diff)
downloadchromium_src-56164f0194e23d5df428bcfa278556cf96ed639a.zip
chromium_src-56164f0194e23d5df428bcfa278556cf96ed639a.tar.gz
chromium_src-56164f0194e23d5df428bcfa278556cf96ed639a.tar.bz2
Move BitmapPlatformDevice::makeOpaque into a shared file
so it's implemented on all platforms. This makes the method available on Linux+Mac, while removing BitmapPlatformDevice::processPixels from Mac (doesn't appear to be used anywhere). Review URL: http://codereview.chromium.org/3227007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58274 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext')
-rw-r--r--skia/ext/bitmap_platform_device.cc71
-rw-r--r--skia/ext/bitmap_platform_device_linux.h2
-rw-r--r--skia/ext/bitmap_platform_device_mac.cc49
-rw-r--r--skia/ext/bitmap_platform_device_mac.h5
-rw-r--r--skia/ext/bitmap_platform_device_win.cc59
-rw-r--r--skia/ext/platform_device_mac.h12
6 files changed, 74 insertions, 124 deletions
diff --git a/skia/ext/bitmap_platform_device.cc b/skia/ext/bitmap_platform_device.cc
new file mode 100644
index 0000000..bec8a63
--- /dev/null
+++ b/skia/ext/bitmap_platform_device.cc
@@ -0,0 +1,71 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "skia/ext/bitmap_platform_device.h"
+
+#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 172a0f1..1c6579cc 100644
--- a/skia/ext/bitmap_platform_device_linux.h
+++ b/skia/ext/bitmap_platform_device_linux.h
@@ -79,6 +79,8 @@ class BitmapPlatformDevice : public PlatformDevice {
// A stub copy constructor. Needs to be properly implemented.
BitmapPlatformDevice(const BitmapPlatformDevice& other);
+ virtual void makeOpaque(int x, int y, int width, int height);
+
// Bitmaps aren't vector graphics.
virtual bool IsVectorial() { return false; }
diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc
index afb02e7..841c75a 100644
--- a/skia/ext/bitmap_platform_device_mac.cc
+++ b/skia/ext/bitmap_platform_device_mac.cc
@@ -19,33 +19,6 @@ namespace skia {
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;
-}
-
static CGContextRef CGContextForData(void* data, int width, int height) {
#define HAS_ARGB_SHIFTS(a, r, g, b) \
(SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \
@@ -279,26 +252,4 @@ void BitmapPlatformDevice::onAccessBitmap(SkBitmap*) {
// Not needed in CoreGraphics
}
-void BitmapPlatformDevice::processPixels(int x, int y,
- int width, int height,
- adjustAlpha adjustor) {
- const SkBitmap& bitmap = accessBitmap(true);
- const SkMatrix& matrix = data_->transform();
- int bitmap_start_x = SkScalarRound(matrix.getTranslateX()) + x;
- int bitmap_start_y = SkScalarRound(matrix.getTranslateY()) + y;
-
- SkAutoLockPixels lock(bitmap);
- if (Constrain(bitmap.width(), &bitmap_start_x, &width) &&
- Constrain(bitmap.height(), &bitmap_start_y, &height)) {
- uint32_t* data = bitmap.getAddr32(0, 0);
- size_t row_words = bitmap.rowBytes() / 4;
- for (int i = 0; i < height; i++) {
- size_t offset = (i + bitmap_start_y) * row_words + bitmap_start_x;
- for (int j = 0; j < width; j++) {
- adjustor(data + offset + j);
- }
- }
- }
-}
-
} // namespace skia
diff --git a/skia/ext/bitmap_platform_device_mac.h b/skia/ext/bitmap_platform_device_mac.h
index a775a08..195dca8 100644
--- a/skia/ext/bitmap_platform_device_mac.h
+++ b/skia/ext/bitmap_platform_device_mac.h
@@ -58,6 +58,7 @@ class BitmapPlatformDevice : public PlatformDevice {
virtual void DrawToContext(CGContextRef context, int x, int y,
const CGRect* src_rect);
+ virtual void makeOpaque(int x, int y, int width, int height);
virtual bool IsVectorial() { return false; }
// Returns the color value at the specified location. This does not
@@ -78,10 +79,6 @@ class BitmapPlatformDevice : public PlatformDevice {
// starts accessing pixel data.
virtual void onAccessBitmap(SkBitmap*);
- virtual void processPixels(int x, int y,
- int width, int height,
- adjustAlpha adjustor);
-
// Data associated with this device, guaranteed non-null. We hold a reference
// to this object.
BitmapPlatformDeviceData* data_;
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc
index 76f0ea3..490ad77 100644
--- a/skia/ext/bitmap_platform_device_win.cc
+++ b/skia/ext/bitmap_platform_device_win.cc
@@ -15,37 +15,6 @@
namespace skia {
-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
-
BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData(
HBITMAP hbitmap)
: bitmap_context_(hbitmap),
@@ -286,34 +255,6 @@ void BitmapPlatformDevice::drawToHDC(HDC dc, int x, int y,
data_->ReleaseBitmapDC();
}
-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;
- }
- }
-}
-
// Returns the color value at the specified location.
SkColor BitmapPlatformDevice::getColorAt(int x, int y) {
const SkBitmap& bitmap = accessBitmap(false);
diff --git a/skia/ext/platform_device_mac.h b/skia/ext/platform_device_mac.h
index a32667f..258e448 100644
--- a/skia/ext/platform_device_mac.h
+++ b/skia/ext/platform_device_mac.h
@@ -60,18 +60,6 @@ class PlatformDevice : public SkDevice {
// Loads the specified Skia transform into the device context
static void LoadTransformToCGContext(CGContextRef context,
const SkMatrix& matrix);
-
- // Function pointer used by the processPixels method for setting the alpha
- // value of a particular pixel.
- typedef void (*adjustAlpha)(uint32_t* pixel);
-
- // Loops through each of the pixels in the specified range, invoking
- // adjustor for the alpha value of each pixel.
- virtual void processPixels(int x,
- int y,
- int width,
- int height,
- adjustAlpha adjustor) = 0;
};
} // namespace skia