summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-22 00:10:00 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-22 00:10:00 +0000
commit8c2fcd19acaa0b3aeeae0aacd0f698d9d0e4b0a4 (patch)
tree9ae4cf3df2df8b9816abbeeefcde36b6dd33a040
parentfbbb58d4c5cc57c72b84ee4337b155e2a64224e1 (diff)
downloadchromium_src-8c2fcd19acaa0b3aeeae0aacd0f698d9d0e4b0a4.zip
chromium_src-8c2fcd19acaa0b3aeeae0aacd0f698d9d0e4b0a4.tar.gz
chromium_src-8c2fcd19acaa0b3aeeae0aacd0f698d9d0e4b0a4.tar.bz2
Move port/.../skia/public to skia/ext for Linux. Windows & Mac already moved there. This leaves forwarding headers in base/gfx, which I'll clean up in a future pass.
Review URL: http://codereview.chromium.org/11808 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5873 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/gfx/bitmap_platform_device.h2
-rw-r--r--base/gfx/bitmap_platform_device_linux.h2
-rw-r--r--base/gfx/platform_canvas.h2
-rw-r--r--base/gfx/platform_canvas_linux.h4
-rw-r--r--base/gfx/platform_device.h2
-rw-r--r--base/gfx/platform_device_linux.h2
-rw-r--r--skia/SConscript4
-rw-r--r--skia/ext/bitmap_platform_device.h (renamed from webkit/port/platform/graphics/skia/public/BitmapPlatformDevice.h)2
-rw-r--r--skia/ext/bitmap_platform_device_linux.cc (renamed from webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.cpp)2
-rw-r--r--skia/ext/bitmap_platform_device_linux.h (renamed from webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.h)8
-rw-r--r--skia/ext/platform_canvas.h (renamed from webkit/port/platform/graphics/skia/public/PlatformCanvas.h)2
-rw-r--r--skia/ext/platform_canvas_linux.cc (renamed from webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.cpp)2
-rw-r--r--skia/ext/platform_canvas_linux.h (renamed from webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.h)6
-rw-r--r--skia/ext/platform_device_linux.cc (renamed from webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.cpp)2
-rw-r--r--skia/ext/platform_device_linux.h (renamed from webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.h)6
-rw-r--r--webkit/SConscript.port4
-rw-r--r--webkit/port/platform/graphics/skia/public/PlatformCanvas_unittest.cpp296
-rw-r--r--webkit/port/platform/graphics/skia/public/PlatformDevice.h27
-rw-r--r--webkit/port/platform/graphics/skia/public/README3
-rw-r--r--webkit/port/platform/graphics/skia/public/VectorDevice.cpp612
-rw-r--r--webkit/port/platform/graphics/skia/public/VectorDevice.h119
21 files changed, 26 insertions, 1083 deletions
diff --git a/base/gfx/bitmap_platform_device.h b/base/gfx/bitmap_platform_device.h
index 7c25eb2..19a35ba 100644
--- a/base/gfx/bitmap_platform_device.h
+++ b/base/gfx/bitmap_platform_device.h
@@ -4,4 +4,4 @@
// TODO(brettw) this file should be removed and the includes changed to this
// new location.
-#include "webkit/port/platform/graphics/skia/public/BitmapPlatformDevice.h"
+#include "skia/ext/bitmap_platform_device.h"
diff --git a/base/gfx/bitmap_platform_device_linux.h b/base/gfx/bitmap_platform_device_linux.h
index 3db11cb..25b2894 100644
--- a/base/gfx/bitmap_platform_device_linux.h
+++ b/base/gfx/bitmap_platform_device_linux.h
@@ -7,6 +7,6 @@
// TODO(brettw) this file should be removed and the includes changed to this
// new location.
-#include "webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.h"
+#include "skia/ext/bitmap_platform_device_linux.h"
#endif // BASE_GFX_BITMAP_PLATFORM_DEVICE_LINUX_H_
diff --git a/base/gfx/platform_canvas.h b/base/gfx/platform_canvas.h
index 5bf0ec1..427a7f8 100644
--- a/base/gfx/platform_canvas.h
+++ b/base/gfx/platform_canvas.h
@@ -4,4 +4,4 @@
// TODO(brettw) this file should be removed and the includes changed to this
// new location.
-#include "webkit/port/platform/graphics/skia/public/PlatformCanvas.h"
+#include "skia/ext/platform_canvas.h"
diff --git a/base/gfx/platform_canvas_linux.h b/base/gfx/platform_canvas_linux.h
index dbd9fc2..4a493a4 100644
--- a/base/gfx/platform_canvas_linux.h
+++ b/base/gfx/platform_canvas_linux.h
@@ -7,6 +7,6 @@
// TODO(brettw) this file should be removed and the includes changed to this
// new location.
-#include "webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.h"
+#include "skia/ext/platform_canvas_linux.h"
-#endif // BASE_GFX_PLATFORM_CANVAS_MAC_H_
+#endif // BASE_GFX_PLATFORM_CANVAS_LINUX_H_
diff --git a/base/gfx/platform_device.h b/base/gfx/platform_device.h
index 11202c6..2c2acd2 100644
--- a/base/gfx/platform_device.h
+++ b/base/gfx/platform_device.h
@@ -4,4 +4,4 @@
// TODO(brettw) this file should be removed and the includes changed to this
// new location.
-#include "webkit/port/platform/graphics/skia/public/PlatformDevice.h"
+#include "skia/ext/platform_device.h"
diff --git a/base/gfx/platform_device_linux.h b/base/gfx/platform_device_linux.h
index ffd5a2d..3cb9572 100644
--- a/base/gfx/platform_device_linux.h
+++ b/base/gfx/platform_device_linux.h
@@ -7,6 +7,6 @@
// TODO(brettw) this file should be removed and the includes changed to this
// new location.
-#include "webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.h"
+#include "skia/ext/platform_device_linux.h"
#endif // BASE_GFX_PLATFORM_DEVICE_LINUX_H_
diff --git a/skia/SConscript b/skia/SConscript
index 97ea1be..0178f38 100644
--- a/skia/SConscript
+++ b/skia/SConscript
@@ -155,6 +155,10 @@ input_files = [
]
if env['PLATFORM'] == 'posix':
+ input_files.append('ext/bitmap_platform_device_linux.cc')
+ input_files.append('ext/platform_canvas_linux.cc')
+ input_files.append('ext/platform_device_linux.cc')
+
# On Linux we use Skia to render fonts with FreeType and fontconfig
input_files.remove('sgl/SkTypeface_fake.cpp')
input_files.remove('ports/SkFontHost_none.cpp')
diff --git a/webkit/port/platform/graphics/skia/public/BitmapPlatformDevice.h b/skia/ext/bitmap_platform_device.h
index 1b0df28..d33ae73 100644
--- a/webkit/port/platform/graphics/skia/public/BitmapPlatformDevice.h
+++ b/skia/ext/bitmap_platform_device.h
@@ -21,7 +21,7 @@ typedef BitmapPlatformDeviceMac BitmapPlatformDevice;
} // namespace gfx
#elif defined(__linux__)
-#include "BitmapPlatformDeviceLinux.h"
+#include "skia/ext/bitmap_platform_device_linux.h"
namespace gfx {
typedef BitmapPlatformDeviceLinux BitmapPlatformDevice;
diff --git a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.cpp b/skia/ext/bitmap_platform_device_linux.cc
index 18f8ab1..4dd322d 100644
--- a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.cpp
+++ b/skia/ext/bitmap_platform_device_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 "base/gfx/bitmap_platform_device_linux.h"
+#include "skia/ext/bitmap_platform_device_linux.h"
#include <cairo/cairo.h>
diff --git a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.h b/skia/ext/bitmap_platform_device_linux.h
index 4985c5b..14e4c0c 100644
--- a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.h
+++ b/skia/ext/bitmap_platform_device_linux.h
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BitmapPlatformDeviceLinux_h
-#define BitmapPlatformDeviceLinux_h
+#ifndef SKIA_EXT_BITMAP_PLATFORM_DEVICE_LINUX_H_
+#define SKIA_EXT_BITMAP_PLATFORM_DEVICE_LINUX_H_
-#include "PlatformDeviceLinux.h"
#include "base/ref_counted.h"
+#include "skia/ext/platform_device_linux.h"
typedef struct _cairo_surface cairo_surface_t;
@@ -88,4 +88,4 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
} // namespace gfx
-#endif // BitmapPlatformDeviceLinux_h
+#endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_LINUX_H_
diff --git a/webkit/port/platform/graphics/skia/public/PlatformCanvas.h b/skia/ext/platform_canvas.h
index a2af39e..b1e4310 100644
--- a/webkit/port/platform/graphics/skia/public/PlatformCanvas.h
+++ b/skia/ext/platform_canvas.h
@@ -21,7 +21,7 @@ typedef PlatformCanvasMac PlatformCanvas;
} // namespace gfx
#elif defined(__linux__)
-#include "PlatformCanvasLinux.h"
+#include "skia/ext/platform_canvas_linux.h"
namespace gfx {
typedef PlatformCanvasLinux PlatformCanvas;
diff --git a/webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.cpp b/skia/ext/platform_canvas_linux.cc
index b579536..126c7ff 100644
--- a/webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.cpp
+++ 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 "base/gfx/platform_canvas_linux.h"
+#include "skia/ext/platform_canvas_linux.h"
#include "base/gfx/platform_device_linux.h"
#include "base/gfx/bitmap_platform_device_linux.h"
diff --git a/webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.h b/skia/ext/platform_canvas_linux.h
index 6eefee8..e2153a7 100644
--- a/webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.h
+++ b/skia/ext/platform_canvas_linux.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef PlatformCanvasLinux_h
-#define PlatformCanvasLinux_h
+#ifndef SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
+#define SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
#include "PlatformDeviceLinux.h"
@@ -49,4 +49,4 @@ class PlatformCanvasLinux : public SkCanvas {
} // namespace gfx
-#endif // PlatformCanvasLinux_h
+#endif // SKIA_EXT_PLATFORM_CANVAS_LINUX_H_
diff --git a/webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.cpp b/skia/ext/platform_device_linux.cc
index 50ffd51..f148ed1 100644
--- a/webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.cpp
+++ b/skia/ext/platform_device_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 "PlatformDeviceLinux.h"
+#include "skia/ext/platform_device_linux.h"
namespace gfx {
diff --git a/webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.h b/skia/ext/platform_device_linux.h
index 7c853a4..185baf0 100644
--- a/webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.h
+++ b/skia/ext/platform_device_linux.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef PlatformDeviceLinux_h
-#define PlatformDeviceLinux_h
+#ifndef SKIA_EXT_PLATFORM_DEVICE_LINUX_H_
+#define SKIA_EXT_PLATFORM_DEVICE_LINUX_H_
#include "SkDevice.h"
@@ -22,4 +22,4 @@ class PlatformDeviceLinux : public SkDevice {
} // namespace gfx
-#endif // PlatformDeviceLinux_h
+#endif // SKIA_EXT_PLATFORM_DEVICE_LINUX_H_
diff --git a/webkit/SConscript.port b/webkit/SConscript.port
index f518675..f7421ca 100644
--- a/webkit/SConscript.port
+++ b/webkit/SConscript.port
@@ -129,10 +129,6 @@ if env['PLATFORM'] == 'posix':
'$PORT_DIR/platform/chromium/ScrollbarThemeChromiumLinux.cpp',
'$PORT_DIR/platform/graphics/chromium/GlyphPageTreeNodeLinux.cpp',
'$PORT_DIR/platform/graphics/skia/GdkSkia.cc',
-
- '$PORT_DIR/platform/graphics/skia/public/PlatformCanvasLinux.cpp',
- '$PORT_DIR/platform/graphics/skia/public/PlatformDeviceLinux.cpp',
- '$PORT_DIR/platform/graphics/skia/public/BitmapPlatformDeviceLinux.cpp',
])
if env['PLATFORM'] == 'darwin':
diff --git a/webkit/port/platform/graphics/skia/public/PlatformCanvas_unittest.cpp b/webkit/port/platform/graphics/skia/public/PlatformCanvas_unittest.cpp
deleted file mode 100644
index 8e227ad..0000000
--- a/webkit/port/platform/graphics/skia/public/PlatformCanvas_unittest.cpp
+++ /dev/null
@@ -1,296 +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.
-
-// TODO(awalker): clean up the const/non-const reference handling in this test
-
-#include "build/build_config.h"
-
-#if defined(OS_WIN)
-#include <windows.h>
-#else
-#include <unistd.h>
-#endif
-
-#include "base/gfx/platform_canvas.h"
-#include "base/gfx/platform_device.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-#include "SkColor.h"
-
-namespace gfx {
-
-namespace {
-
-// Return true if the canvas is filled to canvas_color,
-// and contains a single rectangle filled to rect_color.
-bool VerifyRect(const PlatformCanvas& canvas,
- uint32_t canvas_color, uint32_t rect_color,
- int x, int y, int w, int h) {
- PlatformDevice& device = canvas.getTopPlatformDevice();
- const SkBitmap& bitmap = device.accessBitmap(false);
- SkAutoLockPixels lock(bitmap);
-
- for (int cur_y = 0; cur_y < bitmap.height(); cur_y++) {
- for (int cur_x = 0; cur_x < bitmap.width(); cur_x++) {
- if (cur_x >= x && cur_x < x + w &&
- cur_y >= y && cur_y < y + h) {
- // Inside the square should be rect_color
- if (*bitmap.getAddr32(cur_x, cur_y) != rect_color)
- return false;
- } else {
- // Outside the square should be canvas_color
- if (*bitmap.getAddr32(cur_x, cur_y) != canvas_color)
- return false;
- }
- }
- }
- return true;
-}
-
-// Checks whether there is a white canvas with a black square at the given
-// location in pixels (not in the canvas coordinate system).
-// TODO(ericroman): rename Square to Rect
-bool VerifyBlackSquare(const PlatformCanvas& canvas, int x, int y, int w, int h) {
- return VerifyRect(canvas, SK_ColorWHITE, SK_ColorBLACK, x, y, w, h);
-}
-
-// Check that every pixel in the canvas is a single color.
-bool VerifyCanvasColor(const PlatformCanvas& canvas, uint32_t canvas_color) {
- return VerifyRect(canvas, canvas_color, 0, 0, 0, 0, 0);
-}
-
-#if defined(OS_WIN)
-void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) {
- HDC dc = canvas.beginPlatformPaint();
-
- RECT inner_rc;
- inner_rc.left = x;
- inner_rc.top = y;
- inner_rc.right = x + w;
- inner_rc.bottom = y + h;
- FillRect(dc, &inner_rc, reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH)));
-
- canvas.endPlatformPaint();
-}
-#elif defined(OS_MACOSX)
-void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) {
- CGContextRef context = canvas.beginPlatformPaint();
-
- CGRect inner_rc = CGRectMake(x, y, w, h);
- // RGBA opaque black
- CGColorRef black = CGColorCreateGenericRGB(0.0, 0.0, 0.0, 1.0);
- CGContextSetFillColorWithColor(context, black);
- CGColorRelease(black);
- CGContextFillRect(context, inner_rc);
-
- canvas.endPlatformPaint();
-}
-#else
-void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) {
- NOTIMPLEMENTED();
-}
-#endif
-
-// Clips the contents of the canvas to the given rectangle. This will be
-// intersected with any existing clip.
-void AddClip(PlatformCanvas& canvas, int x, int y, int w, int h) {
- SkRect rect;
- rect.set(SkIntToScalar(x), SkIntToScalar(y),
- SkIntToScalar(x + w), SkIntToScalar(y + h));
- canvas.clipRect(rect);
-}
-
-class LayerSaver {
- public:
- LayerSaver(PlatformCanvas& canvas, int x, int y, int w, int h)
- : canvas_(canvas),
- x_(x),
- y_(y),
- w_(w),
- h_(h) {
- SkRect bounds;
- bounds.set(SkIntToScalar(x_), SkIntToScalar(y_),
- SkIntToScalar(right()), SkIntToScalar(bottom()));
- canvas_.saveLayer(&bounds, NULL);
- }
-
- ~LayerSaver() {
- canvas_.getTopPlatformDevice().fixupAlphaBeforeCompositing();
- canvas_.restore();
- }
-
- int x() const { return x_; }
- int y() const { return y_; }
- int w() const { return w_; }
- int h() const { return h_; }
-
- // Returns the EXCLUSIVE far bounds of the layer.
- int right() const { return x_ + w_; }
- int bottom() const { return y_ + h_; }
-
- private:
- PlatformCanvas& canvas_;
- int x_, y_, w_, h_;
-};
-
-// Size used for making layers in many of the below tests.
-const int kLayerX = 2;
-const int kLayerY = 3;
-const int kLayerW = 9;
-const int kLayerH = 7;
-
-// Size used by some tests to draw a rectangle inside the layer.
-const int kInnerX = 4;
-const int kInnerY = 5;
-const int kInnerW = 2;
-const int kInnerH = 3;
-
-}
-
-// This just checks that our checking code is working properly, it just uses
-// regular skia primitives.
-TEST(PlatformCanvas, SkLayer) {
- // Create the canvas initialized to opaque white.
- PlatformCanvas canvas(16, 16, true);
- canvas.drawColor(SK_ColorWHITE);
-
- // Make a layer and fill it completely to make sure that the bounds are
- // correct.
- {
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- canvas.drawColor(SK_ColorBLACK);
- }
- EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX, kLayerY, kLayerW, kLayerH));
-}
-
-// Test native clipping.
-TEST(PlatformCanvas, ClipRegion) {
- // Initialize a white canvas
- PlatformCanvas canvas(16, 16, true);
- canvas.drawColor(SK_ColorWHITE);
- EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorWHITE));
-
- // Test that initially the canvas has no clip region, by filling it
- // with a black rectangle.
- // Note: Don't use LayerSaver, since internally it sets a clip region.
- DrawNativeRect(canvas, 0, 0, 16, 16);
- canvas.getTopPlatformDevice().fixupAlphaBeforeCompositing();
- EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorBLACK));
-
- // Test that intersecting disjoint clip rectangles sets an empty clip region
- canvas.drawColor(SK_ColorWHITE);
- EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorWHITE));
- {
- LayerSaver layer(canvas, 0, 0, 16, 16);
- AddClip(canvas, 2, 3, 4, 5);
- AddClip(canvas, 4, 9, 10, 10);
- DrawNativeRect(canvas, 0, 0, 16, 16);
- }
- EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorWHITE));
-}
-
-// Test the layers get filled properly by native rendering.
-TEST(PlatformCanvas, FillLayer) {
- // Create the canvas initialized to opaque white.
- PlatformCanvas canvas(16, 16, true);
-
- // Make a layer and fill it completely to make sure that the bounds are
- // correct.
- canvas.drawColor(SK_ColorWHITE);
- {
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- DrawNativeRect(canvas, 0, 0, 100, 100);
- }
- EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX, kLayerY, kLayerW, kLayerH));
-
- // Make a layer and fill it partially to make sure the translation is correct.
- canvas.drawColor(SK_ColorWHITE);
- {
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
- }
- EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH));
-
- // Add a clip on the layer and fill to make sure clip is correct.
- canvas.drawColor(SK_ColorWHITE);
- {
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- canvas.save();
- AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
- DrawNativeRect(canvas, 0, 0, 100, 100);
- canvas.restore();
- }
- EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH));
-
- // Add a clip and then make the layer to make sure the clip is correct.
- canvas.drawColor(SK_ColorWHITE);
- canvas.save();
- AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
- {
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- DrawNativeRect(canvas, 0, 0, 100, 100);
- }
- canvas.restore();
- EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH));
-}
-
-// Test that translation + make layer works properly.
-TEST(PlatformCanvas, TranslateLayer) {
- // Create the canvas initialized to opaque white.
- PlatformCanvas canvas(16, 16, true);
-
- // Make a layer and fill it completely to make sure that the bounds are
- // correct.
- canvas.drawColor(SK_ColorWHITE);
- canvas.save();
- canvas.translate(1, 1);
- {
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- DrawNativeRect(canvas, 0, 0, 100, 100);
- }
- canvas.restore();
- EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX + 1, kLayerY + 1,
- kLayerW, kLayerH));
-
- // Translate then make the layer.
- canvas.drawColor(SK_ColorWHITE);
- canvas.save();
- canvas.translate(1, 1);
- {
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
- }
- canvas.restore();
- EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 1, kInnerY + 1,
- kInnerW, kInnerH));
-
- // Make the layer then translate.
- canvas.drawColor(SK_ColorWHITE);
- canvas.save();
- {
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- canvas.translate(1, 1);
- DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
- }
- canvas.restore();
- EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 1, kInnerY + 1,
- kInnerW, kInnerH));
-
- // Translate both before and after, and have a clip.
- canvas.drawColor(SK_ColorWHITE);
- canvas.save();
- canvas.translate(1, 1);
- {
- LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH);
- canvas.translate(1, 1);
- AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH);
- DrawNativeRect(canvas, 0, 0, 100, 100);
- }
- canvas.restore();
- EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 2, kInnerY + 2,
- kInnerW, kInnerH));
-}
-
-} // namespace
-
diff --git a/webkit/port/platform/graphics/skia/public/PlatformDevice.h b/webkit/port/platform/graphics/skia/public/PlatformDevice.h
deleted file mode 100644
index 1cd8847..0000000
--- a/webkit/port/platform/graphics/skia/public/PlatformDevice.h
+++ /dev/null
@@ -1,27 +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.
-
-// 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.
-
-#if defined(WIN32)
-#include "skia/ext/platform_device_win.h"
-#elif defined(__APPLE__)
-#include "skia/ext/platform_device_mac.h"
-#elif defined(__linux__)
-#include "PlatformDeviceLinux.h"
-#endif
-
-namespace gfx {
-
-#if defined(WIN32)
-typedef PlatformDeviceWin PlatformDevice;
-#elif defined(__APPLE__)
-typedef PlatformDeviceMac PlatformDevice;
-#elif defined(__linux__)
-typedef PlatformDeviceLinux PlatformDevice;
-#endif
-
-} // namespace gfx
diff --git a/webkit/port/platform/graphics/skia/public/README b/webkit/port/platform/graphics/skia/public/README
deleted file mode 100644
index a0dfcdf..0000000
--- a/webkit/port/platform/graphics/skia/public/README
+++ /dev/null
@@ -1,3 +0,0 @@
-The files in this directory must not depend on WebKit types since they are used
-by both the port and the Chromium application layer. They may only depend on
-Skia and the system libraries.
diff --git a/webkit/port/platform/graphics/skia/public/VectorDevice.cpp b/webkit/port/platform/graphics/skia/public/VectorDevice.cpp
deleted file mode 100644
index 2f5e3aa..0000000
--- a/webkit/port/platform/graphics/skia/public/VectorDevice.cpp
+++ /dev/null
@@ -1,612 +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.
-
-#include "VectorDevice.h"
-
-#include "base/gfx/gdi_util.h"
-#include "base/gfx/skia_utils.h"
-#include "base/logging.h"
-#include "base/scoped_handle.h"
-
-#include "SkUtils.h"
-
-namespace gfx {
-
-VectorDevice* VectorDevice::create(HDC dc, int width, int height) {
- InitializeDC(dc);
-
- // Link the SkBitmap to the current selected bitmap in the device context.
- SkBitmap bitmap;
- HGDIOBJ selected_bitmap = GetCurrentObject(dc, OBJ_BITMAP);
- bool succeeded = false;
- if (selected_bitmap != NULL) {
- BITMAP bitmap_data;
- 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.
- if (width == bitmap_data.bmWidth &&
- height == bitmap_data.bmHeight) {
- bitmap.setConfig(SkBitmap::kARGB_8888_Config,
- bitmap_data.bmWidth,
- bitmap_data.bmHeight,
- bitmap_data.bmWidthBytes);
- bitmap.setPixels(bitmap_data.bmBits);
- succeeded = true;
- }
- }
- }
-
- if (!succeeded)
- bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
-
- return new VectorDevice(dc, bitmap);
-}
-
-VectorDevice::VectorDevice(HDC dc, const SkBitmap& bitmap)
- : PlatformDeviceWin(bitmap),
- hdc_(dc),
- previous_brush_(NULL),
- previous_pen_(NULL) {
- transform_.reset();
-}
-
-VectorDevice::~VectorDevice() {
- DCHECK(previous_brush_ == NULL);
- DCHECK(previous_pen_ == NULL);
-}
-
-
-void VectorDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
- // TODO(maruel): Bypass the current transformation matrix.
- SkRect rect;
- rect.fLeft = 0;
- rect.fTop = 0;
- rect.fRight = SkIntToScalar(width() + 1);
- rect.fBottom = SkIntToScalar(height() + 1);
- drawRect(draw, rect, paint);
-}
-
-void VectorDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
- size_t count, const SkPoint pts[],
- const SkPaint& paint) {
- if (!count)
- return;
-
- if (mode == SkCanvas::kPoints_PointMode) {
- NOTREACHED();
- return;
- }
-
- SkPaint tmp_paint(paint);
- tmp_paint.setStyle(SkPaint::kStroke_Style);
-
- // Draw a path instead.
- SkPath path;
- switch (mode) {
- case SkCanvas::kLines_PointMode:
- if (count % 2) {
- NOTREACHED();
- return;
- }
- for (size_t i = 0; i < count / 2; ++i) {
- path.moveTo(pts[2 * i]);
- path.lineTo(pts[2 * i + 1]);
- }
- break;
- case SkCanvas::kPolygon_PointMode:
- path.moveTo(pts[0]);
- for (size_t i = 1; i < count; ++i) {
- path.lineTo(pts[i]);
- }
- break;
- default:
- NOTREACHED();
- return;
- }
- // Draw the calculated path.
- drawPath(draw, path, tmp_paint);
-}
-
-void VectorDevice::drawRect(const SkDraw& draw, const SkRect& rect,
- const SkPaint& paint) {
- if (paint.getPathEffect()) {
- // Draw a path instead.
- SkPath path_orginal;
- path_orginal.addRect(rect);
-
- // Apply the path effect to the rect.
- SkPath path_modified;
- paint.getFillPath(path_orginal, &path_modified);
-
- // Removes the path effect from the temporary SkPaint object.
- SkPaint paint_no_effet(paint);
- paint_no_effet.setPathEffect(NULL)->safeUnref();
-
- // Draw the calculated path.
- drawPath(draw, path_modified, paint_no_effet);
- return;
- }
-
- if (!ApplyPaint(paint)) {
- return;
- }
- HDC dc = getBitmapDC();
- if (!Rectangle(dc, SkScalarRound(rect.fLeft),
- SkScalarRound(rect.fTop),
- SkScalarRound(rect.fRight),
- SkScalarRound(rect.fBottom))) {
- NOTREACHED();
- }
- Cleanup();
-}
-
-void VectorDevice::drawPath(const SkDraw& draw, const SkPath& path,
- const SkPaint& paint) {
- if (paint.getPathEffect()) {
- // Apply the path effect forehand.
- SkPath path_modified;
- paint.getFillPath(path, &path_modified);
-
- // Removes the path effect from the temporary SkPaint object.
- SkPaint paint_no_effet(paint);
- paint_no_effet.setPathEffect(NULL)->safeUnref();
-
- // Draw the calculated path.
- drawPath(draw, path_modified, paint_no_effet);
- return;
- }
-
- if (!ApplyPaint(paint)) {
- return;
- }
- HDC dc = getBitmapDC();
- PlatformDeviceWin::LoadPathToDC(dc, path);
- switch (paint.getStyle()) {
- case SkPaint::kFill_Style: {
- BOOL res = StrokeAndFillPath(dc);
- DCHECK(res != 0);
- break;
- }
- case SkPaint::kStroke_Style: {
- BOOL res = StrokePath(dc);
- DCHECK(res != 0);
- break;
- }
- case SkPaint::kStrokeAndFill_Style: {
- BOOL res = StrokeAndFillPath(dc);
- DCHECK(res != 0);
- break;
- }
- default:
- NOTREACHED();
- break;
- }
- Cleanup();
-}
-
-void VectorDevice::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_);
- actual_transform.preConcat(matrix);
- LoadTransformToDC(hdc_, actual_transform);
-
- InternalDrawBitmap(bitmap, 0, 0, paint);
-
- // Restore the original matrix.
- LoadTransformToDC(hdc_, transform_);
-}
-
-void VectorDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
- int x, int y, const SkPaint& paint) {
- SkMatrix identity;
- identity.reset();
- LoadTransformToDC(hdc_, identity);
-
- InternalDrawBitmap(bitmap, x, y, paint);
-
- // Restore the original matrix.
- LoadTransformToDC(hdc_, transform_);
-}
-
-void VectorDevice::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.
- NOTREACHED();
-}
-
-void VectorDevice::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.
- NOTREACHED();
-}
-
-void VectorDevice::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.
- NOTREACHED();
-}
-
-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) {
- // This function isn't used in the code. Verify this assumption.
- NOTREACHED();
-}
-
-void VectorDevice::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) {
- // 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().
-
- SkPaint::Style style = paint.getStyle();
- if (!paint.getAlpha())
- style = SkPaint::kStyleCount;
-
- switch (style) {
- case SkPaint::kFill_Style:
- if (!CreateBrush(true, paint) ||
- !CreatePen(false, paint))
- return false;
- break;
- case SkPaint::kStroke_Style:
- if (!CreateBrush(false, paint) ||
- !CreatePen(true, paint))
- return false;
- break;
- case SkPaint::kStrokeAndFill_Style:
- if (!CreateBrush(true, paint) ||
- !CreatePen(true, paint))
- return false;
- break;
- default:
- if (!CreateBrush(false, paint) ||
- !CreatePen(false, paint))
- return false;
- break;
- }
-
- /*
- getFlags();
- isAntiAlias();
- isDither()
- isLinearText()
- isSubpixelText()
- isUnderlineText()
- isStrikeThruText()
- isFakeBoldText()
- isDevKernText()
- isFilterBitmap()
-
- // Skia's text is not used. This should be fixed.
- getTextAlign()
- getTextScaleX()
- getTextSkewX()
- getTextEncoding()
- getFontMetrics()
- getFontSpacing()
- */
-
- // BUG 1094907: Implement shaders. Shaders currently in use:
- // SkShader::CreateBitmapShader
- // SkGradientShader::CreateRadial
- // SkGradientShader::CreateLinear
- // DCHECK(!paint.getShader());
-
- // http://b/1106647 Implement loopers and mask filter. Looper currently in
- // use:
- // SkBlurDrawLooper is used for shadows.
- // DCHECK(!paint.getLooper());
- // DCHECK(!paint.getMaskFilter());
-
- // http://b/1165900 Implement xfermode.
- // DCHECK(!paint.getXfermode());
-
- // The path effect should be processed before arriving here.
- DCHECK(!paint.getPathEffect());
-
- // These aren't used in the code. Verify this assumption.
- DCHECK(!paint.getColorFilter());
- DCHECK(!paint.getRasterizer());
- // Reuse code to load Win32 Fonts.
- DCHECK(!paint.getTypeface());
- return true;
-}
-
-void VectorDevice::setMatrixClip(const SkMatrix& transform,
- const SkRegion& region) {
- transform_ = transform;
- LoadTransformToDC(hdc_, transform_);
- clip_region_ = region;
- if (!clip_region_.isEmpty())
- LoadClipRegion();
-}
-
-void VectorDevice::drawToHDC(HDC dc, int x, int y, const RECT* src_rect) {
- NOTREACHED();
-}
-
-void VectorDevice::LoadClipRegion() {
- SkMatrix t;
- t.reset();
- LoadClippingRegionToDC(hdc_, clip_region_, t);
-}
-
-bool VectorDevice::CreateBrush(bool use_brush, COLORREF color) {
- DCHECK(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
- // WHITE_BRUSH instead.
-
- if (!use_brush) {
- // Set the transparency.
- if (0 == SetBkMode(hdc_, TRANSPARENT)) {
- NOTREACHED();
- return false;
- }
-
- // Select the NULL brush.
- previous_brush_ = SelectObject(GetStockObject(NULL_BRUSH));
- return previous_brush_ != NULL;
- }
-
- // Set the opacity.
- if (0 == SetBkMode(hdc_, OPAQUE)) {
- NOTREACHED();
- return false;
- }
-
- // Create and select the brush.
- previous_brush_ = SelectObject(CreateSolidBrush(color));
- return previous_brush_ != NULL;
-}
-
-bool VectorDevice::CreatePen(bool use_pen, COLORREF color, int stroke_width,
- float stroke_miter, DWORD pen_style) {
- DCHECK(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
- // instead.
-
- // No pen case
- if (!use_pen) {
- previous_pen_ = SelectObject(GetStockObject(NULL_PEN));
- return previous_pen_ != NULL;
- }
-
- // Use the stock pen if the stroke width is 0.
- if (stroke_width == 0) {
- // Create a pen with the right color.
- previous_pen_ = SelectObject(::CreatePen(PS_SOLID, 0, color));
- return previous_pen_ != NULL;
- }
-
- // Load a custom pen.
- LOGBRUSH brush;
- brush.lbStyle = BS_SOLID;
- brush.lbColor = color;
- brush.lbHatch = 0;
- HPEN pen = ExtCreatePen(pen_style, stroke_width, &brush, 0, NULL);
- DCHECK(pen != NULL);
- previous_pen_ = SelectObject(pen);
- if (previous_pen_ == NULL)
- return false;
-
- if (!SetMiterLimit(hdc_, stroke_miter, NULL)) {
- NOTREACHED();
- return false;
- }
- return true;
-}
-
-void VectorDevice::Cleanup() {
- if (previous_brush_) {
- HGDIOBJ result = SelectObject(previous_brush_);
- previous_brush_ = NULL;
- if (result) {
- BOOL res = DeleteObject(result);
- DCHECK(res != 0);
- }
- }
- if (previous_pen_) {
- HGDIOBJ result = SelectObject(previous_pen_);
- previous_pen_ = NULL;
- if (result) {
- BOOL res = DeleteObject(result);
- DCHECK(res != 0);
- }
- }
- // Remove any loaded path from the context.
- AbortPath(hdc_);
-}
-
-HGDIOBJ VectorDevice::SelectObject(HGDIOBJ object) {
- HGDIOBJ result = ::SelectObject(hdc_, object);
- DCHECK(result != HGDI_ERROR);
- if (result == HGDI_ERROR)
- return NULL;
- return result;
-}
-
-bool VectorDevice::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.
- NOTREACHED();
- use_brush = false;
- }
-
- return CreateBrush(use_brush, SkColorToCOLORREF(paint.getColor()));
-}
-
-bool VectorDevice::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.
- NOTREACHED();
- use_pen = false;
- }
-
- DWORD pen_style = PS_GEOMETRIC | PS_SOLID;
- switch (paint.getStrokeJoin()) {
- case SkPaint::kMiter_Join:
- // Connects path segments with a sharp join.
- pen_style |= PS_JOIN_MITER;
- break;
- case SkPaint::kRound_Join:
- // Connects path segments with a round join.
- pen_style |= PS_JOIN_ROUND;
- break;
- case SkPaint::kBevel_Join:
- // Connects path segments with a flat bevel join.
- pen_style |= PS_JOIN_BEVEL;
- break;
- default:
- NOTREACHED();
- break;
- }
- switch (paint.getStrokeCap()) {
- case SkPaint::kButt_Cap:
- // Begin/end contours with no extension.
- pen_style |= PS_ENDCAP_FLAT;
- break;
- case SkPaint::kRound_Cap:
- // Begin/end contours with a semi-circle extension.
- pen_style |= PS_ENDCAP_ROUND;
- break;
- case SkPaint::kSquare_Cap:
- // Begin/end contours with a half square extension.
- pen_style |= PS_ENDCAP_SQUARE;
- break;
- default:
- NOTREACHED();
- break;
- }
-
- return CreatePen(use_pen,
- SkColorToCOLORREF(paint.getColor()),
- SkScalarRound(paint.getStrokeWidth()),
- paint.getStrokeMiter(),
- pen_style);
-}
-
-void VectorDevice::InternalDrawBitmap(const SkBitmap& bitmap, int x, int y,
- const SkPaint& paint) {
- uint8 alpha = paint.getAlpha();
- if (alpha == 0)
- return;
-
- bool is_translucent;
- if (alpha != 255) {
- // ApplyPaint expect an opaque color.
- SkPaint tmp_paint(paint);
- tmp_paint.setAlpha(255);
- if (!ApplyPaint(tmp_paint))
- return;
- is_translucent = true;
- } else {
- if (!ApplyPaint(paint))
- return;
- is_translucent = false;
- }
- int src_size_x = bitmap.width();
- int src_size_y = bitmap.height();
- if (!src_size_x || !src_size_y)
- return;
-
- // Create a BMP v4 header that we can serialize.
- BITMAPV4HEADER bitmap_header;
- gfx::CreateBitmapV4Header(src_size_x, src_size_y, &bitmap_header);
- HDC dc = getBitmapDC();
- SkAutoLockPixels lock(bitmap);
- DCHECK_EQ(bitmap.getConfig(), SkBitmap::kARGB_8888_Config);
- const uint32_t* pixels = static_cast<const uint32_t*>(bitmap.getPixels());
- if (pixels == NULL) {
- NOTREACHED();
- return;
- }
-
- if (!is_translucent) {
- int row_length = bitmap.rowBytesAsPixels();
- // There is no quick way to determine if an image is opaque.
- for (int y2 = 0; y2 < src_size_y; ++y2) {
- for (int x2 = 0; x2 < src_size_x; ++x2) {
- if (SkColorGetA(pixels[(y2 * row_length) + x2]) != 255) {
- is_translucent = true;
- y2 = src_size_y;
- break;
- }
- }
- }
- }
-
- BITMAPINFOHEADER hdr;
- gfx::CreateBitmapHeader(src_size_x, src_size_y, &hdr);
- if (is_translucent) {
- // The image must be loaded as a bitmap inside a device context.
- ScopedHDC bitmap_dc(::CreateCompatibleDC(dc));
- void* bits = NULL;
- ScopedBitmap hbitmap(::CreateDIBSection(
- bitmap_dc, reinterpret_cast<const BITMAPINFO*>(&hdr),
- DIB_RGB_COLORS, &bits, NULL, 0));
- memcpy(bits, pixels, bitmap.getSize());
- DCHECK(hbitmap);
- HGDIOBJ old_bitmap = ::SelectObject(bitmap_dc, hbitmap);
- DeleteObject(old_bitmap);
-
- // After some analysis of IE7's behavior, this is the thing to do. I was
- // sure IE7 was doing so kind of bitmasking due to the way translucent image
- // where renderered but after some windbg tracing, it is being done by the
- // printer driver after all (mostly HP printers). IE7 always use AlphaBlend
- // for bitmasked images. The trick seems to switch the stretching mode in
- // what the driver expects.
- DWORD previous_mode = GetStretchBltMode(dc);
- BOOL result = SetStretchBltMode(dc, COLORONCOLOR);
- DCHECK(result);
- // Note that this function expect premultiplied colors (!)
- BLENDFUNCTION blend_function = {AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA};
- result = GdiAlphaBlend(dc,
- x, y, // Destination origin.
- src_size_x, src_size_y, // Destination size.
- bitmap_dc,
- 0, 0, // Source origin.
- src_size_x, src_size_y, // Source size.
- blend_function);
- DCHECK(result);
- result = SetStretchBltMode(dc, previous_mode);
- DCHECK(result);
- } else {
- BOOL result = StretchDIBits(dc,
- x, y, // Destination origin.
- src_size_x, src_size_y,
- 0, 0, // Source origin.
- src_size_x, src_size_y, // Source size.
- pixels,
- reinterpret_cast<const BITMAPINFO*>(&hdr),
- DIB_RGB_COLORS,
- SRCCOPY);
- DCHECK(result);
- }
- Cleanup();
-}
-
-} // namespace gfx
-
diff --git a/webkit/port/platform/graphics/skia/public/VectorDevice.h b/webkit/port/platform/graphics/skia/public/VectorDevice.h
deleted file mode 100644
index 8579689..0000000
--- a/webkit/port/platform/graphics/skia/public/VectorDevice.h
+++ /dev/null
@@ -1,119 +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 VectorDevice_h
-#define VectorDevice_h
-
-#include "base/basictypes.h"
-#include "base/gfx/platform_device_win.h"
-#include "SkMatrix.h"
-#include "SkRegion.h"
-
-namespace gfx {
-
-// A device is basically a wrapper around SkBitmap that provides a surface for
-// 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 {
- public:
- // Factory function. The DC is kept as the output context.
- static VectorDevice* create(HDC dc, int width, int height);
-
- VectorDevice(HDC dc, const SkBitmap& bitmap);
- virtual ~VectorDevice();
-
- virtual HDC getBitmapDC() {
- return hdc_;
- }
-
- virtual void drawPaint(const SkDraw& draw, const SkPaint& paint);
- virtual void drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
- size_t count, const SkPoint[], const SkPaint& paint);
- virtual void drawRect(const SkDraw& draw, const SkRect& r,
- const SkPaint& paint);
- virtual void drawPath(const SkDraw& draw, const SkPath& path,
- const SkPaint& paint);
- virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
- const SkMatrix& matrix, const SkPaint& paint);
- virtual void drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
- int x, int y, const SkPaint& paint);
- virtual void drawText(const SkDraw& draw, const void* text, size_t len,
- SkScalar x, SkScalar y, const SkPaint& paint);
- virtual void drawPosText(const SkDraw& draw, const void* text, size_t len,
- const SkScalar pos[], SkScalar constY,
- int scalarsPerPos, const SkPaint& paint);
- virtual void drawTextOnPath(const SkDraw& draw, const void* text, size_t len,
- const SkPath& path, const SkMatrix* matrix,
- const SkPaint& paint);
- virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode,
- int vertexCount,
- const SkPoint verts[], const SkPoint texs[],
- const SkColor colors[], SkXfermode* xmode,
- const uint16_t indices[], int indexCount,
- const SkPaint& paint);
- virtual void drawDevice(const SkDraw& draw, SkDevice*, int x, int y,
- const SkPaint&);
-
-
- virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region);
- virtual void drawToHDC(HDC dc, int x, int y, const RECT* src_rect);
- virtual bool IsVectorial() { return true; }
-
- void LoadClipRegion();
-
- private:
- // Applies the SkPaint's painting properties in the current GDI context, if
- // possible. If GDI can't support all paint's properties, returns false. It
- // doesn't execute the "commands" in SkPaint.
- bool ApplyPaint(const SkPaint& paint);
-
- // Selects a new object in the device context. It can be a pen, a brush, a
- // clipping region, a bitmap or a font. Returns the old selected object.
- HGDIOBJ SelectObject(HGDIOBJ object);
-
- // Creates a brush according to SkPaint's properties.
- bool CreateBrush(bool use_brush, const SkPaint& paint);
-
- // Creates a pen according to SkPaint's properties.
- bool CreatePen(bool use_pen, const SkPaint& paint);
-
- // Restores back the previous objects (pen, brush, etc) after a paint command.
- void Cleanup();
-
- // Creates a brush according to SkPaint's properties.
- bool CreateBrush(bool use_brush, COLORREF color);
-
- // Creates a pen according to SkPaint's properties.
- bool CreatePen(bool use_pen, COLORREF color, int stroke_width,
- float stroke_miter, DWORD pen_style);
-
- // Draws a bitmap in the the device, using the currently loaded matrix.
- void InternalDrawBitmap(const SkBitmap& bitmap, int x, int y,
- const SkPaint& paint);
-
- // The Windows Device Context handle. It is the backend used with GDI drawing.
- // This backend is write-only and vectorial.
- HDC hdc_;
-
- // Translation assigned to the DC: we need to keep track of this separately
- // so it can be updated even if the DC isn't created yet.
- SkMatrix transform_;
-
- // The current clipping
- SkRegion clip_region_;
-
- // Previously selected brush before the current drawing.
- HGDIOBJ previous_brush_;
-
- // Previously selected pen before the current drawing.
- HGDIOBJ previous_pen_;
-
- DISALLOW_COPY_AND_ASSIGN(VectorDevice);
-};
-
-} // namespace gfx
-
-#endif // VectorDevice_h
-