summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--skia/ext/bitmap_platform_device_data.h106
-rw-r--r--skia/ext/bitmap_platform_device_linux.cc73
-rw-r--r--skia/ext/bitmap_platform_device_mac.cc70
-rw-r--r--skia/ext/bitmap_platform_device_win.cc61
-rw-r--r--skia/skia.gyp1
5 files changed, 136 insertions, 175 deletions
diff --git a/skia/ext/bitmap_platform_device_data.h b/skia/ext/bitmap_platform_device_data.h
new file mode 100644
index 0000000..36e0ad5
--- /dev/null
+++ b/skia/ext/bitmap_platform_device_data.h
@@ -0,0 +1,106 @@
+// 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.
+
+#ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_DATA_H_
+#define SKIA_EXT_BITMAP_PLATFORM_DEVICE_DATA_H_
+
+#include "skia/ext/bitmap_platform_device.h"
+
+namespace skia {
+
+class BitmapPlatformDevice::BitmapPlatformDeviceData :
+#if defined(WIN32) || defined(__APPLE__)
+ public SkRefCnt {
+#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+ // These objects are reference counted and own a Cairo surface. The surface
+ // is the backing store for a Skia bitmap and we reference count it so that
+ // we can copy BitmapPlatformDevice objects without having to copy all the
+ // image data.
+ public base::RefCounted<BitmapPlatformDeviceData> {
+#endif
+
+ public:
+#if defined(WIN32)
+ typedef HBITMAP PlatformContext;
+#elif defined(__APPLE__)
+ typedef CGContextRef PlatformContext;
+#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+ typedef cairo_t* PlatformContext;
+#endif
+
+#if defined(WIN32) || defined(__APPLE__)
+ explicit BitmapPlatformDeviceData(PlatformContext bitmap);
+#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+ explicit BitmapPlatformDeviceData(cairo_surface_t* surface);
+#endif
+
+#if defined(WIN32)
+ // Create/destroy hdc_, which is the memory DC for our bitmap data.
+ HDC GetBitmapDC();
+ void ReleaseBitmapDC();
+ bool IsBitmapDCCreated() const;
+#endif
+
+#if defined(__APPLE__)
+ void ReleaseBitmapContext() {
+ SkASSERT(bitmap_context_);
+ CGContextRelease(bitmap_context_);
+ bitmap_context_ = NULL;
+ }
+#endif // defined(__APPLE__)
+
+ // Sets the transform and clip operations. This will not update the CGContext,
+ // but will mark the config as dirty. The next call of LoadConfig will
+ // pick up these changes.
+ void SetMatrixClip(const SkMatrix& transform, const SkRegion& region);
+
+ // Loads the current transform and clip into the context. Can be called even
+ // when |bitmap_context_| is NULL (will be a NOP).
+ void LoadConfig();
+
+ const SkMatrix& transform() const {
+ return transform_;
+ }
+
+ PlatformContext bitmap_context() {
+ return bitmap_context_;
+ }
+
+ private:
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+ friend class base::RefCounted<BitmapPlatformDeviceData>;
+#endif
+ virtual ~BitmapPlatformDeviceData();
+
+ // Lazily-created graphics context used to draw into the bitmap.
+ PlatformContext bitmap_context_;
+
+#if defined(WIN32)
+ // Lazily-created DC used to draw into the bitmap, see GetBitmapDC().
+ HDC hdc_;
+#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+ cairo_surface_t *const surface_;
+#endif
+
+ // True when there is a transform or clip that has not been set to the
+ // context. The context is retrieved for every text operation, and the
+ // transform and clip do not change as much. We can save time by not loading
+ // the clip and transform for every one.
+ bool config_dirty_;
+
+ // Translation assigned to the context: we need to keep track of this
+ // separately so it can be updated even if the context isn't created yet.
+ SkMatrix transform_;
+
+ // The current clipping
+ SkRegion clip_region_;
+
+ // Disallow copy & assign.
+ BitmapPlatformDeviceData(const BitmapPlatformDeviceData&);
+ BitmapPlatformDeviceData& operator=(const BitmapPlatformDeviceData&);
+};
+
+} // namespace skia
+
+#endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_DATA_H_
diff --git a/skia/ext/bitmap_platform_device_linux.cc b/skia/ext/bitmap_platform_device_linux.cc
index 9b589de..4c566b4 100644
--- a/skia/ext/bitmap_platform_device_linux.cc
+++ b/skia/ext/bitmap_platform_device_linux.cc
@@ -1,9 +1,11 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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_linux.h"
+#include "skia/ext/bitmap_platform_device_data.h"
+
#include <cairo/cairo.h>
namespace skia {
@@ -35,72 +37,18 @@ void LoadClipToContext(cairo_t* context, const SkRegion& clip) {
} // namespace
-// -----------------------------------------------------------------------------
-// These objects are reference counted and own a Cairo surface. The surface is
-// the backing store for a Skia bitmap and we reference count it so that we can
-// copy BitmapPlatformDevice objects without having to copy all the image
-// data.
-// -----------------------------------------------------------------------------
-class BitmapPlatformDevice::BitmapPlatformDeviceData
- : public base::RefCounted<BitmapPlatformDeviceData> {
- public:
- explicit BitmapPlatformDeviceData(cairo_surface_t* surface);
-
- cairo_t* GetContext();
-
- // Sets the transform and clip operations. This will not update the Cairo
- // surface, but will mark the config as dirty. The next call of LoadConfig
- // will pick up these changes.
- void SetMatrixClip(const SkMatrix& transform, const SkRegion& region);
-
- protected:
- void LoadConfig();
-
- // The Cairo surface inside this DC.
- cairo_t* context_;
- cairo_surface_t *const surface_;
-
- // True when there is a transform or clip that has not been set to the
- // surface. The surface is retrieved for every text operation, and the
- // transform and clip do not change as much. We can save time by not loading
- // the clip and transform for every one.
- bool config_dirty_;
-
- // Translation assigned to the DC: we need to keep track of this separately
- // so it can be updated even if the DC isn't created yet.
- SkMatrix transform_;
-
- // The current clipping
- SkRegion clip_region_;
-
- // Disallow copy & assign.
- BitmapPlatformDeviceData(const BitmapPlatformDeviceData&);
- BitmapPlatformDeviceData& operator=(
- const BitmapPlatformDeviceData&);
-
- private:
- friend class base::RefCounted<BitmapPlatformDeviceData>;
-
- ~BitmapPlatformDeviceData();
-};
-
BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData(
cairo_surface_t* surface)
: surface_(surface),
config_dirty_(true) { // Want to load the config next time.
- context_ = cairo_create(surface);
+ bitmap_context_ = cairo_create(surface);
}
BitmapPlatformDevice::BitmapPlatformDeviceData::~BitmapPlatformDeviceData() {
- cairo_destroy(context_);
+ cairo_destroy(bitmap_context_);
cairo_surface_destroy(surface_);
}
-cairo_t* BitmapPlatformDevice::BitmapPlatformDeviceData::GetContext() {
- LoadConfig();
- return context_;
-}
-
void BitmapPlatformDevice::BitmapPlatformDeviceData::SetMatrixClip(
const SkMatrix& transform,
const SkRegion& region) {
@@ -110,17 +58,17 @@ void BitmapPlatformDevice::BitmapPlatformDeviceData::SetMatrixClip(
}
void BitmapPlatformDevice::BitmapPlatformDeviceData::LoadConfig() {
- if (!config_dirty_ || !context_)
+ if (!config_dirty_ || !bitmap_context_)
return; // Nothing to do.
config_dirty_ = false;
// Load the identity matrix since this is what our clip is relative to.
cairo_matrix_t cairo_matrix;
cairo_matrix_init_identity(&cairo_matrix);
- cairo_set_matrix(context_, &cairo_matrix);
+ cairo_set_matrix(bitmap_context_, &cairo_matrix);
- LoadClipToContext(context_, clip_region_);
- LoadMatrixToContext(context_, transform_);
+ LoadClipToContext(bitmap_context_, clip_region_);
+ LoadMatrixToContext(bitmap_context_, transform_);
}
// We use this static factory function instead of the regular constructor so
@@ -187,7 +135,8 @@ BitmapPlatformDevice::~BitmapPlatformDevice() {
}
cairo_t* BitmapPlatformDevice::beginPlatformPaint() {
- cairo_t* cairo = data_->GetContext();
+ data_->LoadConfig();
+ cairo_t* cairo = data_->bitmap_context();
// Tell Cairo that we've (probably) modified its pixel buffer without
// its knowledge.
cairo_surface_mark_dirty(cairo_get_target(cairo));
diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc
index feb192b..afb02e7 100644
--- a/skia/ext/bitmap_platform_device_mac.cc
+++ b/skia/ext/bitmap_platform_device_mac.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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.
@@ -8,6 +8,7 @@
#include "base/mac_util.h"
#include "base/ref_counted.h"
+#include "skia/ext/bitmap_platform_device_data.h"
#include "skia/ext/skia_utils_mac.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkRegion.h"
@@ -75,59 +76,6 @@ static CGContextRef CGContextForData(void* data, int width, int height) {
} // namespace
-class BitmapPlatformDevice::BitmapPlatformDeviceData : public SkRefCnt {
- public:
- explicit BitmapPlatformDeviceData(CGContextRef bitmap);
-
- // Create/destroy CoreGraphics context for our bitmap data.
- CGContextRef GetBitmapContext() {
- LoadConfig();
- return bitmap_context_;
- }
-
- void ReleaseBitmapContext() {
- SkASSERT(bitmap_context_);
- CGContextRelease(bitmap_context_);
- bitmap_context_ = NULL;
- }
-
- // Sets the transform and clip operations. This will not update the CGContext,
- // but will mark the config as dirty. The next call of LoadConfig will
- // pick up these changes.
- void SetMatrixClip(const SkMatrix& transform, const SkRegion& region);
-
- // Loads the current transform and clip into the DC. Can be called even when
- // |bitmap_context_| is NULL (will be a NOP).
- void LoadConfig();
-
- // Lazily-created graphics context used to draw into the bitmap.
- CGContextRef bitmap_context_;
-
- // True when there is a transform or clip that has not been set to the
- // CGContext. The CGContext is retrieved for every text operation, and the
- // transform and clip do not change as much. We can save time by not loading
- // the clip and transform for every one.
- bool config_dirty_;
-
- // Translation assigned to the CGContext: we need to keep track of this
- // separately so it can be updated even if the CGContext isn't created yet.
- SkMatrix transform_;
-
- // The current clipping
- SkRegion clip_region_;
-
- private:
- friend class base::RefCounted<BitmapPlatformDeviceData>;
- ~BitmapPlatformDeviceData() {
- if (bitmap_context_)
- CGContextRelease(bitmap_context_);
- }
-
- // Disallow copy & assign.
- BitmapPlatformDeviceData(const BitmapPlatformDeviceData&);
- BitmapPlatformDeviceData& operator=(const BitmapPlatformDeviceData&);
-};
-
BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData(
CGContextRef bitmap)
: bitmap_context_(bitmap),
@@ -147,6 +95,11 @@ BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData(
CGContextSaveGState(bitmap_context_);
}
+BitmapPlatformDevice::BitmapPlatformDeviceData::~BitmapPlatformDeviceData() {
+ if (bitmap_context_)
+ CGContextRelease(bitmap_context_);
+}
+
void BitmapPlatformDevice::BitmapPlatformDeviceData::SetMatrixClip(
const SkMatrix& transform,
const SkRegion& region) {
@@ -274,7 +227,8 @@ BitmapPlatformDevice& BitmapPlatformDevice::operator=(
}
CGContextRef BitmapPlatformDevice::GetBitmapContext() {
- return data_->GetBitmapContext();
+ data_->LoadConfig();
+ return data_->bitmap_context();
}
void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform,
@@ -285,14 +239,14 @@ void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform,
void BitmapPlatformDevice::DrawToContext(CGContextRef context, int x, int y,
const CGRect* src_rect) {
bool created_dc = false;
- if (!data_->bitmap_context_) {
+ if (!data_->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(data_->bitmap_context());
CGRect bounds;
bounds.origin.x = x;
bounds.origin.y = y;
@@ -329,7 +283,7 @@ void BitmapPlatformDevice::processPixels(int x, int y,
int width, int height,
adjustAlpha adjustor) {
const SkBitmap& bitmap = accessBitmap(true);
- SkMatrix& matrix = data_->transform_;
+ const SkMatrix& matrix = data_->transform();
int bitmap_start_x = SkScalarRound(matrix.getTranslateX()) + x;
int bitmap_start_y = SkScalarRound(matrix.getTranslateY()) + y;
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc
index 27323cb..76f0ea3 100644
--- a/skia/ext/bitmap_platform_device_win.cc
+++ b/skia/ext/bitmap_platform_device_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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.
@@ -7,6 +7,7 @@
#include "skia/ext/bitmap_platform_device_win.h"
+#include "skia/ext/bitmap_platform_device_data.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkRegion.h"
@@ -45,64 +46,14 @@ bool Constrain(int available_size, int* position, int *size) {
} // namespace
-class BitmapPlatformDevice::BitmapPlatformDeviceData : public SkRefCnt {
- public:
- explicit BitmapPlatformDeviceData(HBITMAP hbitmap);
-
- // Create/destroy hdc_, which is the memory DC for our bitmap data.
- HDC GetBitmapDC();
- void ReleaseBitmapDC();
- bool IsBitmapDCCreated() const;
-
- // Sets the transform and clip operations. This will not update the DC,
- // but will mark the config as dirty. The next call of LoadConfig will
- // pick up these changes.
- void SetMatrixClip(const SkMatrix& transform, const SkRegion& region);
-
- const SkMatrix& transform() const {
- return transform_;
- }
-
- protected:
- // Loads the current transform and clip into the DC. Can be called even when
- // the DC is NULL (will be a NOP).
- void LoadConfig();
-
- // Windows bitmap corresponding to our surface.
- HBITMAP hbitmap_;
-
- // Lazily-created DC used to draw into the bitmap, see getBitmapDC.
- HDC hdc_;
-
- // True when there is a transform or clip that has not been set to the DC.
- // The DC is retrieved for every text operation, and the transform and clip
- // do not change as much. We can save time by not loading the clip and
- // transform for every one.
- bool config_dirty_;
-
- // Translation assigned to the DC: we need to keep track of this separately
- // so it can be updated even if the DC isn't created yet.
- SkMatrix transform_;
-
- // The current clipping
- SkRegion clip_region_;
-
- private:
- virtual ~BitmapPlatformDeviceData();
-
- // Copy & assign are not supported.
- BitmapPlatformDeviceData(const BitmapPlatformDeviceData&);
- BitmapPlatformDeviceData& operator=(const BitmapPlatformDeviceData&);
-};
-
BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData(
HBITMAP hbitmap)
- : hbitmap_(hbitmap),
+ : bitmap_context_(hbitmap),
hdc_(NULL),
config_dirty_(true) { // Want to load the config next time.
// Initialize the clip region to the entire bitmap.
BITMAP bitmap_data;
- if (GetObject(hbitmap_, sizeof(BITMAP), &bitmap_data)) {
+ if (GetObject(bitmap_context_, sizeof(BITMAP), &bitmap_data)) {
SkIRect rect;
rect.set(0, 0, bitmap_data.bmWidth, bitmap_data.bmHeight);
clip_region_ = SkRegion(rect);
@@ -116,14 +67,14 @@ BitmapPlatformDevice::BitmapPlatformDeviceData::~BitmapPlatformDeviceData() {
ReleaseBitmapDC();
// this will free the bitmap data as well as the bitmap handle
- DeleteObject(hbitmap_);
+ DeleteObject(bitmap_context_);
}
HDC BitmapPlatformDevice::BitmapPlatformDeviceData::GetBitmapDC() {
if (!hdc_) {
hdc_ = CreateCompatibleDC(NULL);
InitializeDC(hdc_);
- HGDIOBJ old_bitmap = SelectObject(hdc_, hbitmap_);
+ HGDIOBJ old_bitmap = SelectObject(hdc_, bitmap_context_);
// When the memory DC is created, its display surface is exactly one
// monochrome pixel wide and one monochrome pixel high. Since we select our
// own bitmap, we must delete the previous one.
diff --git a/skia/skia.gyp b/skia/skia.gyp
index 2b17094..74e394f 100644
--- a/skia/skia.gyp
+++ b/skia/skia.gyp
@@ -498,6 +498,7 @@
'../third_party/skia/include/images/SkPageFlipper.h',
'ext/bitmap_platform_device.h',
+ 'ext/bitmap_platform_device_data.h',
'ext/bitmap_platform_device_linux.cc',
'ext/bitmap_platform_device_linux.h',
'ext/bitmap_platform_device_mac.cc',