diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-22 00:10:00 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-22 00:10:00 +0000 |
commit | 8c2fcd19acaa0b3aeeae0aacd0f698d9d0e4b0a4 (patch) | |
tree | 9ae4cf3df2df8b9816abbeeefcde36b6dd33a040 /webkit | |
parent | fbbb58d4c5cc57c72b84ee4337b155e2a64224e1 (diff) | |
download | chromium_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
Diffstat (limited to 'webkit')
14 files changed, 0 insertions, 1451 deletions
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/BitmapPlatformDevice.h b/webkit/port/platform/graphics/skia/public/BitmapPlatformDevice.h deleted file mode 100644 index 1b0df28..0000000 --- a/webkit/port/platform/graphics/skia/public/BitmapPlatformDevice.h +++ /dev/null @@ -1,30 +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 bitmap device class -// that can be used by upper-level classes that just need to pass a reference -// around. - -#if defined(WIN32) -#include "skia/ext/bitmap_platform_device_win.h" -namespace gfx { - -typedef BitmapPlatformDeviceWin BitmapPlatformDevice; - -} // namespace gfx -#elif defined(__APPLE__) -#include "skia/ext/bitmap_platform_device_mac.h" -namespace gfx { - -typedef BitmapPlatformDeviceMac BitmapPlatformDevice; - -} // namespace gfx -#elif defined(__linux__) -#include "BitmapPlatformDeviceLinux.h" -namespace gfx { - -typedef BitmapPlatformDeviceLinux BitmapPlatformDevice; - -} // namespace gfx -#endif diff --git a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.cpp b/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.cpp deleted file mode 100644 index 18f8ab1..0000000 --- a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.cpp +++ /dev/null @@ -1,94 +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 "base/gfx/bitmap_platform_device_linux.h" - -#include <cairo/cairo.h> - -#include "base/logging.h" - -namespace gfx { - -// ----------------------------------------------------------------------------- -// 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 -// data. -// ----------------------------------------------------------------------------- -class BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinuxData - : public base::RefCounted<BitmapPlatformDeviceLinuxData> { - public: - explicit BitmapPlatformDeviceLinuxData(cairo_surface_t* surface) - : surface_(surface) { } - - cairo_surface_t* surface() const { return surface_; } - - protected: - cairo_surface_t *const surface_; - - friend class base::RefCounted<BitmapPlatformDeviceLinuxData>; - ~BitmapPlatformDeviceLinuxData() { - cairo_surface_destroy(surface_); - } - - DISALLOW_EVIL_CONSTRUCTORS(BitmapPlatformDeviceLinuxData); -}; - -// 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 = - cairo_image_surface_create(CAIRO_FORMAT_ARGB32, - width, height); - - SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, - cairo_image_surface_get_stride(surface)); - bitmap.setPixels(cairo_image_surface_get_data(surface)); - bitmap.setIsOpaque(is_opaque); - -#ifndef NDEBUG - if (is_opaque) { - bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green - } -#endif - - // The device object will take ownership of the graphics context. - return new BitmapPlatformDeviceLinux - (bitmap, new BitmapPlatformDeviceLinuxData(surface)); -} - -// 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( - const SkBitmap& bitmap, - BitmapPlatformDeviceLinuxData* data) - : PlatformDeviceLinux(bitmap), - data_(data) { -} - -BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux( - const BitmapPlatformDeviceLinux& other) - : PlatformDeviceLinux(const_cast<BitmapPlatformDeviceLinux&>( - other).accessBitmap(true)), - data_(other.data_) { -} - -BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() { -} - -cairo_surface_t* BitmapPlatformDeviceLinux::surface() const { - return data_->surface(); -} - -BitmapPlatformDeviceLinux& BitmapPlatformDeviceLinux::operator=( - const BitmapPlatformDeviceLinux& other) { - data_ = other.data_; - return *this; -} - -} // namespace gfx diff --git a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.h b/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.h deleted file mode 100644 index 4985c5b..0000000 --- a/webkit/port/platform/graphics/skia/public/BitmapPlatformDeviceLinux.h +++ /dev/null @@ -1,91 +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 BitmapPlatformDeviceLinux_h -#define BitmapPlatformDeviceLinux_h - -#include "PlatformDeviceLinux.h" -#include "base/ref_counted.h" - -typedef struct _cairo_surface cairo_surface_t; - -// ----------------------------------------------------------------------------- -// Image byte ordering on Linux: -// -// Pixels are packed into 32-bit words these days. Even for 24-bit images, -// often 8-bits will be left unused for alignment reasons. Thus, when you see -// ARGB as the byte order you have to wonder if that's in memory order or -// little-endian order. Here I'll write A.R.G.B to specifiy the memory order. -// -// GdkPixbuf's provide a nice backing store and defaults to R.G.B.A order. -// They'll do the needed byte swapping to match the X server when drawn. -// -// Skia can be controled in skia/include/corecg/SkUserConfig.h (see bits about -// SK_R32_SHIFT). For Linux we define it to be ARGB in registers. For little -// endian machines that means B.G.R.A in memory. -// -// The image loaders are controlled in -// webkit/port/platform/image-decoders/ImageDecoder.h (see setRGBA). These are -// also configured for ARGB in registers. -// -// Cairo's only 32-bit mode is ARGB in registers. -// -// X servers commonly have a 32-bit visual with xRGB in registers (since they -// typically don't do alpha blending of drawables at the user level. Composite -// extensions aside.) -// -// We don't use GdkPixbuf because its byte order differs from the rest. Most -// importantly, it differs from Cairo which, being a system library, is -// something that we can't easily change. -// ----------------------------------------------------------------------------- - -namespace gfx { - -// ----------------------------------------------------------------------------- -// This is the Linux bitmap backing for Skia. We create a Cairo image surface -// to store the backing buffer. This buffer is BGRA in memory (on little-endian -// machines). -// -// For now we are also using Cairo to paint to the Drawables so we provide an -// accessor for getting the surface. -// -// This is all quite ok for test_shell. In the future we will want to use -// 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 { - // A reference counted cairo surface - class BitmapPlatformDeviceLinuxData; - - public: - /// Static constructor. I don't understand this, it's just a copy of the mac - static BitmapPlatformDeviceLinux* Create(int width, int height, - bool is_opaque); - - // Create a BitmapPlatformDeviceLinux from an already constructed bitmap; - // you should probably be using Create(). This may become private later if - // we ever have to share state between some native drawing UI and Skia, like - // 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); - - // A stub copy constructor. Needs to be properly implemented. - BitmapPlatformDeviceLinux(const BitmapPlatformDeviceLinux& other); - - // Bitmaps aren't vector graphics. - virtual bool IsVectorial() { return false; } - - cairo_surface_t* surface() const; - - private: - scoped_refptr<BitmapPlatformDeviceLinuxData> data_; -}; - -} // namespace gfx - -#endif // BitmapPlatformDeviceLinux_h diff --git a/webkit/port/platform/graphics/skia/public/PlatformCanvas.h b/webkit/port/platform/graphics/skia/public/PlatformCanvas.h deleted file mode 100644 index a2af39e..0000000 --- a/webkit/port/platform/graphics/skia/public/PlatformCanvas.h +++ /dev/null @@ -1,30 +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 canvas class -// that can be used by upper-level classes that just need to pass a reference -// around. - -#if defined(WIN32) -#include "skia/ext/platform_canvas_win.h" -namespace gfx { - -typedef PlatformCanvasWin PlatformCanvas; - -} // namespace gfx -#elif defined(__APPLE__) -#include "skia/ext/platform_canvas_mac.h" -namespace gfx { - -typedef PlatformCanvasMac PlatformCanvas; - -} // namespace gfx -#elif defined(__linux__) -#include "PlatformCanvasLinux.h" -namespace gfx { - -typedef PlatformCanvasLinux PlatformCanvas; - -} // namespace gfx -#endif diff --git a/webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.cpp b/webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.cpp deleted file mode 100644 index b579536..0000000 --- a/webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.cpp +++ /dev/null @@ -1,55 +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 "base/gfx/platform_canvas_linux.h" - -#include "base/gfx/platform_device_linux.h" -#include "base/gfx/bitmap_platform_device_linux.h" -#include "base/logging.h" - -namespace gfx { - -PlatformCanvasLinux::PlatformCanvasLinux() : SkCanvas() { -} - -PlatformCanvasLinux::PlatformCanvasLinux(int width, int height, bool is_opaque) - : SkCanvas() { - if (!initialize(width, height, is_opaque)) - CHECK(false); -} - -PlatformCanvasLinux::~PlatformCanvasLinux() { -} - -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; -} - -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()); -} - -SkDevice* PlatformCanvasLinux::createDevice(SkBitmap::Config config, - int width, - int height, - bool is_opaque, bool isForLayer) { - DCHECK(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); -} - -} // namespace gfx diff --git a/webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.h b/webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.h deleted file mode 100644 index 6eefee8..0000000 --- a/webkit/port/platform/graphics/skia/public/PlatformCanvasLinux.h +++ /dev/null @@ -1,52 +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 PlatformCanvasLinux_h -#define PlatformCanvasLinux_h - -#include "PlatformDeviceLinux.h" - -namespace gfx { - -// 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); - virtual ~PlatformCanvasLinux(); - - // For two-part init, call if you use the no-argument constructor above - bool initialize(int width, int height, bool is_opaque); - - // 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; - - 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&); -}; - -} // namespace gfx - -#endif // PlatformCanvasLinux_h 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/PlatformDeviceLinux.cpp b/webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.cpp deleted file mode 100644 index 50ffd51..0000000 --- a/webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.cpp +++ /dev/null @@ -1,13 +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 "PlatformDeviceLinux.h" - -namespace gfx { - -PlatformDeviceLinux::PlatformDeviceLinux(const SkBitmap& bitmap) - : SkDevice(bitmap) { -} - -} // namespace gfx diff --git a/webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.h b/webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.h deleted file mode 100644 index 7c853a4..0000000 --- a/webkit/port/platform/graphics/skia/public/PlatformDeviceLinux.h +++ /dev/null @@ -1,25 +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 PlatformDeviceLinux_h -#define PlatformDeviceLinux_h - -#include "SkDevice.h" - -namespace gfx { - -// Blindly copying the mac hierarchy. -class PlatformDeviceLinux : public SkDevice { - public: - // Returns if the preferred rendering engine is vectorial or bitmap based. - virtual bool IsVectorial() = 0; - - protected: - // Forwards |bitmap| to SkDevice's constructor. - PlatformDeviceLinux(const SkBitmap& bitmap); -}; - -} // namespace gfx - -#endif // PlatformDeviceLinux_h 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 - |