summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-14 15:14:53 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-14 15:14:53 +0000
commitbd63dc9cdf640a6d1e833ce0b5ed7ed9090973b0 (patch)
tree149a64e70ca634bd43019d639d9ae29ca6d45a9a /skia
parentb39627f8eef41a2d4e1f4516bf905d6ad895e56b (diff)
downloadchromium_src-bd63dc9cdf640a6d1e833ce0b5ed7ed9090973b0.zip
chromium_src-bd63dc9cdf640a6d1e833ce0b5ed7ed9090973b0.tar.gz
chromium_src-bd63dc9cdf640a6d1e833ce0b5ed7ed9090973b0.tar.bz2
Refactor the PlatformContext layer to have only one class.
Previously we had three classes of PlatformCanvas*, one for each platform. Then we had a typedef of PlatformContext to PlatformCanvas[Mac|Win|Linux] for the specific platform. This means that it was almost impossible to forward-declare PlatformCanvas and there were a bunch of unnecessary includes of platform_canvas.h in header files. This change makes there be only one platform_canvas.h header with ifdefs, which removes a decent amount of duplicated code. There is a platform-independent file, and one platform-dependent file of platform_canvas for each platform. I also renamed PlatformDevice[Mac|Win|Linux] to PlatformDevice, althouth in this case I kept the separate headers since there was much less overlap. I also broke out CanvasPaint into separate headers so this template doesn't need to be included all over the project (only a couple of files actually need it). Review URL: http://codereview.chromium.org/125109 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18363 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/bitmap_platform_device.h21
-rw-r--r--skia/ext/bitmap_platform_device_linux.cc56
-rw-r--r--skia/ext/bitmap_platform_device_linux.h28
-rw-r--r--skia/ext/bitmap_platform_device_mac.cc71
-rw-r--r--skia/ext/bitmap_platform_device_mac.h26
-rw-r--r--skia/ext/bitmap_platform_device_win.cc81
-rw-r--r--skia/ext/bitmap_platform_device_win.h34
-rw-r--r--skia/ext/canvas_paint.h17
-rw-r--r--skia/ext/canvas_paint_linux.h99
-rw-r--r--skia/ext/canvas_paint_win.h132
-rw-r--r--skia/ext/platform_canvas.cc26
-rw-r--r--skia/ext/platform_canvas.h122
-rw-r--r--skia/ext/platform_canvas_linux.cc59
-rw-r--r--skia/ext/platform_canvas_linux.h154
-rw-r--r--skia/ext/platform_canvas_mac.cc104
-rw-r--r--skia/ext/platform_canvas_mac.h96
-rw-r--r--skia/ext/platform_canvas_win.cc70
-rw-r--r--skia/ext/platform_canvas_win.h213
-rw-r--r--skia/ext/platform_device.h18
-rw-r--r--skia/ext/platform_device_linux.cc3
-rw-r--r--skia/ext/platform_device_linux.h6
-rw-r--r--skia/ext/platform_device_mac.cc15
-rw-r--r--skia/ext/platform_device_mac.h6
-rw-r--r--skia/ext/platform_device_win.cc18
-rw-r--r--skia/ext/platform_device_win.h6
-rw-r--r--skia/ext/vector_canvas.cc13
-rw-r--r--skia/ext/vector_canvas.h6
-rw-r--r--skia/ext/vector_canvas_unittest.cc14
-rw-r--r--skia/ext/vector_platform_device_win.cc (renamed from skia/ext/vector_device.cc)139
-rw-r--r--skia/ext/vector_platform_device_win.h (renamed from skia/ext/vector_device.h)22
-rwxr-xr-x[-rw-r--r--]skia/skia.gyp8
31 files changed, 775 insertions, 908 deletions
diff --git a/skia/ext/bitmap_platform_device.h b/skia/ext/bitmap_platform_device.h
index fcc8644c..bcc4972 100644
--- a/skia/ext/bitmap_platform_device.h
+++ b/skia/ext/bitmap_platform_device.h
@@ -1,10 +1,12 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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.
-// Declare a platform-neutral name for this platform's bitmap device class
-// that can be used by upper-level classes that just need to pass a reference
-// around.
+#ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_H_
+#define SKIA_EXT_BITMAP_PLATFORM_DEVICE_H_
+
+// This file provides an easy way to include the appropriate
+// BitmapPlatformDevice header file for your platform.
#if defined(WIN32)
#include "skia/ext/bitmap_platform_device_win.h"
@@ -14,14 +16,5 @@
#include "skia/ext/bitmap_platform_device_linux.h"
#endif
-namespace skia {
-
-#if defined(WIN32)
-typedef BitmapPlatformDeviceWin BitmapPlatformDevice;
-#elif defined(__APPLE__)
-typedef BitmapPlatformDeviceMac BitmapPlatformDevice;
-#elif defined(__linux__)
-typedef BitmapPlatformDeviceLinux BitmapPlatformDevice;
-#endif
+#endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_H_
-} // namespace skia
diff --git a/skia/ext/bitmap_platform_device_linux.cc b/skia/ext/bitmap_platform_device_linux.cc
index f6a0e6d..1b061b0 100644
--- a/skia/ext/bitmap_platform_device_linux.cc
+++ b/skia/ext/bitmap_platform_device_linux.cc
@@ -11,13 +11,13 @@ namespace skia {
// -----------------------------------------------------------------------------
// 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 BitmapPlatformDeviceLinux objects without having to copy all the image
+// copy BitmapPlatformDevice objects without having to copy all the image
// data.
// -----------------------------------------------------------------------------
-class BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinuxData
- : public base::RefCounted<BitmapPlatformDeviceLinuxData> {
+class BitmapPlatformDevice::BitmapPlatformDeviceData
+ : public base::RefCounted<BitmapPlatformDeviceData> {
public:
- explicit BitmapPlatformDeviceLinuxData(cairo_surface_t* surface)
+ explicit BitmapPlatformDeviceData(cairo_surface_t* surface)
: surface_(surface) { }
cairo_surface_t* surface() const { return surface_; }
@@ -25,23 +25,24 @@ class BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinuxData
protected:
cairo_surface_t *const surface_;
- friend class base::RefCounted<BitmapPlatformDeviceLinuxData>;
- ~BitmapPlatformDeviceLinuxData() {
+ friend class base::RefCounted<BitmapPlatformDeviceData>;
+ ~BitmapPlatformDeviceData() {
cairo_surface_destroy(surface_);
}
// Disallow copy & assign.
- BitmapPlatformDeviceLinuxData(const BitmapPlatformDeviceLinuxData&);
- BitmapPlatformDeviceLinuxData& operator=(
- const BitmapPlatformDeviceLinuxData&);
+ BitmapPlatformDeviceData(const BitmapPlatformDeviceData&);
+ BitmapPlatformDeviceData& operator=(
+ const BitmapPlatformDeviceData&);
};
// We use this static factory function instead of the regular constructor so
// that we can create the pixel data before calling the constructor. This is
// required so that we can call the base class' constructor with the pixel
// data.
-BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create(
- int width, int height, bool is_opaque, cairo_surface_t* surface) {
+BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
+ bool is_opaque,
+ cairo_surface_t* surface) {
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height,
cairo_image_surface_get_stride(surface));
@@ -55,12 +56,12 @@ BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create(
#endif
// The device object will take ownership of the graphics context.
- return new BitmapPlatformDeviceLinux
- (bitmap, new BitmapPlatformDeviceLinuxData(surface));
+ return new BitmapPlatformDevice
+ (bitmap, new BitmapPlatformDeviceData(surface));
}
-BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create(
- int width, int height, bool is_opaque) {
+BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
+ bool is_opaque) {
cairo_surface_t* surface =
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
width, height);
@@ -68,8 +69,9 @@ BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create(
return Create(width, height, is_opaque, surface);
}
-BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create(
- int width, int height, bool is_opaque, uint8_t* data) {
+BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
+ bool is_opaque,
+ uint8_t* data) {
cairo_surface_t* surface = cairo_image_surface_create_for_data(
data, CAIRO_FORMAT_ARGB32, width, height,
cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width));
@@ -79,29 +81,29 @@ BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create(
// The device will own the bitmap, which corresponds to also owning the pixel
// data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
-BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(
+BitmapPlatformDevice::BitmapPlatformDevice(
const SkBitmap& bitmap,
- BitmapPlatformDeviceLinuxData* data)
- : PlatformDeviceLinux(bitmap),
+ BitmapPlatformDeviceData* data)
+ : PlatformDevice(bitmap),
data_(data) {
}
-BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(
- const BitmapPlatformDeviceLinux& other)
- : PlatformDeviceLinux(const_cast<BitmapPlatformDeviceLinux&>(
+BitmapPlatformDevice::BitmapPlatformDevice(
+ const BitmapPlatformDevice& other)
+ : PlatformDevice(const_cast<BitmapPlatformDevice&>(
other).accessBitmap(true)),
data_(other.data_) {
}
-BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() {
+BitmapPlatformDevice::~BitmapPlatformDevice() {
}
-cairo_surface_t* BitmapPlatformDeviceLinux::surface() const {
+cairo_surface_t* BitmapPlatformDevice::surface() const {
return data_->surface();
}
-BitmapPlatformDeviceLinux& BitmapPlatformDeviceLinux::operator=(
- const BitmapPlatformDeviceLinux& other) {
+BitmapPlatformDevice& BitmapPlatformDevice::operator=(
+ const BitmapPlatformDevice& other) {
data_ = other.data_;
return *this;
}
diff --git a/skia/ext/bitmap_platform_device_linux.h b/skia/ext/bitmap_platform_device_linux.h
index bb261bd..a40986c 100644
--- a/skia/ext/bitmap_platform_device_linux.h
+++ b/skia/ext/bitmap_platform_device_linux.h
@@ -54,19 +54,18 @@ namespace skia {
// shared memory between the renderer and the main process at least. In this
// case we'll probably create the buffer from a precreated region of memory.
// -----------------------------------------------------------------------------
-class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
+class BitmapPlatformDevice : public PlatformDevice {
// A reference counted cairo surface
- class BitmapPlatformDeviceLinuxData;
+ class BitmapPlatformDeviceData;
public:
- static BitmapPlatformDeviceLinux* Create(int width, int height,
- bool is_opaque);
+ static BitmapPlatformDevice* Create(int width, int height, bool is_opaque);
+
// This doesn't take ownership of |data|
- static BitmapPlatformDeviceLinux* Create(int width, int height,
- bool is_opaque, uint8_t* data);
- static BitmapPlatformDeviceLinux* Create(int width, int height,
- bool is_opaque,
- cairo_surface_t* surface);
+ static BitmapPlatformDevice* Create(int width, int height,
+ bool is_opaque, uint8_t* data);
+ static BitmapPlatformDevice* Create(int width, int height,
+ bool is_opaque, cairo_surface_t* surface);
// Create a BitmapPlatformDeviceLinux from an already constructed bitmap;
// you should probably be using Create(). This may become private later if
@@ -74,13 +73,12 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
// the Windows and Mac versions of this class do.
//
// This object takes ownership of @data.
- BitmapPlatformDeviceLinux(const SkBitmap& other,
- BitmapPlatformDeviceLinuxData* data);
- virtual ~BitmapPlatformDeviceLinux();
- BitmapPlatformDeviceLinux& operator=(const BitmapPlatformDeviceLinux& other);
+ BitmapPlatformDevice(const SkBitmap& other, BitmapPlatformDeviceData* data);
+ virtual ~BitmapPlatformDevice();
+ BitmapPlatformDevice& operator=(const BitmapPlatformDevice& other);
// A stub copy constructor. Needs to be properly implemented.
- BitmapPlatformDeviceLinux(const BitmapPlatformDeviceLinux& other);
+ BitmapPlatformDevice(const BitmapPlatformDevice& other);
// Bitmaps aren't vector graphics.
virtual bool IsVectorial() { return false; }
@@ -92,7 +90,7 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
cairo_surface_t* surface() const;
private:
- scoped_refptr<BitmapPlatformDeviceLinuxData> data_;
+ scoped_refptr<BitmapPlatformDeviceData> data_;
};
} // namespace skia
diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc
index 41458c1..79c735a 100644
--- a/skia/ext/bitmap_platform_device_mac.cc
+++ b/skia/ext/bitmap_platform_device_mac.cc
@@ -46,9 +46,9 @@ bool Constrain(int available_size, int* position, int *size) {
} // namespace
-class BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData : public SkRefCnt {
+class BitmapPlatformDevice::BitmapPlatformDeviceData : public SkRefCnt {
public:
- explicit BitmapPlatformDeviceMacData(CGContextRef bitmap);
+ explicit BitmapPlatformDeviceData(CGContextRef bitmap);
// Create/destroy CoreGraphics context for our bitmap data.
CGContextRef GetBitmapContext() {
@@ -88,19 +88,18 @@ class BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData : public SkRefCnt {
SkRegion clip_region_;
private:
- friend class base::RefCounted<BitmapPlatformDeviceMacData>;
- ~BitmapPlatformDeviceMacData() {
+ friend class base::RefCounted<BitmapPlatformDeviceData>;
+ ~BitmapPlatformDeviceData() {
if (bitmap_context_)
CGContextRelease(bitmap_context_);
}
// Disallow copy & assign.
- BitmapPlatformDeviceMacData(const BitmapPlatformDeviceMacData&);
- BitmapPlatformDeviceMacData& operator=(const BitmapPlatformDeviceMacData&);
+ BitmapPlatformDeviceData(const BitmapPlatformDeviceData&);
+ BitmapPlatformDeviceData& operator=(const BitmapPlatformDeviceData&);
};
-BitmapPlatformDeviceMac::\
- BitmapPlatformDeviceMacData::BitmapPlatformDeviceMacData(
+BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData(
CGContextRef bitmap)
: bitmap_context_(bitmap),
config_dirty_(true) { // Want to load the config next time.
@@ -119,7 +118,7 @@ BitmapPlatformDeviceMac::\
CGContextSaveGState(bitmap_context_);
}
-void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::SetMatrixClip(
+void BitmapPlatformDevice::BitmapPlatformDeviceData::SetMatrixClip(
const SkMatrix& transform,
const SkRegion& region) {
transform_ = transform;
@@ -127,7 +126,7 @@ void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::SetMatrixClip(
config_dirty_ = true;
}
-void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::LoadConfig() {
+void BitmapPlatformDevice::BitmapPlatformDeviceData::LoadConfig() {
if (!config_dirty_ || !bitmap_context_)
return; // Nothing to do.
config_dirty_ = false;
@@ -154,10 +153,10 @@ void BitmapPlatformDeviceMac::BitmapPlatformDeviceMacData::LoadConfig() {
// that we can create the pixel data before calling the constructor. This is
// required so that we can call the base class' constructor with the pixel
// data.
-BitmapPlatformDeviceMac* BitmapPlatformDeviceMac::Create(CGContextRef context,
- int width,
- int height,
- bool is_opaque) {
+BitmapPlatformDevice* BitmapPlatformDevice::Create(CGContextRef context,
+ int width,
+ int height,
+ bool is_opaque) {
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
if (bitmap.allocPixels() != true)
@@ -197,51 +196,51 @@ BitmapPlatformDeviceMac* BitmapPlatformDeviceMac::Create(CGContextRef context,
}
// The device object will take ownership of the graphics context.
- return new BitmapPlatformDeviceMac(
- new BitmapPlatformDeviceMacData(context), bitmap);
+ return new BitmapPlatformDevice(
+ new BitmapPlatformDeviceData(context), bitmap);
}
// The device will own the bitmap, which corresponds to also owning the pixel
// data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
-BitmapPlatformDeviceMac::BitmapPlatformDeviceMac(
- BitmapPlatformDeviceMacData* data, const SkBitmap& bitmap)
- : PlatformDeviceMac(bitmap),
+BitmapPlatformDevice::BitmapPlatformDevice(
+ BitmapPlatformDeviceData* data, const SkBitmap& bitmap)
+ : PlatformDevice(bitmap),
data_(data) {
}
// The copy constructor just adds another reference to the underlying data.
// We use a const cast since the default Skia definitions don't define the
// proper constedness that we expect (accessBitmap should really be const).
-BitmapPlatformDeviceMac::BitmapPlatformDeviceMac(
- const BitmapPlatformDeviceMac& other)
- : PlatformDeviceMac(
- const_cast<BitmapPlatformDeviceMac&>(other).accessBitmap(true)),
+BitmapPlatformDevice::BitmapPlatformDevice(
+ const BitmapPlatformDevice& other)
+ : PlatformDevice(
+ const_cast<BitmapPlatformDevice&>(other).accessBitmap(true)),
data_(other.data_) {
data_->ref();
}
-BitmapPlatformDeviceMac::~BitmapPlatformDeviceMac() {
+BitmapPlatformDevice::~BitmapPlatformDevice() {
data_->unref();
}
-BitmapPlatformDeviceMac& BitmapPlatformDeviceMac::operator=(
- const BitmapPlatformDeviceMac& other) {
+BitmapPlatformDevice& BitmapPlatformDevice::operator=(
+ const BitmapPlatformDevice& other) {
data_ = other.data_;
data_->ref();
return *this;
}
-CGContextRef BitmapPlatformDeviceMac::GetBitmapContext() {
+CGContextRef BitmapPlatformDevice::GetBitmapContext() {
return data_->GetBitmapContext();
}
-void BitmapPlatformDeviceMac::setMatrixClip(const SkMatrix& transform,
- const SkRegion& region) {
+void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform,
+ const SkRegion& region) {
data_->SetMatrixClip(transform, region);
}
-void BitmapPlatformDeviceMac::DrawToContext(CGContextRef context, int x, int y,
- const CGRect* src_rect) {
+void BitmapPlatformDevice::DrawToContext(CGContextRef context, int x, int y,
+ const CGRect* src_rect) {
bool created_dc = false;
if (!data_->bitmap_context_) {
created_dc = true;
@@ -273,20 +272,20 @@ void BitmapPlatformDeviceMac::DrawToContext(CGContextRef context, int x, int y,
}
// Returns the color value at the specified location.
-SkColor BitmapPlatformDeviceMac::getColorAt(int x, int y) {
+SkColor BitmapPlatformDevice::getColorAt(int x, int y) {
const SkBitmap& bitmap = accessBitmap(true);
SkAutoLockPixels lock(bitmap);
uint32_t* data = bitmap.getAddr32(0, 0);
return static_cast<SkColor>(data[x + y * width()]);
}
-void BitmapPlatformDeviceMac::onAccessBitmap(SkBitmap*) {
+void BitmapPlatformDevice::onAccessBitmap(SkBitmap*) {
// Not needed in CoreGraphics
}
-void BitmapPlatformDeviceMac::processPixels(int x, int y,
- int width, int height,
- adjustAlpha adjustor) {
+void BitmapPlatformDevice::processPixels(int x, int y,
+ int width, int height,
+ adjustAlpha adjustor) {
const SkBitmap& bitmap = accessBitmap(true);
SkMatrix& matrix = data_->transform_;
int bitmap_start_x = SkScalarRound(matrix.getTranslateX()) + x;
diff --git a/skia/ext/bitmap_platform_device_mac.h b/skia/ext/bitmap_platform_device_mac.h
index 0cf483f..6580302 100644
--- a/skia/ext/bitmap_platform_device_mac.h
+++ b/skia/ext/bitmap_platform_device_mac.h
@@ -11,7 +11,7 @@ namespace skia {
// A device is basically a wrapper around SkBitmap that provides a surface for
// SkCanvas to draw into. Our device provides a surface CoreGraphics can also
-// write to. BitmapPlatformDeviceMac creates a bitmap using
+// write to. BitmapPlatformDevice creates a bitmap using
// CGCreateBitmapContext() in a format that Skia supports and can then use this
// to draw text into, etc. This pixel data is provided to the bitmap that the
// device contains so that it can be shared.
@@ -23,7 +23,7 @@ namespace skia {
// For us, that other bitmap will become invalid as soon as the device becomes
// invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE
// DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead.
-class BitmapPlatformDeviceMac : public PlatformDeviceMac {
+class BitmapPlatformDevice : public PlatformDevice {
public:
// Factory function. The screen DC is used to create the bitmap, and will not
// be stored beyond this function. is_opaque should be set if the caller
@@ -32,10 +32,10 @@ class BitmapPlatformDeviceMac : public PlatformDeviceMac {
// The shared_section parameter is optional (pass NULL for default behavior).
// If shared_section is non-null, then it must be a handle to a file-mapping
// object returned by CreateFileMapping. See CreateDIBSection for details.
- static BitmapPlatformDeviceMac* Create(CGContextRef context,
- int width,
- int height,
- bool is_opaque);
+ static BitmapPlatformDevice* Create(CGContextRef context,
+ int width,
+ int height,
+ bool is_opaque);
// Copy constructor. When copied, devices duplicate their internal data, so
// stay linked. This is because their implementation is very heavyweight
@@ -48,11 +48,11 @@ class BitmapPlatformDeviceMac : public PlatformDeviceMac {
//
// Copy constucting and "=" is designed for saving the device or passing it
// around to another routine willing to deal with the bitmap data directly.
- BitmapPlatformDeviceMac(const BitmapPlatformDeviceMac& other);
- virtual ~BitmapPlatformDeviceMac();
+ BitmapPlatformDevice(const BitmapPlatformDevice& other);
+ virtual ~BitmapPlatformDevice();
// See warning for copy constructor above.
- BitmapPlatformDeviceMac& operator=(const BitmapPlatformDeviceMac& other);
+ BitmapPlatformDevice& operator=(const BitmapPlatformDevice& other);
virtual CGContextRef GetBitmapContext();
virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region);
@@ -69,10 +69,10 @@ class BitmapPlatformDeviceMac : public PlatformDeviceMac {
// Reference counted data that can be shared between multiple devices. This
// allows copy constructors and operator= for devices to work properly. The
// bitmaps used by the base device class are already refcounted and copyable.
- class BitmapPlatformDeviceMacData;
+ class BitmapPlatformDeviceData;
- BitmapPlatformDeviceMac(BitmapPlatformDeviceMacData* data,
- const SkBitmap& bitmap);
+ BitmapPlatformDevice(BitmapPlatformDeviceData* data,
+ const SkBitmap& bitmap);
// Flushes the CoreGraphics context so that the pixel data can be accessed
// directly by Skia. Overridden from SkDevice, this is called when Skia
@@ -85,7 +85,7 @@ class BitmapPlatformDeviceMac : public PlatformDeviceMac {
// Data associated with this device, guaranteed non-null. We hold a reference
// to this object.
- BitmapPlatformDeviceMacData* data_;
+ BitmapPlatformDeviceData* data_;
};
} // namespace skia
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc
index ecd609f..646692d 100644
--- a/skia/ext/bitmap_platform_device_win.cc
+++ b/skia/ext/bitmap_platform_device_win.cc
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <windows.h>
+#include <psapi.h>
+
#include "skia/ext/bitmap_platform_device_win.h"
#include "third_party/skia/include/core/SkMatrix.h"
@@ -42,9 +45,9 @@ bool Constrain(int available_size, int* position, int *size) {
} // namespace
-class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData : public SkRefCnt {
+class BitmapPlatformDevice::BitmapPlatformDeviceData : public SkRefCnt {
public:
- explicit BitmapPlatformDeviceWinData(HBITMAP hbitmap);
+ explicit BitmapPlatformDeviceData(HBITMAP hbitmap);
// Create/destroy hdc_, which is the memory DC for our bitmap data.
HDC GetBitmapDC();
@@ -85,14 +88,14 @@ class BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData : public SkRefCnt {
SkRegion clip_region_;
private:
- virtual ~BitmapPlatformDeviceWinData();
+ virtual ~BitmapPlatformDeviceData();
// Copy & assign are not supported.
- BitmapPlatformDeviceWinData(const BitmapPlatformDeviceWinData&);
- BitmapPlatformDeviceWinData& operator=(const BitmapPlatformDeviceWinData&);
+ BitmapPlatformDeviceData(const BitmapPlatformDeviceData&);
+ BitmapPlatformDeviceData& operator=(const BitmapPlatformDeviceData&);
};
-BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::BitmapPlatformDeviceWinData(
+BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData(
HBITMAP hbitmap)
: hbitmap_(hbitmap),
hdc_(NULL),
@@ -108,7 +111,7 @@ BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::BitmapPlatformDeviceWinDat
transform_.reset();
}
-BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::~BitmapPlatformDeviceWinData() {
+BitmapPlatformDevice::BitmapPlatformDeviceData::~BitmapPlatformDeviceData() {
if (hdc_)
ReleaseBitmapDC();
@@ -116,7 +119,7 @@ BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::~BitmapPlatformDeviceWinDa
DeleteObject(hbitmap_);
}
-HDC BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::GetBitmapDC() {
+HDC BitmapPlatformDevice::BitmapPlatformDeviceData::GetBitmapDC() {
if (!hdc_) {
hdc_ = CreateCompatibleDC(NULL);
InitializeDC(hdc_);
@@ -131,19 +134,19 @@ HDC BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::GetBitmapDC() {
return hdc_;
}
-void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::ReleaseBitmapDC() {
+void BitmapPlatformDevice::BitmapPlatformDeviceData::ReleaseBitmapDC() {
SkASSERT(hdc_);
DeleteDC(hdc_);
hdc_ = NULL;
}
-bool BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::IsBitmapDCCreated()
+bool BitmapPlatformDevice::BitmapPlatformDeviceData::IsBitmapDCCreated()
const {
return hdc_ != NULL;
}
-void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::SetMatrixClip(
+void BitmapPlatformDevice::BitmapPlatformDeviceData::SetMatrixClip(
const SkMatrix& transform,
const SkRegion& region) {
transform_ = transform;
@@ -151,7 +154,7 @@ void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::SetMatrixClip(
config_dirty_ = true;
}
-void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::LoadConfig() {
+void BitmapPlatformDevice::BitmapPlatformDeviceData::LoadConfig() {
if (!config_dirty_ || !hdc_)
return; // Nothing to do.
config_dirty_ = false;
@@ -166,7 +169,7 @@ void BitmapPlatformDeviceWin::BitmapPlatformDeviceWinData::LoadConfig() {
// that we can create the pixel data before calling the constructor. This is
// required so that we can call the base class' constructor with the pixel
// data.
-BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(
+BitmapPlatformDevice* BitmapPlatformDevice::create(
HDC screen_dc,
int width,
int height,
@@ -219,16 +222,28 @@ BitmapPlatformDeviceWin* BitmapPlatformDeviceWin::create(
// The device object will take ownership of the HBITMAP. The initial refcount
// of the data object will be 1, which is what the constructor expects.
- return new BitmapPlatformDeviceWin(new BitmapPlatformDeviceWinData(hbitmap),
- bitmap);
+ return new BitmapPlatformDevice(new BitmapPlatformDeviceData(hbitmap),
+ bitmap);
+}
+
+// static
+BitmapPlatformDevice* BitmapPlatformDevice::create(int width,
+ int height,
+ bool is_opaque,
+ HANDLE shared_section) {
+ HDC screen_dc = GetDC(NULL);
+ BitmapPlatformDevice* device = BitmapPlatformDevice::create(
+ screen_dc, width, height, is_opaque, shared_section);
+ ReleaseDC(NULL, screen_dc);
+ return device;
}
// The device will own the HBITMAP, which corresponds to also owning the pixel
// data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
-BitmapPlatformDeviceWin::BitmapPlatformDeviceWin(
- BitmapPlatformDeviceWinData* data,
+BitmapPlatformDevice::BitmapPlatformDevice(
+ BitmapPlatformDeviceData* data,
const SkBitmap& bitmap)
- : PlatformDeviceWin(bitmap),
+ : PlatformDevice(bitmap),
data_(data) {
// The data object is already ref'ed for us by create().
}
@@ -236,36 +251,36 @@ BitmapPlatformDeviceWin::BitmapPlatformDeviceWin(
// The copy constructor just adds another reference to the underlying data.
// We use a const cast since the default Skia definitions don't define the
// proper constedness that we expect (accessBitmap should really be const).
-BitmapPlatformDeviceWin::BitmapPlatformDeviceWin(
- const BitmapPlatformDeviceWin& other)
- : PlatformDeviceWin(
- const_cast<BitmapPlatformDeviceWin&>(other).accessBitmap(true)),
+BitmapPlatformDevice::BitmapPlatformDevice(
+ const BitmapPlatformDevice& other)
+ : PlatformDevice(
+ const_cast<BitmapPlatformDevice&>(other).accessBitmap(true)),
data_(other.data_) {
data_->ref();
}
-BitmapPlatformDeviceWin::~BitmapPlatformDeviceWin() {
+BitmapPlatformDevice::~BitmapPlatformDevice() {
data_->unref();
}
-BitmapPlatformDeviceWin& BitmapPlatformDeviceWin::operator=(
- const BitmapPlatformDeviceWin& other) {
+BitmapPlatformDevice& BitmapPlatformDevice::operator=(
+ const BitmapPlatformDevice& other) {
data_ = other.data_;
data_->ref();
return *this;
}
-HDC BitmapPlatformDeviceWin::getBitmapDC() {
+HDC BitmapPlatformDevice::getBitmapDC() {
return data_->GetBitmapDC();
}
-void BitmapPlatformDeviceWin::setMatrixClip(const SkMatrix& transform,
- const SkRegion& region) {
+void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform,
+ const SkRegion& region) {
data_->SetMatrixClip(transform, region);
}
-void BitmapPlatformDeviceWin::drawToHDC(HDC dc, int x, int y,
- const RECT* src_rect) {
+void BitmapPlatformDevice::drawToHDC(HDC dc, int x, int y,
+ const RECT* src_rect) {
bool created_dc = !data_->IsBitmapDCCreated();
HDC source_dc = getBitmapDC();
@@ -318,7 +333,7 @@ void BitmapPlatformDeviceWin::drawToHDC(HDC dc, int x, int y,
data_->ReleaseBitmapDC();
}
-void BitmapPlatformDeviceWin::makeOpaque(int x, int y, int width, int height) {
+void BitmapPlatformDevice::makeOpaque(int x, int y, int width, int height) {
const SkBitmap& bitmap = accessBitmap(true);
SkASSERT(bitmap.config() == SkBitmap::kARGB_8888_Config);
@@ -347,14 +362,14 @@ void BitmapPlatformDeviceWin::makeOpaque(int x, int y, int width, int height) {
}
// Returns the color value at the specified location.
-SkColor BitmapPlatformDeviceWin::getColorAt(int x, int y) {
+SkColor BitmapPlatformDevice::getColorAt(int x, int y) {
const SkBitmap& bitmap = accessBitmap(false);
SkAutoLockPixels lock(bitmap);
uint32_t* data = bitmap.getAddr32(0, 0);
return static_cast<SkColor>(data[x + y * width()]);
}
-void BitmapPlatformDeviceWin::onAccessBitmap(SkBitmap* bitmap) {
+void BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) {
// FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI
// operation has occurred on our DC.
if (data_->IsBitmapDCCreated())
diff --git a/skia/ext/bitmap_platform_device_win.h b/skia/ext/bitmap_platform_device_win.h
index 428441d..b37792a 100644
--- a/skia/ext/bitmap_platform_device_win.h
+++ b/skia/ext/bitmap_platform_device_win.h
@@ -11,7 +11,7 @@ namespace skia {
// A device is basically a wrapper around SkBitmap that provides a surface for
// SkCanvas to draw into. Our device provides a surface Windows can also write
-// to. BitmapPlatformDeviceWin creates a bitmap using CreateDIBSection() in a
+// to. BitmapPlatformDevice creates a bitmap using CreateDIBSection() in a
// format that Skia supports and can then use this to draw ClearType into, etc.
// This pixel data is provided to the bitmap that the device contains so that it
// can be shared.
@@ -23,7 +23,7 @@ namespace skia {
// For us, that other bitmap will become invalid as soon as the device becomes
// invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE
// DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead.
-class BitmapPlatformDeviceWin : public PlatformDeviceWin {
+class BitmapPlatformDevice : public PlatformDevice {
public:
// Factory function. The screen DC is used to create the bitmap, and will not
// be stored beyond this function. is_opaque should be set if the caller
@@ -32,11 +32,17 @@ class BitmapPlatformDeviceWin : public PlatformDeviceWin {
// The shared_section parameter is optional (pass NULL for default behavior).
// If shared_section is non-null, then it must be a handle to a file-mapping
// object returned by CreateFileMapping. See CreateDIBSection for details.
- static BitmapPlatformDeviceWin* create(HDC screen_dc,
- int width,
- int height,
- bool is_opaque,
- HANDLE shared_section);
+ static BitmapPlatformDevice* create(HDC screen_dc,
+ int width,
+ int height,
+ bool is_opaque,
+ HANDLE shared_section);
+
+ // This version is the same as above but will get the screen DC itself.
+ static BitmapPlatformDevice* create(int width,
+ int height,
+ bool is_opaque,
+ HANDLE shared_section);
// Copy constructor. When copied, devices duplicate their internal data, so
// stay linked. This is because their implementation is very heavyweight
@@ -49,11 +55,11 @@ class BitmapPlatformDeviceWin : public PlatformDeviceWin {
//
// Copy constucting and "=" is designed for saving the device or passing it
// around to another routine willing to deal with the bitmap data directly.
- BitmapPlatformDeviceWin(const BitmapPlatformDeviceWin& other);
- virtual ~BitmapPlatformDeviceWin();
+ BitmapPlatformDevice(const BitmapPlatformDevice& other);
+ virtual ~BitmapPlatformDevice();
// See warning for copy constructor above.
- BitmapPlatformDeviceWin& operator=(const BitmapPlatformDeviceWin& other);
+ BitmapPlatformDevice& operator=(const BitmapPlatformDevice& other);
// Retrieves the bitmap DC, which is the memory DC for our bitmap data. The
// bitmap DC is lazy created.
@@ -78,15 +84,15 @@ class BitmapPlatformDeviceWin : public PlatformDeviceWin {
// Reference counted data that can be shared between multiple devices. This
// allows copy constructors and operator= for devices to work properly. The
// bitmaps used by the base device class are already refcounted and copyable.
- class BitmapPlatformDeviceWinData;
+ class BitmapPlatformDeviceData;
// Private constructor. The data should already be ref'ed for us.
- BitmapPlatformDeviceWin(BitmapPlatformDeviceWinData* data,
- const SkBitmap& bitmap);
+ BitmapPlatformDevice(BitmapPlatformDeviceData* data,
+ const SkBitmap& bitmap);
// Data associated with this device, guaranteed non-null. We hold a reference
// to this object.
- BitmapPlatformDeviceWinData* data_;
+ BitmapPlatformDeviceData* data_;
};
} // namespace skia
diff --git a/skia/ext/canvas_paint.h b/skia/ext/canvas_paint.h
new file mode 100644
index 0000000..c65b880
--- /dev/null
+++ b/skia/ext/canvas_paint.h
@@ -0,0 +1,17 @@
+// Copyright (c) 2009 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_CANVAS_PAINT_H_
+#define SKIA_EXT_CANVAS_PAINT_H_
+
+// This file provides an easy way to include the appropriate CanvasPaint
+// header file on your platform.
+
+#if defined(WIN32)
+#include "skia/ext/canvas_paint_win.h"
+#elif defined(__linux__)
+#include "skia/ext/canvas_paint_linux.h"
+#endif
+
+#endif // SKIA_EXT_CANVAS_PAINT_H_
diff --git a/skia/ext/canvas_paint_linux.h b/skia/ext/canvas_paint_linux.h
new file mode 100644
index 0000000..d05f1d6
--- /dev/null
+++ b/skia/ext/canvas_paint_linux.h
@@ -0,0 +1,99 @@
+
+// Copyright (c) 2009 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_CANVAS_PAINT_LINUX_H_
+#define SKIA_EXT_CANVAS_PAINT_LINUX_H_
+
+#include "skia/ext/platform_canvas.h"
+
+namespace skia {
+
+// A class designed to translate skia painting into a region in a
+// GdkWindow. This class has been adapted from the class with the same name in
+// platform_canvas_win.h. On construction, it will set up a context for
+// painting into, and on destruction, it will commit it to the GdkWindow.
+template <class T>
+class CanvasPaintT : public T {
+ public:
+ // This constructor assumes the result is opaque.
+ explicit CanvasPaintT(GdkEventExpose* event)
+ : surface_(NULL),
+ window_(event->window),
+ rectangle_(event->area),
+ composite_alpha_(false) {
+ init(true);
+ }
+
+ CanvasPaintT(GdkEventExpose* event, bool opaque)
+ : surface_(NULL),
+ window_(event->window),
+ rectangle_(event->area),
+ composite_alpha_(false) {
+ init(opaque);
+ }
+
+ virtual ~CanvasPaintT() {
+ if (!is_empty()) {
+ T::restoreToCount(1);
+
+ // Blit the dirty rect to the window.
+ cairo_t* cr = gdk_cairo_create(window_);
+ if (composite_alpha_)
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_surface(cr, surface_, rectangle_.x, rectangle_.y);
+ cairo_rectangle(cr, rectangle_.x, rectangle_.y,
+ rectangle_.width, rectangle_.height);
+ cairo_fill(cr);
+ cairo_destroy(cr);
+ }
+ }
+
+ // Sets whether the bitmap is composited in such a way that the alpha channel
+ // is honored. This is only useful if you've enabled an RGBA colormap on the
+ // widget. The default is false.
+ void set_composite_alpha(bool composite_alpha) {
+ composite_alpha_ = composite_alpha;
+ }
+
+ // Returns true if the invalid region is empty. The caller should call this
+ // function to determine if anything needs painting.
+ bool is_empty() const {
+ return rectangle_.width == 0 || rectangle_.height == 0;
+ }
+
+ const GdkRectangle& rectangle() const {
+ return rectangle_;
+ }
+
+ private:
+ void init(bool opaque) {
+ if (!T::initialize(rectangle_.width, rectangle_.height, opaque, NULL)) {
+ // Cause a deliberate crash;
+ *(char*) 0 = 0;
+ }
+
+ // Need to translate so that the dirty region appears at the origin of the
+ // surface.
+ T::translate(-SkIntToScalar(rectangle_.x), -SkIntToScalar(rectangle_.y));
+
+ surface_ = T::getTopPlatformDevice().beginPlatformPaint();
+ }
+
+ cairo_surface_t* surface_;
+ GdkWindow* window_;
+ GdkRectangle rectangle_;
+ // See description above setter.
+ bool composite_alpha_;
+
+ // Disallow copy and assign.
+ CanvasPaintT(const CanvasPaintT&);
+ CanvasPaintT& operator=(const CanvasPaintT&);
+};
+
+typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint;
+
+} // namespace skia
+
+#endif // SKIA_EXT_CANVAS_PAINT_LINUX_H_
diff --git a/skia/ext/canvas_paint_win.h b/skia/ext/canvas_paint_win.h
new file mode 100644
index 0000000..ebf1ba0
--- /dev/null
+++ b/skia/ext/canvas_paint_win.h
@@ -0,0 +1,132 @@
+// Copyright (c) 2009 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_CANVAS_PAINT_WIN_H_
+#define SKIA_EXT_CANVAS_PAINT_WIN_H_
+
+#include "skia/ext/platform_canvas.h"
+
+namespace skia {
+
+// A class designed to help with WM_PAINT operations on Windows. It will
+// do BeginPaint/EndPaint on init/destruction, and will create the bitmap and
+// canvas with the correct size and transform for the dirty rect. The bitmap
+// will be automatically painted to the screen on destruction.
+//
+// You MUST call isEmpty before painting to determine if anything needs
+// painting. Sometimes the dirty rect can actually be empty, and this makes
+// the bitmap functions we call unhappy. The caller should not paint in this
+// case.
+//
+// Therefore, all you need to do is:
+// case WM_PAINT: {
+// gfx::PlatformCanvasPaint canvas(hwnd);
+// if (!canvas.isEmpty()) {
+// ... paint to the canvas ...
+// }
+// return 0;
+// }
+template <class T>
+class CanvasPaintT : public T {
+ public:
+ // This constructor assumes the canvas is opaque.
+ explicit CanvasPaintT(HWND hwnd) : hwnd_(hwnd), paint_dc_(NULL),
+ for_paint_(true) {
+ memset(&ps_, 0, sizeof(ps_));
+ initPaint(true);
+ }
+
+ CanvasPaintT(HWND hwnd, bool opaque) : hwnd_(hwnd), paint_dc_(NULL),
+ for_paint_(true) {
+ memset(&ps_, 0, sizeof(ps_));
+ initPaint(opaque);
+ }
+
+ // Creates a CanvasPaintT for the specified region that paints to the
+ // specified dc. This does NOT do BeginPaint/EndPaint.
+ CanvasPaintT(HDC dc, bool opaque, int x, int y, int w, int h)
+ : hwnd_(NULL),
+ paint_dc_(dc),
+ for_paint_(false) {
+ memset(&ps_, 0, sizeof(ps_));
+ ps_.rcPaint.left = x;
+ ps_.rcPaint.right = x + w;
+ ps_.rcPaint.top = y;
+ ps_.rcPaint.bottom = y + h;
+ init(opaque);
+ }
+
+ virtual ~CanvasPaintT() {
+ if (!isEmpty()) {
+ restoreToCount(1);
+ // Commit the drawing to the screen
+ getTopPlatformDevice().drawToHDC(paint_dc_,
+ ps_.rcPaint.left, ps_.rcPaint.top,
+ NULL);
+ }
+ if (for_paint_)
+ EndPaint(hwnd_, &ps_);
+ }
+
+ // Returns true if the invalid region is empty. The caller should call this
+ // function to determine if anything needs painting.
+ bool isEmpty() const {
+ return ps_.rcPaint.right - ps_.rcPaint.left == 0 ||
+ ps_.rcPaint.bottom - ps_.rcPaint.top == 0;
+ }
+
+ // Use to access the Windows painting parameters, especially useful for
+ // getting the bounding rect for painting: paintstruct().rcPaint
+ const PAINTSTRUCT& paintStruct() const {
+ return ps_;
+ }
+
+ // Returns the DC that will be painted to
+ HDC paintDC() const {
+ return paint_dc_;
+ }
+
+ protected:
+ HWND hwnd_;
+ HDC paint_dc_;
+ PAINTSTRUCT ps_;
+
+ private:
+ void initPaint(bool opaque) {
+ paint_dc_ = BeginPaint(hwnd_, &ps_);
+
+ init(opaque);
+ }
+
+ void init(bool opaque) {
+ // FIXME(brettw) for ClearType, we probably want to expand the bounds of
+ // painting by one pixel so that the boundaries will be correct (ClearType
+ // text can depend on the adjacent pixel). Then we would paint just the
+ // inset pixels to the screen.
+ const int width = ps_.rcPaint.right - ps_.rcPaint.left;
+ const int height = ps_.rcPaint.bottom - ps_.rcPaint.top;
+ if (!initialize(width, height, opaque, NULL)) {
+ // Cause a deliberate crash;
+ *(char*) 0 = 0;
+ }
+
+ // This will bring the canvas into the screen coordinate system for the
+ // dirty rect
+ translate(SkIntToScalar(-ps_.rcPaint.left),
+ SkIntToScalar(-ps_.rcPaint.top));
+ }
+
+ // If true, this canvas was created for a BeginPaint.
+ const bool for_paint_;
+
+ // Disallow copy and assign.
+ CanvasPaintT(const CanvasPaintT&);
+ CanvasPaintT& operator=(const CanvasPaintT&);
+};
+
+typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint;
+
+} // namespace skia
+
+#endif // SKIA_EXT_CANVAS_PAINT_WIN_H_
diff --git a/skia/ext/platform_canvas.cc b/skia/ext/platform_canvas.cc
new file mode 100644
index 0000000..9121a0d
--- /dev/null
+++ b/skia/ext/platform_canvas.cc
@@ -0,0 +1,26 @@
+// Copyright (c) 2006-2008 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/platform_canvas.h"
+#include "third_party/skia/include/core/SkTypes.h"
+
+namespace skia {
+
+SkDevice* PlatformCanvas::setBitmapDevice(const SkBitmap&) {
+ SkASSERT(false); // Should not be called.
+ return NULL;
+}
+
+PlatformDevice& PlatformCanvas::getTopPlatformDevice() const {
+ // All of our devices should be our special PlatformDevice.
+ SkCanvas::LayerIter iter(const_cast<PlatformCanvas*>(this), false);
+ return *static_cast<PlatformDevice*>(iter.device());
+}
+
+// static
+size_t PlatformCanvas::StrideForWidth(unsigned width) {
+ return 4 * width;
+}
+
+} // namespace skia
diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h
index e0883e3..f16fa1f 100644
--- a/skia/ext/platform_canvas.h
+++ b/skia/ext/platform_canvas.h
@@ -2,26 +2,122 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Declare a platform-neutral name for this platform's canvas class
-// that can be used by upper-level classes that just need to pass a reference
-// around.
+#ifndef SKIA_EXT_PLATFORM_CANVAS_H_
+#define SKIA_EXT_PLATFORM_CANVAS_H_
-#if defined(WIN32)
-#include "skia/ext/platform_canvas_win.h"
-#elif defined(__APPLE__)
-#include "skia/ext/platform_canvas_mac.h"
-#elif defined(__linux__)
-#include "skia/ext/platform_canvas_linux.h"
-#endif
+// The platform-specific device will include the necessary platform headers
+// to get the surface type.
+#include "skia/ext/platform_device.h"
+#include "third_party/skia/include/core/SkCanvas.h"
namespace skia {
+// This class is a specialization of the regular SkCanvas that is designed to
+// work with a PlatformDevice to manage platform-specific drawing. It allows
+// using both Skia operations and platform-specific operations.
+class PlatformCanvas : public SkCanvas {
+ public:
+ // Set is_opaque if you are going to erase the bitmap and not use
+ // transparency: this will enable some optimizations.
+ // If you use the version with no arguments, you MUST call initialize()
+ PlatformCanvas();
+ PlatformCanvas(int width, int height, bool is_opaque);
+ virtual ~PlatformCanvas();
+
#if defined(WIN32)
-typedef PlatformCanvasWin PlatformCanvas;
+ // Windows ------------------------------------------------------------------
+
+ // The shared_section parameter is passed to gfx::PlatformDevice::create.
+ // See it for details.
+ PlatformCanvas(int width, int height, bool is_opaque, HANDLE shared_section);
+
+ // For two-part init, call if you use the no-argument constructor above. Note
+ // that we want this to optionally match the Linux initialize if you only
+ // pass 3 arguments, hence the evil default argument.
+ bool initialize(int width, int height, bool is_opaque,
+ HANDLE shared_section = NULL);
+
#elif defined(__APPLE__)
-typedef PlatformCanvasMac PlatformCanvas;
+ // Mac -----------------------------------------------------------------------
+
+ PlatformCanvas(int width, int height, bool is_opaque,
+ CGContextRef context);
+ PlatformCanvas(int width, int height, bool is_opaque, uint8_t* context);
+
+ // For two-part init, call if you use the no-argument constructor above
+ bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL);
+
#elif defined(__linux__)
-typedef PlatformCanvasLinux PlatformCanvas;
+ // Linux ---------------------------------------------------------------------
+
+ // Construct a canvas from the given memory region. The memory is not cleared
+ // first. @data must be, at least, @height * StrideForWidth(@width) bytes.
+ PlatformCanvas(int width, int height, bool is_opaque, uint8_t* data);
+
+ // For two-part init, call if you use the no-argument constructor above
+ bool initialize(int width, int height, bool is_opaque, uint8_t* data = NULL);
+
#endif
+ // Shared --------------------------------------------------------------------
+
+ // These calls should surround calls to platform drawing routines, the
+ // surface returned here can be used with the native platform routines
+ //
+ // Call endPlatformPaint when you are done and want to use Skia operations
+ // after calling the platform-specific beginPlatformPaint; this will
+ // synchronize the bitmap to OS if necessary.
+ PlatformDevice::PlatformSurface beginPlatformPaint();
+ void endPlatformPaint();
+
+ // Returns the platform device pointer of the topmost rect with a non-empty
+ // clip. In practice, this is usually either the top layer or nothing, since
+ // we usually set the clip to new layers when we make them.
+ //
+ // If there is no layer that is not all clipped out, this will return a
+ // dummy device so callers do not have to check. If you are concerned about
+ // performance, check the clip before doing any painting.
+ //
+ // This is different than SkCanvas' getDevice, because that returns the
+ // bottommost device.
+ //
+ // Danger: the resulting device should not be saved. It will be invalidated
+ // by the next call to save() or restore().
+ PlatformDevice& getTopPlatformDevice() const;
+
+ // Return the stride (length of a line in bytes) for the given width. Because
+ // we use 32-bits per pixel, this will be roughly 4*width. However, for
+ // alignment reasons we may wish to increase that.
+ static size_t StrideForWidth(unsigned width);
+
+ // Allow callers to see the non-virtual function even though we have an
+ // override of a virtual one.
+ // FIXME(brettw) is this necessary?
+ using SkCanvas::clipRect;
+
+ protected:
+ // Creates a device store for use by the canvas. We override this so that
+ // the device is always our own so we know that we can use platform
+ // operations on it.
+ virtual SkDevice* createDevice(SkBitmap::Config,
+ int width,
+ int height,
+ bool is_opaque,
+ bool isForLayer);
+
+ private:
+ // Unimplemented. This is to try to prevent people from calling this function
+ // on SkCanvas. SkCanvas' version is not virtual, so we can't prevent this
+ // 100%, but hopefully this will make people notice and not use the function.
+ // Calling SkCanvas' version will create a new device which is not compatible
+ // with us and we will crash if somebody tries to draw into it with
+ // CoreGraphics.
+ virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap);
+
+ // Disallow copy and assign.
+ PlatformCanvas(const PlatformCanvas&);
+ PlatformCanvas& operator=(const PlatformCanvas&);
+};
} // namespace skia
+
+#endif // SKIA_EXT_PLATFORM_CANVAS_H_
diff --git a/skia/ext/platform_canvas_linux.cc b/skia/ext/platform_canvas_linux.cc
index 6ea8581..61e8404 100644
--- a/skia/ext/platform_canvas_linux.cc
+++ b/skia/ext/platform_canvas_linux.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "skia/ext/platform_canvas_linux.h"
+#include "skia/ext/platform_canvas.h"
#include <cairo/cairo.h>
@@ -12,39 +12,28 @@
namespace skia {
-PlatformCanvasLinux::PlatformCanvasLinux() : SkCanvas() {
+PlatformCanvas::PlatformCanvas() : SkCanvas() {
}
-PlatformCanvasLinux::PlatformCanvasLinux(int width, int height, bool is_opaque)
+PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque)
: SkCanvas() {
if (!initialize(width, height, is_opaque))
SK_CRASH();
}
-PlatformCanvasLinux::PlatformCanvasLinux(int width, int height, bool is_opaque,
- uint8_t* data)
+PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque,
+ uint8_t* data)
: SkCanvas() {
if (!initialize(width, height, is_opaque, data))
SK_CRASH();
}
-PlatformCanvasLinux::~PlatformCanvasLinux() {
+PlatformCanvas::~PlatformCanvas() {
}
-
-bool PlatformCanvasLinux::initialize(int width, int height, bool is_opaque) {
- SkDevice* device = createPlatformDevice(width, height, is_opaque);
- if (!device)
- return false;
-
- setDevice(device);
- device->unref(); // was created with refcount 1, and setDevice also refs
- return true;
-}
-
-bool PlatformCanvasLinux::initialize(int width, int height, bool is_opaque,
- uint8_t* data) {
+bool PlatformCanvas::initialize(int width, int height, bool is_opaque,
+ uint8_t* data) {
SkDevice* device =
- BitmapPlatformDeviceLinux::Create(width, height, is_opaque, data);
+ BitmapPlatformDevice::Create(width, height, is_opaque, data);
if (!device)
return false;
@@ -53,33 +42,21 @@ bool PlatformCanvasLinux::initialize(int width, int height, bool is_opaque,
return true;
}
-cairo_surface_t* PlatformCanvasLinux::beginPlatformPaint() {
+cairo_surface_t* PlatformCanvas::beginPlatformPaint() {
return getTopPlatformDevice().beginPlatformPaint();
}
-PlatformDeviceLinux& PlatformCanvasLinux::getTopPlatformDevice() const {
- // All of our devices should be our special PlatformDevice.
- SkCanvas::LayerIter iter(const_cast<PlatformCanvasLinux*>(this), false);
- return *static_cast<PlatformDeviceLinux*>(iter.device());
+void PlatformCanvas::endPlatformPaint() {
+ // We don't need to do anything on Linux here.
}
-SkDevice* PlatformCanvasLinux::createDevice(SkBitmap::Config config,
- int width,
- int height,
- bool is_opaque, bool isForLayer) {
+SkDevice* PlatformCanvas::createDevice(SkBitmap::Config config,
+ int width,
+ int height,
+ bool is_opaque,
+ bool isForLayer) {
SkASSERT(config == SkBitmap::kARGB_8888_Config);
- return createPlatformDevice(width, height, is_opaque);
-}
-
-SkDevice* PlatformCanvasLinux::createPlatformDevice(int width,
- int height,
- bool is_opaque) {
- return BitmapPlatformDeviceLinux::Create(width, height, is_opaque);
-}
-
-// static
-size_t PlatformCanvasLinux::StrideForWidth(unsigned width) {
- return cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
+ return BitmapPlatformDevice::Create(width, height, is_opaque);
}
} // namespace skia
diff --git a/skia/ext/platform_canvas_linux.h b/skia/ext/platform_canvas_linux.h
deleted file mode 100644
index 47e8162..0000000
--- a/skia/ext/platform_canvas_linux.h
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright (c) 2006-2008 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_PLATFORM_CANVAS_LINUX_H_
-#define SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
-
-#include <unistd.h>
-
-#include "skia/ext/platform_device_linux.h"
-
-#include <cairo/cairo.h>
-#include <gdk/gdk.h>
-
-namespace skia {
-
-// This class is a specialization of the regular SkCanvas that is designed to
-// work with a gfx::PlatformDevice to manage platform-specific drawing. It
-// allows using both Skia operations and platform-specific operations.
-class PlatformCanvasLinux : public SkCanvas {
- public:
- // Set is_opaque if you are going to erase the bitmap and not use
- // tranparency: this will enable some optimizations. The shared_section
- // parameter is passed to gfx::PlatformDevice::create. See it for details.
- //
- // If you use the version with no arguments, you MUST call initialize()
- PlatformCanvasLinux();
- PlatformCanvasLinux(int width, int height, bool is_opaque);
- // Construct a canvas from the given memory region. The memory is not cleared
- // first. @data must be, at least, @height * StrideForWidth(@width) bytes.
- PlatformCanvasLinux(int width, int height, bool is_opaque, uint8_t* data);
- virtual ~PlatformCanvasLinux();
-
- // For two-part init, call if you use the no-argument constructor above
- bool initialize(int width, int height, bool is_opaque);
- bool initialize(int width, int height, bool is_opaque, uint8_t* data);
-
- // These calls should surround calls to platform-specific drawing routines.
- // The cairo_surface_t* returned by beginPlatformPaint represents the
- // memory that can be used to draw into.
- // endPlatformPaint is a no-op; it is used for symmetry with Windows.
- cairo_surface_t* beginPlatformPaint();
- void endPlatformPaint() {}
-
- // Returns the platform device pointer of the topmost rect with a non-empty
- // clip. Both the windows and mac versions have an equivalent of this method;
- // a Linux version is added for compatibility.
- PlatformDeviceLinux& getTopPlatformDevice() const;
-
- // Return the stride (length of a line in bytes) for the given width. Because
- // we use 32-bits per pixel, this will be roughly 4*width. However, for
- // alignment reasons we may wish to increase that.
- static size_t StrideForWidth(unsigned width);
-
- protected:
- // Creates a device store for use by the canvas. We override this so that
- // the device is always our own so we know that we can use GDI operations
- // on it. Simply calls into createPlatformDevice().
- virtual SkDevice* createDevice(SkBitmap::Config, int width, int height,
- bool is_opaque, bool isForLayer);
-
- // Creates a device store for use by the canvas. By default, it creates a
- // BitmapPlatformDevice object. Can be overridden to change the object type.
- virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque);
-
- // Disallow copy and assign.
- PlatformCanvasLinux(const PlatformCanvasLinux&);
- PlatformCanvasLinux& operator=(const PlatformCanvasLinux&);
-};
-
-// A class designed to translate skia painting into a region in a
-// GdkWindow. This class has been adapted from the class with the same name in
-// platform_canvas_win.h. On construction, it will set up a context for
-// painting into, and on destruction, it will commit it to the GdkWindow.
-template <class T>
-class CanvasPaintT : public T {
- public:
- explicit CanvasPaintT(GdkEventExpose* event)
- : surface_(NULL),
- window_(event->window),
- rectangle_(event->area),
- composite_alpha_(false) {
- init(true);
- }
-
- CanvasPaintT(GdkEventExpose* event, bool opaque)
- : surface_(NULL),
- window_(event->window),
- rectangle_(event->area),
- composite_alpha_(false) {
- init(opaque);
- }
-
- virtual ~CanvasPaintT() {
- if (!isEmpty()) {
- T::restoreToCount(1);
-
- // Blit the dirty rect to the window.
- cairo_t* cr = gdk_cairo_create(window_);
- if (composite_alpha_)
- cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
- cairo_set_source_surface(cr, surface_, rectangle_.x, rectangle_.y);
- cairo_rectangle(cr, rectangle_.x, rectangle_.y,
- rectangle_.width, rectangle_.height);
- cairo_fill(cr);
- cairo_destroy(cr);
- }
- }
-
- // Sets whether the bitmap is composited in such a way that the alpha channel
- // is honored. This is only useful if you've enabled an RGBA colormap on the
- // widget. The default is false.
- void set_composite_alpha(bool composite_alpha) {
- composite_alpha_ = composite_alpha;
- }
-
- // Returns true if the invalid region is empty. The caller should call this
- // function to determine if anything needs painting.
- bool isEmpty() const {
- return rectangle_.width == 0 || rectangle_.height == 0;
- }
-
- const GdkRectangle& rectangle() const {
- return rectangle_;
- }
-
- private:
- void init(bool opaque) {
- if (!T::initialize(rectangle_.width, rectangle_.height, opaque, NULL)) {
- // Cause a deliberate crash;
- *(char*) 0 = 0;
- }
-
- // Need to translate so that the dirty region appears at the origin of the
- // surface.
- T::translate(-SkIntToScalar(rectangle_.x), -SkIntToScalar(rectangle_.y));
-
- surface_ = T::getTopPlatformDevice().beginPlatformPaint();
- }
-
- cairo_surface_t* surface_;
- GdkWindow* window_;
- GdkRectangle rectangle_;
- // See description above setter.
- bool composite_alpha_;
-
- // Disallow copy and assign.
- CanvasPaintT(const CanvasPaintT&);
- CanvasPaintT& operator=(const CanvasPaintT&);
-};
-
-} // namespace skia
-
-#endif // SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
diff --git a/skia/ext/platform_canvas_mac.cc b/skia/ext/platform_canvas_mac.cc
index ba1549d..4e42bb1 100644
--- a/skia/ext/platform_canvas_mac.cc
+++ b/skia/ext/platform_canvas_mac.cc
@@ -2,118 +2,68 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "skia/ext/platform_canvas_mac.h"
+#include "skia/ext/platform_canvas.h"
#include "skia/ext/bitmap_platform_device_mac.h"
#include "third_party/skia/include/core/SkTypes.h"
namespace skia {
-PlatformCanvasMac::PlatformCanvasMac() : SkCanvas() {
+PlatformCanvas::PlatformCanvas() : SkCanvas() {
}
-PlatformCanvasMac::PlatformCanvasMac(int width, int height, bool is_opaque)
+PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque)
: SkCanvas() {
initialize(width, height, is_opaque);
}
-PlatformCanvasMac::PlatformCanvasMac(int width,
- int height,
- bool is_opaque,
- CGContextRef context)
+PlatformCanvas::PlatformCanvas(int width,
+ int height,
+ bool is_opaque,
+ CGContextRef context)
: SkCanvas() {
initialize(width, height, is_opaque);
}
-PlatformCanvasMac::PlatformCanvasMac(int width,
- int height,
- bool is_opaque,
- uint8_t* data)
+PlatformCanvas::PlatformCanvas(int width,
+ int height,
+ bool is_opaque,
+ uint8_t* data)
: SkCanvas() {
initialize(width, height, is_opaque, data);
}
-PlatformCanvasMac::~PlatformCanvasMac() {
+PlatformCanvas::~PlatformCanvas() {
}
-bool PlatformCanvasMac::initialize(int width,
- int height,
- bool is_opaque) {
- SkDevice* device = createPlatformDevice(width, height, is_opaque, NULL);
+bool PlatformCanvas::initialize(int width,
+ int height,
+ bool is_opaque,
+ uint8_t* data) {
+ SkDevice* device = BitmapPlatformDevice::Create(NULL, width, height,
+ is_opaque);
if (!device)
return false;
setDevice(device);
- device->unref(); // was created with refcount 1, and setDevice also refs
+ device->unref(); // Was created with refcount 1, and setDevice also refs.
return true;
}
-bool PlatformCanvasMac::initialize(int width,
- int height,
- bool is_opaque,
- uint8_t* data) {
- CGContextRef context = NULL;
- CGColorSpaceRef colorSpace;
-
- colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
- context = CGBitmapContextCreate(
- data, width, height, 8 /* bits per plane */, 4 * width /* stride */,
- colorSpace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
- CGColorSpaceRelease(colorSpace);
- if (!context)
- return false;
- // Change the coordinate system to match WebCore's
- CGContextTranslateCTM(context, 0, height);
- CGContextScaleCTM(context, 1.0, -1.0);
-
- SkDevice* device = createPlatformDevice(width, height, is_opaque, context);
- if (!device)
- return false;
-
- setDevice(device);
- device->unref(); // was created with refcount 1, and setDevice also refs
- return true;
-}
-
-CGContextRef PlatformCanvasMac::beginPlatformPaint() {
+CGContextRef PlatformCanvas::beginPlatformPaint() {
return getTopPlatformDevice().GetBitmapContext();
}
-void PlatformCanvasMac::endPlatformPaint() {
- // flushing will be done in onAccessBitmap
-}
-
-PlatformDeviceMac& PlatformCanvasMac::getTopPlatformDevice() const {
- // All of our devices should be our special PlatformDeviceMac.
- SkCanvas::LayerIter iter(const_cast<PlatformCanvasMac*>(this), false);
- return *static_cast<PlatformDeviceMac*>(iter.device());
+void PlatformCanvas::endPlatformPaint() {
+ // Flushing will be done in onAccessBitmap.
}
-SkDevice* PlatformCanvasMac::createDevice(SkBitmap::Config config,
- int width,
- int height,
- bool is_opaque, bool isForLayer) {
+SkDevice* PlatformCanvas::createDevice(SkBitmap::Config config,
+ int width,
+ int height,
+ bool is_opaque, bool isForLayer) {
SkASSERT(config == SkBitmap::kARGB_8888_Config);
- return createPlatformDevice(width, height, is_opaque, NULL);
-}
-
-SkDevice* PlatformCanvasMac::createPlatformDevice(int width,
- int height,
- bool is_opaque,
- CGContextRef context) {
- SkDevice* device = BitmapPlatformDeviceMac::Create(context, width, height,
- is_opaque);
- return device;
-}
-
-SkDevice* PlatformCanvasMac::setBitmapDevice(const SkBitmap&) {
- SkASSERT(false);
- return NULL;
-}
-
-// static
-size_t PlatformCanvasMac::StrideForWidth(unsigned width) {
- return 4 * width;
+ return BitmapPlatformDevice::Create(NULL, width, height, is_opaque);
}
} // namespace skia
diff --git a/skia/ext/platform_canvas_mac.h b/skia/ext/platform_canvas_mac.h
deleted file mode 100644
index d969246..0000000
--- a/skia/ext/platform_canvas_mac.h
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright (c) 2006-2008 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_PLATFORM_CANVAS_MAC_H_
-#define SKIA_EXT_PLATFORM_CANVAS_MAC_H_
-
-#include "skia/ext/platform_device_mac.h"
-
-#include "third_party/skia/include/core/SkCanvas.h"
-
-namespace skia {
-
-// This class is a specialization of the regular SkCanvas that is designed to
-// work with a gfx::PlatformDevice to manage platform-specific drawing. It
-// allows using both Skia operations and platform-specific operations.
-class PlatformCanvasMac : public SkCanvas {
- public:
- // Set is_opaque if you are going to erase the bitmap and not use
- // tranparency: this will enable some optimizations. The shared_section
- // parameter is passed to gfx::PlatformDevice::create. See it for details.
- //
- // If you use the version with no arguments, you MUST call initialize()
- PlatformCanvasMac();
- PlatformCanvasMac(int width, int height, bool is_opaque);
- PlatformCanvasMac(int width, int height, bool is_opaque,
- CGContextRef context);
- PlatformCanvasMac(int width, int height, bool is_opaque,
- uint8_t* context);
- virtual ~PlatformCanvasMac();
-
- // For two-part init, call if you use the no-argument constructor above
- bool initialize(int width, int height, bool is_opaque);
- bool initialize(int width, int height, bool is_opaque, uint8_t* data);
-
- // These calls should surround calls to platform drawing routines. The CG
- // context returned by beginPlatformPaint is the one that can be used to
- // draw into.
- // Call endPlatformPaint when you are done and want to use Skia operations
- // again; this will synchronize the bitmap.
- virtual CGContextRef beginPlatformPaint();
- virtual void endPlatformPaint();
-
- // Returns the platform device pointer of the topmost rect with a non-empty
- // clip. In practice, this is usually either the top layer or nothing, since
- // we usually set the clip to new layers when we make them.
- //
- // If there is no layer that is not all clipped out, this will return a
- // dummy device so callers do not have to check. If you are concerned about
- // performance, check the clip before doing any painting.
- //
- // This is different than SkCanvas' getDevice, because that returns the
- // bottommost device.
- //
- // Danger: the resulting device should not be saved. It will be invalidated
- // by the next call to save() or restore().
- PlatformDeviceMac& getTopPlatformDevice() const;
-
- // Allow callers to see the non-virtual function even though we have an
- // override of a virtual one.
- using SkCanvas::clipRect;
-
- // Return the stride (length of a line in bytes) for the given width. Because
- // we use 32-bits per pixel, this will be roughly 4*width. However, for
- // alignment reasons we may wish to increase that.
- static size_t StrideForWidth(unsigned width);
-
- protected:
- // Creates a device store for use by the canvas. We override this so that
- // the device is always our own so we know that we can use GDI operations
- // on it. Simply calls into createPlatformDevice().
- virtual SkDevice* createDevice(SkBitmap::Config, int width, int height,
- bool is_opaque, bool isForLayer);
-
- // Creates a device store for use by the canvas. By default, it creates a
- // BitmapPlatformDevice object. Can be overridden to change the object type.
- virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque,
- CGContextRef context);
-
- private:
- // Unimplemented. This is to try to prevent people from calling this function
- // on SkCanvas. SkCanvas' version is not virtual, so we can't prevent this
- // 100%, but hopefully this will make people notice and not use the function.
- // Calling SkCanvas' version will create a new device which is not compatible
- // with us and we will crash if somebody tries to draw into it with
- // CoreGraphics.
- SkDevice* setBitmapDevice(const SkBitmap& bitmap);
-
- // Disallow copy and assign.
- PlatformCanvasMac(const PlatformCanvasMac&);
- PlatformCanvasMac& operator=(const PlatformCanvasMac&);
-};
-
-} // namespace skia
-
-#endif // SKIA_EXT_PLATFORM_CANVAS_MAC_H_
diff --git a/skia/ext/platform_canvas_win.cc b/skia/ext/platform_canvas_win.cc
index fe0f852..d81b4f9 100644
--- a/skia/ext/platform_canvas_win.cc
+++ b/skia/ext/platform_canvas_win.cc
@@ -5,9 +5,8 @@
#include <windows.h>
#include <psapi.h>
-#include "skia/ext/platform_canvas_win.h"
-
#include "skia/ext/bitmap_platform_device_win.h"
+#include "skia/ext/platform_canvas.h"
namespace skia {
@@ -54,20 +53,20 @@ __declspec(noinline) void CrashIfInvalidSection(HANDLE shared_section) {
CHECK(::GetHandleInformation(shared_section, &handle_info) == TRUE);
}
-PlatformCanvasWin::PlatformCanvasWin() : SkCanvas() {
+PlatformCanvas::PlatformCanvas() : SkCanvas() {
}
-PlatformCanvasWin::PlatformCanvasWin(int width, int height, bool is_opaque)
+PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque)
: SkCanvas() {
bool initialized = initialize(width, height, is_opaque, NULL);
if (!initialized)
CrashForBitmapAllocationFailure(width, height);
}
-PlatformCanvasWin::PlatformCanvasWin(int width,
- int height,
- bool is_opaque,
- HANDLE shared_section)
+PlatformCanvas::PlatformCanvas(int width,
+ int height,
+ bool is_opaque,
+ HANDLE shared_section)
: SkCanvas() {
bool initialized = initialize(width, height, is_opaque, shared_section);
if (!initialized) {
@@ -76,15 +75,15 @@ PlatformCanvasWin::PlatformCanvasWin(int width,
}
}
-PlatformCanvasWin::~PlatformCanvasWin() {
+PlatformCanvas::~PlatformCanvas() {
}
-bool PlatformCanvasWin::initialize(int width,
- int height,
- bool is_opaque,
- HANDLE shared_section) {
- SkDevice* device =
- createPlatformDevice(width, height, is_opaque, shared_section);
+bool PlatformCanvas::initialize(int width,
+ int height,
+ bool is_opaque,
+ HANDLE shared_section) {
+ SkDevice* device = BitmapPlatformDevice::create(width, height,
+ is_opaque, shared_section);
if (!device)
return false;
@@ -93,48 +92,21 @@ bool PlatformCanvasWin::initialize(int width,
return true;
}
-HDC PlatformCanvasWin::beginPlatformPaint() {
+HDC PlatformCanvas::beginPlatformPaint() {
return getTopPlatformDevice().getBitmapDC();
}
-void PlatformCanvasWin::endPlatformPaint() {
+void PlatformCanvas::endPlatformPaint() {
// we don't clear the DC here since it will be likely to be used again
// flushing will be done in onAccessBitmap
}
-PlatformDeviceWin& PlatformCanvasWin::getTopPlatformDevice() const {
- // All of our devices should be our special PlatformDevice.
- SkCanvas::LayerIter iter(const_cast<PlatformCanvasWin*>(this), false);
- return *static_cast<PlatformDeviceWin*>(iter.device());
-}
-
-SkDevice* PlatformCanvasWin::createDevice(SkBitmap::Config config,
- int width,
- int height,
- bool is_opaque, bool isForLayer) {
+SkDevice* PlatformCanvas::createDevice(SkBitmap::Config config,
+ int width,
+ int height,
+ bool is_opaque, bool isForLayer) {
SkASSERT(config == SkBitmap::kARGB_8888_Config);
- return createPlatformDevice(width, height, is_opaque, NULL);
-}
-
-SkDevice* PlatformCanvasWin::createPlatformDevice(int width,
- int height,
- bool is_opaque,
- HANDLE shared_section) {
- HDC screen_dc = GetDC(NULL);
- SkDevice* device = BitmapPlatformDeviceWin::create(screen_dc, width, height,
- is_opaque, shared_section);
- ReleaseDC(NULL, screen_dc);
- return device;
-}
-
-SkDevice* PlatformCanvasWin::setBitmapDevice(const SkBitmap&) {
- SkASSERT(false); // Should not be called.
- return NULL;
-}
-
-// static
-size_t PlatformCanvasWin::StrideForWidth(unsigned width) {
- return 4 * width;
+ return BitmapPlatformDevice::create(width, height, is_opaque, NULL);
}
} // namespace skia
diff --git a/skia/ext/platform_canvas_win.h b/skia/ext/platform_canvas_win.h
index d031ebf..8559bd4 100644
--- a/skia/ext/platform_canvas_win.h
+++ b/skia/ext/platform_canvas_win.h
@@ -1,203 +1,10 @@
-// Copyright (c) 2006-2008 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_PLATFORM_CANVAS_WIN_H_
-#define SKIA_EXT_PLATFORM_CANVAS_WIN_H_
-
-#include <windows.h>
-
-#include "skia/ext/platform_device_win.h"
-
-#include "third_party/skia/include/core/SkCanvas.h"
-
-namespace skia {
-
-// This class is a specialization of the regular SkCanvas that is designed to
-// work with a PlatformDevice to manage platform-specific drawing. It allows
-// using both Skia operations and platform-specific operations.
-class PlatformCanvasWin : public SkCanvas {
- public:
- // Set is_opaque if you are going to erase the bitmap and not use
- // transparency: this will enable some optimizations. The shared_section
- // parameter is passed to gfx::PlatformDevice::create. See it for details.
- //
- // If you use the version with no arguments, you MUST call initialize()
- PlatformCanvasWin();
- PlatformCanvasWin(int width, int height, bool is_opaque);
- PlatformCanvasWin(int width, int height, bool is_opaque,
- HANDLE shared_section);
- virtual ~PlatformCanvasWin();
-
- // For two-part init, call if you use the no-argument constructor above. Note
- // that we want this to optionally match the Linux initialize if you only
- // pass 3 arguments, hence the evil default argument.
- bool initialize(int width, int height, bool is_opaque,
- HANDLE shared_section = NULL);
-
- // These calls should surround calls to platform drawing routines, the DC
- // returned by beginPlatformPaint is the DC that can be used to draw into.
- // Call endPlatformPaint when you are done and want to use Skia operations
- // again; this will synchronize the bitmap to Windows.
- virtual HDC beginPlatformPaint();
- virtual void endPlatformPaint();
-
- // Returns the platform device pointer of the topmost rect with a non-empty
- // clip. In practice, this is usually either the top layer or nothing, since
- // we usually set the clip to new layers when we make them.
- //
- // If there is no layer that is not all clipped out, this will return a
- // dummy device so callers do not have to check. If you are concerned about
- // performance, check the clip before doing any painting.
- //
- // This is different than SkCanvas' getDevice, because that returns the
- // bottommost device.
- //
- // Danger: the resulting device should not be saved. It will be invalidated
- // by the next call to save() or restore().
- PlatformDeviceWin& getTopPlatformDevice() const;
-
- static size_t StrideForWidth(unsigned width);
-
- protected:
- // Creates a device store for use by the canvas. We override this so that
- // the device is always our own so we know that we can use GDI operations
- // on it. Simply calls into createPlatformDevice().
- virtual SkDevice* createDevice(SkBitmap::Config, int width, int height,
- bool is_opaque, bool isForLayer);
-
- // Creates a device store for use by the canvas. By default, it creates a
- // BitmapPlatformDeviceWin. Can be overridden to change the object type.
- virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque,
- HANDLE shared_section);
-
- private:
- // Unimplemented.
- virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap);
-
- // Disallow copy and assign.
- PlatformCanvasWin(const PlatformCanvasWin&);
- PlatformCanvasWin& operator=(const PlatformCanvasWin&);
-};
-
-// A class designed to help with WM_PAINT operations on Windows. It will
-// do BeginPaint/EndPaint on init/destruction, and will create the bitmap and
-// canvas with the correct size and transform for the dirty rect. The bitmap
-// will be automatically painted to the screen on destruction.
-//
-// You MUST call isEmpty before painting to determine if anything needs
-// painting. Sometimes the dirty rect can actually be empty, and this makes
-// the bitmap functions we call unhappy. The caller should not paint in this
-// case.
-//
-// Therefore, all you need to do is:
-// case WM_PAINT: {
-// gfx::PlatformCanvasWinPaint canvas(hwnd);
-// if (!canvas.isEmpty()) {
-// ... paint to the canvas ...
-// }
-// return 0;
-// }
-template <class T>
-class CanvasPaintT : public T {
- public:
- explicit CanvasPaintT(HWND hwnd) : hwnd_(hwnd), paint_dc_(NULL),
- for_paint_(true) {
- memset(&ps_, 0, sizeof(ps_));
- initPaint(true);
- }
-
- CanvasPaintT(HWND hwnd, bool opaque) : hwnd_(hwnd), paint_dc_(NULL),
- for_paint_(true) {
- memset(&ps_, 0, sizeof(ps_));
- initPaint(opaque);
- }
-
- // Creates a CanvasPaintT for the specified region that paints to the
- // specified dc. This does NOT do BeginPaint/EndPaint.
- CanvasPaintT(HDC dc, bool opaque, int x, int y, int w, int h)
- : hwnd_(NULL),
- paint_dc_(dc),
- for_paint_(false) {
- memset(&ps_, 0, sizeof(ps_));
- ps_.rcPaint.left = x;
- ps_.rcPaint.right = x + w;
- ps_.rcPaint.top = y;
- ps_.rcPaint.bottom = y + h;
- init(opaque);
- }
-
-
- virtual ~CanvasPaintT() {
- if (!isEmpty()) {
- restoreToCount(1);
- // Commit the drawing to the screen
- getTopPlatformDevice().drawToHDC(paint_dc_,
- ps_.rcPaint.left, ps_.rcPaint.top,
- NULL);
- }
- if (for_paint_)
- EndPaint(hwnd_, &ps_);
- }
-
- // Returns true if the invalid region is empty. The caller should call this
- // function to determine if anything needs painting.
- bool isEmpty() const {
- return ps_.rcPaint.right - ps_.rcPaint.left == 0 ||
- ps_.rcPaint.bottom - ps_.rcPaint.top == 0;
- }
-
- // Use to access the Windows painting parameters, especially useful for
- // getting the bounding rect for painting: paintstruct().rcPaint
- const PAINTSTRUCT& paintStruct() const {
- return ps_;
- }
-
- // Returns the DC that will be painted to
- HDC paintDC() const {
- return paint_dc_;
- }
-
- protected:
- HWND hwnd_;
- HDC paint_dc_;
- PAINTSTRUCT ps_;
-
- private:
- void initPaint(bool opaque) {
- paint_dc_ = BeginPaint(hwnd_, &ps_);
-
- init(opaque);
- }
-
- void init(bool opaque) {
- // FIXME(brettw) for ClearType, we probably want to expand the bounds of
- // painting by one pixel so that the boundaries will be correct (ClearType
- // text can depend on the adjacent pixel). Then we would paint just the
- // inset pixels to the screen.
- const int width = ps_.rcPaint.right - ps_.rcPaint.left;
- const int height = ps_.rcPaint.bottom - ps_.rcPaint.top;
- if (!initialize(width, height, opaque, NULL)) {
- // Cause a deliberate crash;
- *(char*) 0 = 0;
- }
-
- // This will bring the canvas into the screen coordinate system for the
- // dirty rect
- translate(SkIntToScalar(-ps_.rcPaint.left),
- SkIntToScalar(-ps_.rcPaint.top));
- }
-
- // If true, this canvas was created for a BeginPaint.
- const bool for_paint_;
-
- // Disallow copy and assign.
- CanvasPaintT(const CanvasPaintT&);
- CanvasPaintT& operator=(const CanvasPaintT&);
-};
-
-typedef CanvasPaintT<PlatformCanvasWin> PlatformCanvasWinPaint;
-
-} // namespace skia
-
-#endif // SKIA_EXT_PLATFORM_CANVAS_WIN_H_
+// Copyright (c) 2009 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.
+
+
+// TODO(brettw) erase this file. This file is necessary because
+// FontChromiumWin.cpp in WebKit includes it, and I want to avoid having to
+// synchronize the checkins to Chromium and WebKit.
+
+#include "skia/ext/platform_canvas.h"
diff --git a/skia/ext/platform_device.h b/skia/ext/platform_device.h
index 413a47f..00845ca 100644
--- a/skia/ext/platform_device.h
+++ b/skia/ext/platform_device.h
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Declare a platform-neutral name for this platform's device class
-// that can be used by upper-level classes that just need to pass a reference
-// around.
+#ifndef SKIA_EXT_PLATFORM_DEVICE_H_
+#define SKIA_EXT_PLATFORM_DEVICE_H_
+
+// This file provides an easy way to include the appropriate PlatformDevice
+// header file for your platform.
#if defined(WIN32)
#include "skia/ext/platform_device_win.h"
@@ -14,14 +16,4 @@
#include "skia/ext/platform_device_linux.h"
#endif
-namespace skia {
-
-#if defined(WIN32)
-typedef PlatformDeviceWin PlatformDevice;
-#elif defined(__APPLE__)
-typedef PlatformDeviceMac PlatformDevice;
-#elif defined(__linux__)
-typedef PlatformDeviceLinux PlatformDevice;
#endif
-
-} // namespace skia
diff --git a/skia/ext/platform_device_linux.cc b/skia/ext/platform_device_linux.cc
index e8d12ec..3cdf6e88 100644
--- a/skia/ext/platform_device_linux.cc
+++ b/skia/ext/platform_device_linux.cc
@@ -6,8 +6,7 @@
namespace skia {
-PlatformDeviceLinux::PlatformDeviceLinux(const SkBitmap& bitmap)
- : SkDevice(bitmap) {
+PlatformDevice::PlatformDevice(const SkBitmap& bitmap) : SkDevice(bitmap) {
}
} // namespace skia
diff --git a/skia/ext/platform_device_linux.h b/skia/ext/platform_device_linux.h
index e438d85a..c23a4d8 100644
--- a/skia/ext/platform_device_linux.h
+++ b/skia/ext/platform_device_linux.h
@@ -12,8 +12,10 @@ typedef struct _cairo_surface cairo_surface_t;
namespace skia {
// Blindly copying the mac hierarchy.
-class PlatformDeviceLinux : public SkDevice {
+class PlatformDevice : public SkDevice {
public:
+ typedef cairo_surface_t* PlatformSurface;
+
// Returns if the preferred rendering engine is vectorial or bitmap based.
virtual bool IsVectorial() = 0;
@@ -21,7 +23,7 @@ class PlatformDeviceLinux : public SkDevice {
protected:
// Forwards |bitmap| to SkDevice's constructor.
- PlatformDeviceLinux(const SkBitmap& bitmap);
+ PlatformDevice(const SkBitmap& bitmap);
};
} // namespace skia
diff --git a/skia/ext/platform_device_mac.cc b/skia/ext/platform_device_mac.cc
index b935b25..d61c605 100644
--- a/skia/ext/platform_device_mac.cc
+++ b/skia/ext/platform_device_mac.cc
@@ -35,18 +35,17 @@ bool constrain(int available_size, int* position, int *size) {
} // namespace
-PlatformDeviceMac::PlatformDeviceMac(const SkBitmap& bitmap)
- : SkDevice(bitmap) {
+PlatformDevice::PlatformDevice(const SkBitmap& bitmap) : SkDevice(bitmap) {
}
// Set up the CGContextRef for peaceful coexistence with Skia
-void PlatformDeviceMac::InitializeCGContext(CGContextRef context) {
+void PlatformDevice::InitializeCGContext(CGContextRef context) {
// CG defaults to the same settings as Skia
}
// static
-void PlatformDeviceMac::LoadPathToCGContext(CGContextRef context,
- const SkPath& path) {
+void PlatformDevice::LoadPathToCGContext(CGContextRef context,
+ const SkPath& path) {
// instead of a persistent attribute of the context, CG specifies the fill
// type per call, so we just have to load up the geometry.
CGContextBeginPath(context);
@@ -89,8 +88,8 @@ void PlatformDeviceMac::LoadPathToCGContext(CGContextRef context,
}
// static
-void PlatformDeviceMac::LoadTransformToCGContext(CGContextRef context,
- const SkMatrix& matrix) {
+void PlatformDevice::LoadTransformToCGContext(CGContextRef context,
+ const SkMatrix& matrix) {
// CoreGraphics can concatenate transforms, but not reset the current one.
// So in order to get the required behavior here, we need to first make
// the current transformation matrix identity and only then load the new one.
@@ -120,7 +119,7 @@ void PlatformDeviceMac::LoadTransformToCGContext(CGContextRef context,
}
// static
-void PlatformDeviceMac::LoadClippingRegionToCGContext(
+void PlatformDevice::LoadClippingRegionToCGContext(
CGContextRef context,
const SkRegion& region,
const SkMatrix& transformation) {
diff --git a/skia/ext/platform_device_mac.h b/skia/ext/platform_device_mac.h
index 2005e89..97efd7c 100644
--- a/skia/ext/platform_device_mac.h
+++ b/skia/ext/platform_device_mac.h
@@ -20,8 +20,10 @@ namespace skia {
// functions.
// This class is abstract and must be subclassed. It provides the basic
// interface to implement it either with or without a bitmap backend.
-class PlatformDeviceMac : public SkDevice {
+class PlatformDevice : public SkDevice {
public:
+ typedef CGContextRef PlatformSurface;
+
// The CGContext that corresponds to the bitmap, used for CoreGraphics
// operations drawing into the bitmap. This is possibly heavyweight, so it
// should exist only during one pass of rendering.
@@ -52,7 +54,7 @@ class PlatformDeviceMac : public SkDevice {
protected:
// Forwards |bitmap| to SkDevice's constructor.
- PlatformDeviceMac(const SkBitmap& bitmap);
+ PlatformDevice(const SkBitmap& bitmap);
// Loads the specified Skia transform into the device context
static void LoadTransformToCGContext(CGContextRef context,
diff --git a/skia/ext/platform_device_win.cc b/skia/ext/platform_device_win.cc
index d58b14a..7bb5bd9 100644
--- a/skia/ext/platform_device_win.cc
+++ b/skia/ext/platform_device_win.cc
@@ -12,12 +12,12 @@
namespace skia {
-PlatformDeviceWin::PlatformDeviceWin(const SkBitmap& bitmap)
+PlatformDevice::PlatformDevice(const SkBitmap& bitmap)
: SkDevice(bitmap) {
}
// static
-void PlatformDeviceWin::InitializeDC(HDC context) {
+void PlatformDevice::InitializeDC(HDC context) {
// Enables world transformation.
// If the GM_ADVANCED graphics mode is set, GDI always draws arcs in the
// counterclockwise direction in logical space. This is equivalent to the
@@ -57,7 +57,7 @@ void PlatformDeviceWin::InitializeDC(HDC context) {
}
// static
-void PlatformDeviceWin::LoadPathToDC(HDC context, const SkPath& path) {
+void PlatformDevice::LoadPathToDC(HDC context, const SkPath& path) {
switch (path.getFillType()) {
case SkPath::kWinding_FillType: {
int res = SetPolyFillMode(context, WINDING);
@@ -117,7 +117,7 @@ void PlatformDeviceWin::LoadPathToDC(HDC context, const SkPath& path) {
}
// static
-void PlatformDeviceWin::LoadTransformToDC(HDC dc, const SkMatrix& matrix) {
+void PlatformDevice::LoadTransformToDC(HDC dc, const SkMatrix& matrix) {
XFORM xf;
xf.eM11 = matrix[SkMatrix::kMScaleX];
xf.eM21 = matrix[SkMatrix::kMSkewX];
@@ -129,8 +129,8 @@ void PlatformDeviceWin::LoadTransformToDC(HDC dc, const SkMatrix& matrix) {
}
// static
-bool PlatformDeviceWin::SkPathToCubicPaths(CubicPaths* paths,
- const SkPath& skpath) {
+bool PlatformDevice::SkPathToCubicPaths(CubicPaths* paths,
+ const SkPath& skpath) {
paths->clear();
CubicPath* current_path = NULL;
SkPoint current_points[4];
@@ -192,9 +192,9 @@ bool PlatformDeviceWin::SkPathToCubicPaths(CubicPaths* paths,
}
// static
-void PlatformDeviceWin::LoadClippingRegionToDC(HDC context,
- const SkRegion& region,
- const SkMatrix& transformation) {
+void PlatformDevice::LoadClippingRegionToDC(HDC context,
+ const SkRegion& region,
+ const SkMatrix& transformation) {
HRGN hrgn;
if (region.isEmpty()) {
// region can be empty, in which case everything will be clipped.
diff --git a/skia/ext/platform_device_win.h b/skia/ext/platform_device_win.h
index 75319bb..82a27e21 100644
--- a/skia/ext/platform_device_win.h
+++ b/skia/ext/platform_device_win.h
@@ -22,8 +22,10 @@ namespace skia {
// to. It also provides functionality to play well with GDI drawing functions.
// This class is abstract and must be subclassed. It provides the basic
// interface to implement it either with or without a bitmap backend.
-class PlatformDeviceWin : public SkDevice {
+class PlatformDevice : public SkDevice {
public:
+ typedef HDC PlatformSurface;
+
// The DC that corresponds to the bitmap, used for GDI operations drawing
// into the bitmap. This is possibly heavyweight, so it should be existant
// only during one pass of rendering.
@@ -62,7 +64,7 @@ class PlatformDeviceWin : public SkDevice {
typedef std::vector<CubicPath> CubicPaths;
// Forwards |bitmap| to SkDevice's constructor.
- PlatformDeviceWin(const SkBitmap& bitmap);
+ PlatformDevice(const SkBitmap& bitmap);
// Loads the specified Skia transform into the device context, excluding
// perspective (which GDI doesn't support).
diff --git a/skia/ext/vector_canvas.cc b/skia/ext/vector_canvas.cc
index ea5542f..75b7310 100644
--- a/skia/ext/vector_canvas.cc
+++ b/skia/ext/vector_canvas.cc
@@ -4,7 +4,8 @@
#include "skia/ext/vector_canvas.h"
-#include "skia/ext/vector_device.h"
+#include "skia/ext/bitmap_platform_device_win.h"
+#include "skia/ext/vector_platform_device_win.h"
namespace skia {
@@ -32,7 +33,7 @@ bool VectorCanvas::initialize(HDC context, int width, int height) {
SkBounder* VectorCanvas::setBounder(SkBounder* bounder) {
if (!IsTopDeviceVectorial())
- return PlatformCanvasWin::setBounder(bounder);
+ return PlatformCanvas::setBounder(bounder);
// This function isn't used in the code. Verify this assumption.
SkASSERT(false);
@@ -59,13 +60,13 @@ SkDevice* VectorCanvas::createPlatformDevice(int width,
// TODO(maruel): http://b/1184002 1184002 When restoring a semi-transparent
// layer, i.e. merging it, we need to rasterize it because GDI doesn't
// support transparency except for AlphaBlend(). Right now, a
- // BitmapPlatformDeviceWin is created when VectorCanvas think a saveLayers()
+ // BitmapPlatformDevice is created when VectorCanvas think a saveLayers()
// call is being done. The way to save a layer would be to create an
// EMF-based VectorDevice and have this device registers the drawing. When
// playing back the device into a bitmap, do it at the printer's dpi instead
// of the layout's dpi (which is much lower).
- return PlatformCanvasWin::createPlatformDevice(width, height, is_opaque,
- shared_section);
+ return BitmapPlatformDevice::create(width, height,
+ is_opaque, shared_section);
}
// TODO(maruel): http://b/1183870 Look if it would be worth to increase the
@@ -77,7 +78,7 @@ SkDevice* VectorCanvas::createPlatformDevice(int width,
// SkScalarRound(value * 10). Safari is already doing the same for text
// rendering.
SkASSERT(shared_section);
- PlatformDeviceWin* device = VectorDevice::create(
+ PlatformDevice* device = VectorPlatformDevice::create(
reinterpret_cast<HDC>(shared_section), width, height);
return device;
}
diff --git a/skia/ext/vector_canvas.h b/skia/ext/vector_canvas.h
index 897ffd4..510e8f3 100644
--- a/skia/ext/vector_canvas.h
+++ b/skia/ext/vector_canvas.h
@@ -5,8 +5,8 @@
#ifndef SKIA_EXT_VECTOR_CANVAS_H_
#define SKIA_EXT_VECTOR_CANVAS_H_
-#include "skia/ext/platform_canvas_win.h"
-#include "skia/ext/vector_device.h"
+#include "skia/ext/platform_canvas.h"
+#include "skia/ext/vector_platform_device_win.h"
namespace skia {
@@ -14,7 +14,7 @@ namespace skia {
// to work with a VectorDevice to manage platform-specific drawing. It allows
// using both Skia operations and platform-specific operations. It *doesn't*
// support reading back from the bitmap backstore since it is not used.
-class VectorCanvas : public PlatformCanvasWin {
+class VectorCanvas : public PlatformCanvas {
public:
VectorCanvas();
VectorCanvas(HDC dc, int width, int height);
diff --git a/skia/ext/vector_canvas_unittest.cc b/skia/ext/vector_canvas_unittest.cc
index b1f9a7c..c513050 100644
--- a/skia/ext/vector_canvas_unittest.cc
+++ b/skia/ext/vector_canvas_unittest.cc
@@ -87,7 +87,7 @@ class Image {
}
// Loads the image from a canvas.
- Image(const skia::PlatformCanvasWin& canvas) : ignore_alpha_(true) {
+ Image(const skia::PlatformCanvas& canvas) : ignore_alpha_(true) {
// Use a different way to access the bitmap. The normal way would be to
// query the SkBitmap.
HDC context = canvas.getTopPlatformDevice().getBitmapDC();
@@ -256,7 +256,7 @@ class ImageTest : public testing::Test {
// kGenerating value. Returns 0 on success or any positive value between ]0,
// 100] on failure. The return value is the percentage of difference between
// the image in the file and the image in the canvas.
- double ProcessCanvas(const skia::PlatformCanvasWin& canvas,
+ double ProcessCanvas(const skia::PlatformCanvas& canvas,
std::wstring filename) const {
filename += L".png";
switch (action_) {
@@ -275,7 +275,7 @@ class ImageTest : public testing::Test {
// Compares the bitmap currently loaded in the context with the file. Returns
// the percentage of pixel difference between both images, between 0 and 100.
- double CompareImage(const skia::PlatformCanvasWin& canvas,
+ double CompareImage(const skia::PlatformCanvas& canvas,
const std::wstring& filename) const {
Image image1(canvas);
Image image2(test_file(filename));
@@ -284,7 +284,7 @@ class ImageTest : public testing::Test {
}
// Saves the bitmap currently loaded in the context into the file.
- void SaveImage(const skia::PlatformCanvasWin& canvas,
+ void SaveImage(const skia::PlatformCanvas& canvas,
const std::wstring& filename) const {
Image(canvas).SaveToFile(test_file(filename));
}
@@ -379,7 +379,7 @@ class VectorCanvasTest : public ImageTest {
context_ = new Context();
bitmap_ = new Bitmap(*context_, size_, size_);
vcanvas_ = new VectorCanvas(context_->context(), size_, size_);
- pcanvas_ = new PlatformCanvasWin(size_, size_, false);
+ pcanvas_ = new PlatformCanvas(size_, size_, false);
// Clear white.
vcanvas_->drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode);
@@ -424,7 +424,7 @@ class VectorCanvasTest : public ImageTest {
VectorCanvas* vcanvas_;
// Pixel based canvas.
- PlatformCanvasWin* pcanvas_;
+ PlatformCanvas* pcanvas_;
// When true (default), vcanvas_ and pcanvas_ contents are compared and
// verified to be identical.
@@ -445,7 +445,7 @@ TEST_F(VectorCanvasTest, Uninitialized) {
context_ = new Context();
bitmap_ = new Bitmap(*context_, size_, size_);
vcanvas_ = new VectorCanvas(context_->context(), size_, size_);
- pcanvas_ = new PlatformCanvasWin(size_, size_, false);
+ pcanvas_ = new PlatformCanvas(size_, size_, false);
// VectorCanvas default initialization is black.
// PlatformCanvas default initialization is almost white 0x01FFFEFD (invalid
diff --git a/skia/ext/vector_device.cc b/skia/ext/vector_platform_device_win.cc
index 94da9b0..48375da 100644
--- a/skia/ext/vector_device.cc
+++ b/skia/ext/vector_platform_device_win.cc
@@ -1,8 +1,10 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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/vector_device.h"
+#include <windows.h>
+
+#include "skia/ext/vector_platform_device_win.h"
#include "base/gfx/gdi_util.h"
#include "skia/ext/skia_utils_win.h"
@@ -10,7 +12,8 @@
namespace skia {
-VectorDevice* VectorDevice::create(HDC dc, int width, int height) {
+VectorPlatformDevice* VectorPlatformDevice::create(HDC dc,
+ int width, int height) {
InitializeDC(dc);
// Link the SkBitmap to the current selected bitmap in the device context.
@@ -22,9 +25,9 @@ VectorDevice* VectorDevice::create(HDC dc, int width, int height) {
if (GetObject(selected_bitmap, sizeof(BITMAP), &bitmap_data) ==
sizeof(BITMAP)) {
// The context has a bitmap attached. Attach our SkBitmap to it.
- // Warning: If the bitmap gets unselected from the HDC, VectorDevice has
- // no way to detect this, so the HBITMAP could be released while SkBitmap
- // still has a reference to it. Be cautious.
+ // Warning: If the bitmap gets unselected from the HDC,
+ // VectorPlatformDevice has no way to detect this, so the HBITMAP could be
+ // released while SkBitmap still has a reference to it. Be cautious.
if (width == bitmap_data.bmWidth &&
height == bitmap_data.bmHeight) {
bitmap.setConfig(SkBitmap::kARGB_8888_Config,
@@ -40,24 +43,24 @@ VectorDevice* VectorDevice::create(HDC dc, int width, int height) {
if (!succeeded)
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
- return new VectorDevice(dc, bitmap);
+ return new VectorPlatformDevice(dc, bitmap);
}
-VectorDevice::VectorDevice(HDC dc, const SkBitmap& bitmap)
- : PlatformDeviceWin(bitmap),
+VectorPlatformDevice::VectorPlatformDevice(HDC dc, const SkBitmap& bitmap)
+ : PlatformDevice(bitmap),
hdc_(dc),
previous_brush_(NULL),
previous_pen_(NULL) {
transform_.reset();
}
-VectorDevice::~VectorDevice() {
+VectorPlatformDevice::~VectorPlatformDevice() {
SkASSERT(previous_brush_ == NULL);
SkASSERT(previous_pen_ == NULL);
}
-void VectorDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
+void VectorPlatformDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
// TODO(maruel): Bypass the current transformation matrix.
SkRect rect;
rect.fLeft = 0;
@@ -67,9 +70,11 @@ void VectorDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
drawRect(draw, rect, paint);
}
-void VectorDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
- size_t count, const SkPoint pts[],
- const SkPaint& paint) {
+void VectorPlatformDevice::drawPoints(const SkDraw& draw,
+ SkCanvas::PointMode mode,
+ size_t count,
+ const SkPoint pts[],
+ const SkPaint& paint) {
if (!count)
return;
@@ -108,8 +113,9 @@ void VectorDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
drawPath(draw, path, tmp_paint);
}
-void VectorDevice::drawRect(const SkDraw& draw, const SkRect& rect,
- const SkPaint& paint) {
+void VectorPlatformDevice::drawRect(const SkDraw& draw,
+ const SkRect& rect,
+ const SkPaint& paint) {
if (paint.getPathEffect()) {
// Draw a path instead.
SkPath path_orginal;
@@ -141,8 +147,9 @@ void VectorDevice::drawRect(const SkDraw& draw, const SkRect& rect,
Cleanup();
}
-void VectorDevice::drawPath(const SkDraw& draw, const SkPath& path,
- const SkPaint& paint) {
+void VectorPlatformDevice::drawPath(const SkDraw& draw,
+ const SkPath& path,
+ const SkPaint& paint) {
if (paint.getPathEffect()) {
// Apply the path effect forehand.
SkPath path_modified;
@@ -161,7 +168,7 @@ void VectorDevice::drawPath(const SkDraw& draw, const SkPath& path,
return;
}
HDC dc = getBitmapDC();
- PlatformDeviceWin::LoadPathToDC(dc, path);
+ PlatformDevice::LoadPathToDC(dc, path);
switch (paint.getStyle()) {
case SkPaint::kFill_Style: {
BOOL res = StrokeAndFillPath(dc);
@@ -185,8 +192,10 @@ void VectorDevice::drawPath(const SkDraw& draw, const SkPath& path,
Cleanup();
}
-void VectorDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
- const SkMatrix& matrix, const SkPaint& paint) {
+void VectorPlatformDevice::drawBitmap(const SkDraw& draw,
+ const SkBitmap& bitmap,
+ const SkMatrix& matrix,
+ const SkPaint& paint) {
// Load the temporary matrix. This is what will translate, rotate and resize
// the bitmap.
SkMatrix actual_transform(transform_);
@@ -199,8 +208,10 @@ void VectorDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
LoadTransformToDC(hdc_, transform_);
}
-void VectorDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
- int x, int y, const SkPaint& paint) {
+void VectorPlatformDevice::drawSprite(const SkDraw& draw,
+ const SkBitmap& bitmap,
+ int x, int y,
+ const SkPaint& paint) {
SkMatrix identity;
identity.reset();
LoadTransformToDC(hdc_, identity);
@@ -211,45 +222,62 @@ void VectorDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
LoadTransformToDC(hdc_, transform_);
}
-void VectorDevice::drawText(const SkDraw& draw, const void* text, size_t byteLength,
- SkScalar x, SkScalar y, const SkPaint& paint) {
+void VectorPlatformDevice::drawText(const SkDraw& draw,
+ const void* text,
+ size_t byteLength,
+ SkScalar x,
+ SkScalar y,
+ const SkPaint& paint) {
// This function isn't used in the code. Verify this assumption.
SkASSERT(false);
}
-void VectorDevice::drawPosText(const SkDraw& draw, const void* text, size_t len,
- const SkScalar pos[], SkScalar constY,
- int scalarsPerPos, const SkPaint& paint) {
+void VectorPlatformDevice::drawPosText(const SkDraw& draw,
+ const void* text,
+ size_t len,
+ const SkScalar pos[],
+ SkScalar constY,
+ int scalarsPerPos,
+ const SkPaint& paint) {
// This function isn't used in the code. Verify this assumption.
SkASSERT(false);
}
-void VectorDevice::drawTextOnPath(const SkDraw& draw, const void* text,
- size_t len,
- const SkPath& path, const SkMatrix* matrix,
- const SkPaint& paint) {
+void VectorPlatformDevice::drawTextOnPath(const SkDraw& draw,
+ const void* text,
+ size_t len,
+ const SkPath& path,
+ const SkMatrix* matrix,
+ const SkPaint& paint) {
// This function isn't used in the code. Verify this assumption.
SkASSERT(false);
}
-void VectorDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
- int vertexCount,
- const SkPoint vertices[], const SkPoint texs[],
- const SkColor colors[], SkXfermode* xmode,
- const uint16_t indices[], int indexCount,
- const SkPaint& paint) {
+void VectorPlatformDevice::drawVertices(const SkDraw& draw,
+ SkCanvas::VertexMode vmode,
+ int vertexCount,
+ const SkPoint vertices[],
+ const SkPoint texs[],
+ const SkColor colors[],
+ SkXfermode* xmode,
+ const uint16_t indices[],
+ int indexCount,
+ const SkPaint& paint) {
// This function isn't used in the code. Verify this assumption.
SkASSERT(false);
}
-void VectorDevice::drawDevice(const SkDraw& draw, SkDevice* device, int x,
- int y, const SkPaint& paint) {
+void VectorPlatformDevice::drawDevice(const SkDraw& draw,
+ SkDevice* device,
+ int x,
+ int y,
+ const SkPaint& paint) {
// TODO(maruel): http://b/1183870 Playback the EMF buffer at printer's dpi if
// it is a vectorial device.
drawSprite(draw, device->accessBitmap(false), x, y, paint);
}
-bool VectorDevice::ApplyPaint(const SkPaint& paint) {
+bool VectorPlatformDevice::ApplyPaint(const SkPaint& paint) {
// Note: The goal here is to transfert the SkPaint's state to the HDC's state.
// This function does not execute the SkPaint drawing commands. These should
// be executed in drawPaint().
@@ -328,7 +356,7 @@ bool VectorDevice::ApplyPaint(const SkPaint& paint) {
return true;
}
-void VectorDevice::setMatrixClip(const SkMatrix& transform,
+void VectorPlatformDevice::setMatrixClip(const SkMatrix& transform,
const SkRegion& region) {
transform_ = transform;
LoadTransformToDC(hdc_, transform_);
@@ -337,17 +365,18 @@ void VectorDevice::setMatrixClip(const SkMatrix& transform,
LoadClipRegion();
}
-void VectorDevice::drawToHDC(HDC dc, int x, int y, const RECT* src_rect) {
+void VectorPlatformDevice::drawToHDC(HDC dc, int x, int y,
+ const RECT* src_rect) {
SkASSERT(false);
}
-void VectorDevice::LoadClipRegion() {
+void VectorPlatformDevice::LoadClipRegion() {
SkMatrix t;
t.reset();
LoadClippingRegionToDC(hdc_, clip_region_, t);
}
-bool VectorDevice::CreateBrush(bool use_brush, COLORREF color) {
+bool VectorPlatformDevice::CreateBrush(bool use_brush, COLORREF color) {
SkASSERT(previous_brush_ == NULL);
// We can't use SetDCBrushColor() or DC_BRUSH when drawing to a EMF buffer.
// SetDCBrushColor() calls are not recorded at all and DC_BRUSH will use
@@ -376,8 +405,11 @@ bool VectorDevice::CreateBrush(bool use_brush, COLORREF color) {
return previous_brush_ != NULL;
}
-bool VectorDevice::CreatePen(bool use_pen, COLORREF color, int stroke_width,
- float stroke_miter, DWORD pen_style) {
+bool VectorPlatformDevice::CreatePen(bool use_pen,
+ COLORREF color,
+ int stroke_width,
+ float stroke_miter,
+ DWORD pen_style) {
SkASSERT(previous_pen_ == NULL);
// We can't use SetDCPenColor() or DC_PEN when drawing to a EMF buffer.
// SetDCPenColor() calls are not recorded at all and DC_PEN will use BLACK_PEN
@@ -414,7 +446,7 @@ bool VectorDevice::CreatePen(bool use_pen, COLORREF color, int stroke_width,
return true;
}
-void VectorDevice::Cleanup() {
+void VectorPlatformDevice::Cleanup() {
if (previous_brush_) {
HGDIOBJ result = SelectObject(previous_brush_);
previous_brush_ = NULL;
@@ -435,7 +467,7 @@ void VectorDevice::Cleanup() {
AbortPath(hdc_);
}
-HGDIOBJ VectorDevice::SelectObject(HGDIOBJ object) {
+HGDIOBJ VectorPlatformDevice::SelectObject(HGDIOBJ object) {
HGDIOBJ result = ::SelectObject(hdc_, object);
SkASSERT(result != HGDI_ERROR);
if (result == HGDI_ERROR)
@@ -443,7 +475,7 @@ HGDIOBJ VectorDevice::SelectObject(HGDIOBJ object) {
return result;
}
-bool VectorDevice::CreateBrush(bool use_brush, const SkPaint& paint) {
+bool VectorPlatformDevice::CreateBrush(bool use_brush, const SkPaint& paint) {
// Make sure that for transparent color, no brush is used.
if (paint.getAlpha() == 0) {
// Test if it ever happen.
@@ -454,7 +486,7 @@ bool VectorDevice::CreateBrush(bool use_brush, const SkPaint& paint) {
return CreateBrush(use_brush, SkColorToCOLORREF(paint.getColor()));
}
-bool VectorDevice::CreatePen(bool use_pen, const SkPaint& paint) {
+bool VectorPlatformDevice::CreatePen(bool use_pen, const SkPaint& paint) {
// Make sure that for transparent color, no pen is used.
if (paint.getAlpha() == 0) {
// Test if it ever happen.
@@ -505,8 +537,9 @@ bool VectorDevice::CreatePen(bool use_pen, const SkPaint& paint) {
pen_style);
}
-void VectorDevice::InternalDrawBitmap(const SkBitmap& bitmap, int x, int y,
- const SkPaint& paint) {
+void VectorPlatformDevice::InternalDrawBitmap(const SkBitmap& bitmap,
+ int x, int y,
+ const SkPaint& paint) {
unsigned char alpha = paint.getAlpha();
if (alpha == 0)
return;
diff --git a/skia/ext/vector_device.h b/skia/ext/vector_platform_device_win.h
index cc534f7..9dfefd6 100644
--- a/skia/ext/vector_device.h
+++ b/skia/ext/vector_platform_device_win.h
@@ -1,11 +1,11 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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_VECTOR_DEVICE_H_
-#define SKIA_EXT_VECTOR_DEVICE_H_
+#ifndef SKIA_EXT_VECTOR_PLATFORM_DEVICE_WIN_H_
+#define SKIA_EXT_VECTOR_PLATFORM_DEVICE_WIN_H_
-#include "skia/ext/platform_device_win.h"
+#include "skia/ext/platform_device.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkRegion.h"
@@ -15,13 +15,13 @@ namespace skia {
// SkCanvas to draw into. This specific device is not not backed by a surface
// and is thus unreadable. This is because the backend is completely vectorial.
// This device is a simple wrapper over a Windows device context (HDC) handle.
-class VectorDevice : public PlatformDeviceWin {
+class VectorPlatformDevice : public PlatformDevice {
public:
// Factory function. The DC is kept as the output context.
- static VectorDevice* create(HDC dc, int width, int height);
+ static VectorPlatformDevice* create(HDC dc, int width, int height);
- VectorDevice(HDC dc, const SkBitmap& bitmap);
- virtual ~VectorDevice();
+ VectorPlatformDevice(HDC dc, const SkBitmap& bitmap);
+ virtual ~VectorPlatformDevice();
virtual HDC getBitmapDC() {
return hdc_;
@@ -110,11 +110,11 @@ class VectorDevice : public PlatformDeviceWin {
HGDIOBJ previous_pen_;
// Copy & assign are not supported.
- VectorDevice(const VectorDevice&);
- const VectorDevice& operator=(const VectorDevice&);
+ VectorPlatformDevice(const VectorPlatformDevice&);
+ const VectorPlatformDevice& operator=(const VectorPlatformDevice&);
};
} // namespace skia
-#endif // SKIA_EXT_VECTOR_DEVICE_H_
+#endif // SKIA_EXT_VECTOR_PLATFORM_DEVICE_WIN_H_
diff --git a/skia/skia.gyp b/skia/skia.gyp
index b9b0714..4158b2b 100644..100755
--- a/skia/skia.gyp
+++ b/skia/skia.gyp
@@ -511,12 +511,10 @@
'ext/image_operations.cc',
'ext/image_operations.h',
'ext/platform_canvas.h',
+ 'ext/platform_canvas.cc',
'ext/platform_canvas_linux.cc',
- 'ext/platform_canvas_linux.h',
'ext/platform_canvas_mac.cc',
- 'ext/platform_canvas_mac.h',
'ext/platform_canvas_win.cc',
- 'ext/platform_canvas_win.h',
'ext/platform_device.h',
'ext/platform_device_linux.cc',
'ext/platform_device_linux.h',
@@ -534,8 +532,8 @@
'ext/skia_utils_win.h',
'ext/vector_canvas.cc',
'ext/vector_canvas.h',
- 'ext/vector_device.cc',
- 'ext/vector_device.h',
+ 'ext/vector_platform_device_win.cc',
+ 'ext/vector_platform_device_win.h',
],
'include_dirs': [
'..',