summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortwiz@google.com <twiz@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-28 16:51:31 +0000
committertwiz@google.com <twiz@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-28 16:51:31 +0000
commit8ebe83a40a7a025bce3a69b46a696311bdade196 (patch)
tree42e55bd04422d08ba37670719f44bb84e1b1b5d8
parent96e636f2a301cf9c17ff4118eb16adc3b431c8be (diff)
downloadchromium_src-8ebe83a40a7a025bce3a69b46a696311bdade196.zip
chromium_src-8ebe83a40a7a025bce3a69b46a696311bdade196.tar.gz
chromium_src-8ebe83a40a7a025bce3a69b46a696311bdade196.tar.bz2
CL removing inheritance of SkDevice from PlatformDevice.
PlatformDevice is now a base interface, which is implemented by the various flavours of BitmapPlatformDevice, and VectorPlatformDevice. The BitmapPlatformDevice and VectorPlatformDevice classes now inherit directly from SkDevice, or SkPDFDevice, as appropriate. PlatformDevice helper functions access the PlatformDevice interface attached to a SkDevice via meta-data on the SkDevice. BUG=none TEST=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=98230 Review URL: http://codereview.chromium.org/7633040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98585 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--printing/pdf_metafile_skia.cc11
-rw-r--r--skia/ext/bitmap_platform_device_linux.cc9
-rw-r--r--skia/ext/bitmap_platform_device_linux.h21
-rw-r--r--skia/ext/bitmap_platform_device_mac.cc3
-rw-r--r--skia/ext/bitmap_platform_device_mac.h15
-rw-r--r--skia/ext/bitmap_platform_device_win.cc4
-rw-r--r--skia/ext/bitmap_platform_device_win.h32
-rw-r--r--skia/ext/platform_device.cc9
-rw-r--r--skia/ext/platform_device.h130
-rw-r--r--skia/ext/platform_device_linux.cc15
-rw-r--r--skia/ext/platform_device_linux.h38
-rw-r--r--skia/ext/platform_device_mac.cc10
-rw-r--r--skia/ext/platform_device_mac.h80
-rw-r--r--skia/ext/platform_device_win.cc12
-rw-r--r--skia/ext/platform_device_win.h90
-rw-r--r--skia/ext/vector_platform_device_cairo_linux.cc18
-rw-r--r--skia/ext/vector_platform_device_cairo_linux.h15
-rw-r--r--skia/ext/vector_platform_device_emf_win.cc15
-rw-r--r--skia/ext/vector_platform_device_emf_win.h10
-rw-r--r--skia/ext/vector_platform_device_skia.cc168
-rw-r--r--skia/ext/vector_platform_device_skia.h58
-rw-r--r--skia/skia.gyp3
22 files changed, 237 insertions, 529 deletions
diff --git a/printing/pdf_metafile_skia.cc b/printing/pdf_metafile_skia.cc
index bc44131..0ec540e 100644
--- a/printing/pdf_metafile_skia.cc
+++ b/printing/pdf_metafile_skia.cc
@@ -61,17 +61,14 @@ SkDevice* PdfMetafileSkia::StartPageForVectorCanvas(
transform.preScale(SkFloatToScalar(scale_factor),
SkFloatToScalar(scale_factor));
- // TODO(ctguil): Refactor: don't create the PDF device explicitly here.
SkISize pdf_page_size = SkISize::Make(page_size.width(), page_size.height());
SkISize pdf_content_size =
SkISize::Make(content_area.width(), content_area.height());
SkRefPtr<SkPDFDevice> pdf_device =
- new SkPDFDevice(pdf_page_size, pdf_content_size, transform);
- pdf_device->unref(); // SkRefPtr and new both took a reference.
- skia::VectorPlatformDeviceSkia* device =
- new skia::VectorPlatformDeviceSkia(pdf_device.get());
- data_->current_page_ = device->PdfDevice();
- return device;
+ new skia::VectorPlatformDeviceSkia(pdf_page_size, pdf_content_size,
+ transform);
+ data_->current_page_ = pdf_device;
+ return pdf_device.get();
}
bool PdfMetafileSkia::StartPage(const gfx::Size& page_size,
diff --git a/skia/ext/bitmap_platform_device_linux.cc b/skia/ext/bitmap_platform_device_linux.cc
index 782b78f..3087adc 100644
--- a/skia/ext/bitmap_platform_device_linux.cc
+++ b/skia/ext/bitmap_platform_device_linux.cc
@@ -120,8 +120,9 @@ BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
BitmapPlatformDevice::BitmapPlatformDevice(
const SkBitmap& bitmap,
BitmapPlatformDeviceData* data)
- : PlatformDevice(bitmap),
+ : SkDevice(bitmap),
data_(data) {
+ SetPlatformDevice(this, this);
}
BitmapPlatformDevice::~BitmapPlatformDevice() {
@@ -146,6 +147,12 @@ cairo_t* BitmapPlatformDevice::BeginPlatformPaint() {
return cairo;
}
+void BitmapPlatformDevice::DrawToNativeContext(
+ PlatformSurface surface, int x, int y, const PlatformRect* src_rect) {
+ // Should never be called on Linux.
+ SkASSERT(false);
+}
+
void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform,
const SkRegion& region,
const SkClipStack&) {
diff --git a/skia/ext/bitmap_platform_device_linux.h b/skia/ext/bitmap_platform_device_linux.h
index e5e4437..57c12ce 100644
--- a/skia/ext/bitmap_platform_device_linux.h
+++ b/skia/ext/bitmap_platform_device_linux.h
@@ -7,8 +7,9 @@
#pragma once
#include "base/basictypes.h"
+#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
-#include "skia/ext/platform_device_linux.h"
+#include "skia/ext/platform_device.h"
typedef struct _cairo_surface cairo_surface_t;
@@ -56,7 +57,7 @@ namespace skia {
// shared memory between the renderer and the main process at least. In this
// case we'll probably create the buffer from a precreated region of memory.
// -----------------------------------------------------------------------------
-class BitmapPlatformDevice : public PlatformDevice {
+class BitmapPlatformDevice : public PlatformDevice, public SkDevice {
// A reference counted cairo surface
class BitmapPlatformDeviceData;
@@ -73,22 +74,24 @@ class BitmapPlatformDevice : public PlatformDevice {
static BitmapPlatformDevice* Create(int width, int height, bool is_opaque);
// This doesn't take ownership of |data|
- static BitmapPlatformDevice* Create(int width, int height,
- bool is_opaque, uint8_t* data);
+ static BitmapPlatformDevice* Create(int width, int height, bool is_opaque,
+ uint8_t* data);
- virtual void MakeOpaque(int x, int y, int width, int height);
+ virtual void MakeOpaque(int x, int y, int width, int height) OVERRIDE;
// Overridden from SkDevice:
virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region,
- const SkClipStack&);
+ const SkClipStack&) OVERRIDE;
// Overridden from PlatformDevice:
- virtual cairo_t* BeginPlatformPaint();
+ virtual cairo_t* BeginPlatformPaint() OVERRIDE;
+ virtual void DrawToNativeContext(PlatformSurface surface, int x, int y,
+ const PlatformRect* src_rect) OVERRIDE;
protected:
virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width,
- int height, bool isOpaque,
- Usage usage);
+ int height, bool isOpaque,
+ Usage usage) OVERRIDE;
private:
static BitmapPlatformDevice* Create(int width, int height, bool is_opaque,
diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc
index d6bfc50..15bf566 100644
--- a/skia/ext/bitmap_platform_device_mac.cc
+++ b/skia/ext/bitmap_platform_device_mac.cc
@@ -180,8 +180,9 @@ BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data,
// data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
BitmapPlatformDevice::BitmapPlatformDevice(
BitmapPlatformDeviceData* data, const SkBitmap& bitmap)
- : PlatformDevice(bitmap),
+ : SkDevice(bitmap),
data_(data) {
+ SetPlatformDevice(this, this);
}
BitmapPlatformDevice::~BitmapPlatformDevice() {
diff --git a/skia/ext/bitmap_platform_device_mac.h b/skia/ext/bitmap_platform_device_mac.h
index fddbaad..da14528 100644
--- a/skia/ext/bitmap_platform_device_mac.h
+++ b/skia/ext/bitmap_platform_device_mac.h
@@ -7,7 +7,8 @@
#pragma once
#include "base/basictypes.h"
-#include "skia/ext/platform_device_mac.h"
+#include "base/compiler_specific.h"
+#include "skia/ext/platform_device.h"
namespace skia {
@@ -25,7 +26,7 @@ namespace skia {
// For us, that other bitmap will become invalid as soon as the device becomes
// invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE
// DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead.
-class BitmapPlatformDevice : public PlatformDevice {
+class BitmapPlatformDevice : public PlatformDevice, public SkDevice {
public:
// |context| may be NULL.
static BitmapPlatformDevice* Create(CGContextRef context,
@@ -42,12 +43,12 @@ class BitmapPlatformDevice : public PlatformDevice {
// PlatformDevice overrides
virtual CGContextRef GetBitmapContext();
virtual void DrawToNativeContext(CGContextRef context, int x, int y,
- const CGRect* src_rect);
- virtual void MakeOpaque(int x, int y, int width, int height);
+ const CGRect* src_rect) OVERRIDE;
+ virtual void MakeOpaque(int x, int y, int width, int height) OVERRIDE;
// SkDevice overrides
virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region,
- const SkClipStack&);
+ const SkClipStack&) OVERRIDE;
protected:
// Reference counted data that can be shared between multiple devices. This
@@ -61,11 +62,11 @@ class BitmapPlatformDevice : public PlatformDevice {
// Flushes the CoreGraphics context so that the pixel data can be accessed
// directly by Skia. Overridden from SkDevice, this is called when Skia
// starts accessing pixel data.
- virtual void onAccessBitmap(SkBitmap*);
+ virtual void onAccessBitmap(SkBitmap*) OVERRIDE;
virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width,
int height, bool isOpaque,
- Usage usage);
+ Usage usage) OVERRIDE;
// Data associated with this device, guaranteed non-null. We hold a reference
// to this object.
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc
index f1345fa..3a2a5b4 100644
--- a/skia/ext/bitmap_platform_device_win.cc
+++ b/skia/ext/bitmap_platform_device_win.cc
@@ -165,10 +165,11 @@ BitmapPlatformDevice* BitmapPlatformDevice::create(int width,
BitmapPlatformDevice::BitmapPlatformDevice(
BitmapPlatformDeviceData* data,
const SkBitmap& bitmap)
- : PlatformDevice(bitmap),
+ : SkDevice(bitmap),
data_(data) {
// The data object is already ref'ed for us by create().
SkDEBUGCODE(begin_paint_count_ = 0);
+ SetPlatformDevice(this, this);
}
BitmapPlatformDevice::~BitmapPlatformDevice() {
@@ -262,4 +263,3 @@ SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice(
}
} // namespace skia
-
diff --git a/skia/ext/bitmap_platform_device_win.h b/skia/ext/bitmap_platform_device_win.h
index 270dc08..5a5e466 100644
--- a/skia/ext/bitmap_platform_device_win.h
+++ b/skia/ext/bitmap_platform_device_win.h
@@ -7,7 +7,8 @@
#pragma once
#include "base/basictypes.h"
-#include "skia/ext/platform_device_win.h"
+#include "base/compiler_specific.h"
+#include "skia/ext/platform_device.h"
namespace skia {
@@ -25,7 +26,7 @@ namespace skia {
// For us, that other bitmap will become invalid as soon as the device becomes
// invalid, which may lead to subtle bugs. Therefore, DO NOT ASSIGN THE
// DEVICE'S PIXEL DATA TO ANOTHER BITMAP, make sure you copy instead.
-class SK_API BitmapPlatformDevice : public PlatformDevice {
+class SK_API BitmapPlatformDevice : public PlatformDevice, public SkDevice {
public:
// Factory function. The screen DC is used to create the bitmap, and will not
// be stored beyond this function. is_opaque should be set if the caller
@@ -34,16 +35,11 @@ class SK_API BitmapPlatformDevice : public PlatformDevice {
// The shared_section parameter is optional (pass NULL for default behavior).
// If shared_section is non-null, then it must be a handle to a file-mapping
// object returned by CreateFileMapping. See CreateDIBSection for details.
- static BitmapPlatformDevice* create(HDC screen_dc,
- int width,
- int height,
- bool is_opaque,
- HANDLE shared_section);
+ static BitmapPlatformDevice* create(HDC screen_dc, int width, int height,
+ bool is_opaque, HANDLE shared_section);
// This version is the same as above but will get the screen DC itself.
- static BitmapPlatformDevice* create(int width,
- int height,
- bool is_opaque,
+ static BitmapPlatformDevice* create(int width, int height, bool is_opaque,
HANDLE shared_section);
virtual ~BitmapPlatformDevice();
@@ -51,26 +47,27 @@ class SK_API BitmapPlatformDevice : public PlatformDevice {
// PlatformDevice overrides
// Retrieves the bitmap DC, which is the memory DC for our bitmap data. The
// bitmap DC is lazy created.
- virtual PlatformSurface BeginPlatformPaint();
- virtual void EndPlatformPaint();
+ virtual PlatformSurface BeginPlatformPaint() OVERRIDE;
+ virtual void EndPlatformPaint() OVERRIDE;
- virtual void DrawToNativeContext(HDC dc, int x, int y, const RECT* src_rect);
- virtual void MakeOpaque(int x, int y, int width, int height);
+ virtual void DrawToNativeContext(HDC dc, int x, int y,
+ const RECT* src_rect) OVERRIDE;
+ virtual void MakeOpaque(int x, int y, int width, int height) OVERRIDE;
// Loads the given transform and clipping region into the HDC. This is
// overridden from SkDevice.
virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region,
- const SkClipStack&);
+ const SkClipStack&) OVERRIDE;
protected:
// Flushes the Windows device context so that the pixel data can be accessed
// directly by Skia. Overridden from SkDevice, this is called when Skia
// starts accessing pixel data.
- virtual void onAccessBitmap(SkBitmap* bitmap);
+ virtual void onAccessBitmap(SkBitmap* bitmap) OVERRIDE;
virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width,
int height, bool isOpaque,
- Usage usage);
+ Usage usage) OVERRIDE;
private:
// Reference counted data that can be shared between multiple devices. This
@@ -96,4 +93,3 @@ class SK_API BitmapPlatformDevice : public PlatformDevice {
} // namespace skia
#endif // SKIA_EXT_BITMAP_PLATFORM_DEVICE_WIN_H_
-
diff --git a/skia/ext/platform_device.cc b/skia/ext/platform_device.cc
index 4bfde0f..9e1dde7 100644
--- a/skia/ext/platform_device.cc
+++ b/skia/ext/platform_device.cc
@@ -27,5 +27,12 @@ PlatformDevice* GetPlatformDevice(SkDevice* device) {
return NULL;
}
-} // namespace skia
+bool PlatformDevice::IsNativeFontRenderingAllowed() {
+ return true;
+}
+bool PlatformDevice::AlphaBlendUsed() const {
+ return false;
+}
+
+} // namespace skia
diff --git a/skia/ext/platform_device.h b/skia/ext/platform_device.h
index 6b3afb1..55ef1f8 100644
--- a/skia/ext/platform_device.h
+++ b/skia/ext/platform_device.h
@@ -6,24 +6,28 @@
#define SKIA_EXT_PLATFORM_DEVICE_H_
#pragma once
-// This file provides an easy way to include the appropriate PlatformDevice
-// header file for your platform.
+#include "build/build_config.h"
-#if defined(WIN32)
+#if defined(OS_WIN)
#include <windows.h>
+#include <vector>
#endif
#include "third_party/skia/include/core/SkPreConfig.h"
+#include "third_party/skia/include/core/SkDevice.h"
#include "third_party/skia/include/core/SkColor.h"
+class SkMatrix;
+class SkPath;
+class SkRegion;
-class SkDevice;
struct SkIRect;
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun)
+#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_FREEBSD) \
+ || defined(OS_SUN)
typedef struct _cairo cairo_t;
typedef struct _cairo_rectangle cairo_rectangle_t;
-#elif defined(__APPLE__)
+#elif defined(OS_MACOSX)
typedef struct CGContext* CGContextRef;
typedef struct CGRect CGRect;
#endif
@@ -32,13 +36,14 @@ namespace skia {
class PlatformDevice;
-#if defined(WIN32)
+#if defined(OS_WIN)
typedef HDC PlatformSurface;
typedef RECT PlatformRect;
-#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun)
+#elif defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_FREEBSD) \
+ || defined(OS_SUN)
typedef cairo_t* PlatformSurface;
typedef cairo_rectangle_t PlatformRect;
-#elif defined(__APPLE__)
+#elif defined(OS_MACOSX)
typedef CGContextRef PlatformSurface;
typedef CGRect PlatformRect;
#endif
@@ -59,15 +64,106 @@ SK_API void SetPlatformDevice(SkDevice* device,
PlatformDevice* platform_device);
SK_API PlatformDevice* GetPlatformDevice(SkDevice* device);
-} // namespace skia
-#if defined(WIN32)
-#include "skia/ext/platform_device_win.h"
-#elif defined(__APPLE__)
-#include "skia/ext/platform_device_mac.h"
-#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
- defined(__sun)
-#include "skia/ext/platform_device_linux.h"
+#if defined(OS_WIN)
+// Initializes the default settings and colors in a device context.
+SK_API void InitializeDC(HDC context);
+#elif defined (OS_MACOSX)
+// Returns the CGContext that backing the SkDevice. Forwards to the bound
+// PlatformDevice. Returns NULL if no PlatformDevice is bound.
+SK_API CGContextRef GetBitmapContext(SkDevice* device);
+#endif
+
+// A SkDevice is basically a wrapper around SkBitmap that provides a surface for
+// SkCanvas to draw into. PlatformDevice provides a surface Windows can also
+// write to. It also provides functionality to play well with GDI drawing
+// functions. This class is abstract and must be subclassed. It provides the
+// basic interface to implement it either with or without a bitmap backend.
+//
+// PlatformDevice provides an interface which sub-classes of SkDevice can also
+// provide to allow for drawing by the native platform into the device.
+class SK_API PlatformDevice {
+ public:
+ virtual ~PlatformDevice() {}
+
+#if defined(OS_MACOSX)
+ // The CGContext that corresponds to the bitmap, used for CoreGraphics
+ // operations drawing into the bitmap. This is possibly heavyweight, so it
+ // should exist only during one pass of rendering.
+ virtual CGContextRef GetBitmapContext() = 0;
#endif
+ // The DC that corresponds to the bitmap, used for GDI operations drawing
+ // into the bitmap. This is possibly heavyweight, so it should be existant
+ // only during one pass of rendering.
+ virtual PlatformSurface BeginPlatformPaint();
+
+ // Finish a previous call to beginPlatformPaint.
+ virtual void EndPlatformPaint();
+
+ // Draws to the given screen DC, if the bitmap DC doesn't exist, this will
+ // temporarily create it. However, if you have created the bitmap DC, it will
+ // be more efficient if you don't free it until after this call so it doesn't
+ // have to be created twice. If src_rect is null, then the entirety of the
+ // source device will be copied.
+ virtual void DrawToNativeContext(PlatformSurface surface, int x, int y,
+ const PlatformRect* src_rect) = 0;
+
+ // Sets the opacity of each pixel in the specified region to be opaque.
+ virtual void MakeOpaque(int x, int y, int width, int height) { }
+
+ // Returns if GDI is allowed to render text to this device.
+ virtual bool IsNativeFontRenderingAllowed();
+
+ // True if AlphaBlend() was called during a
+ // BeginPlatformPaint()/EndPlatformPaint() pair.
+ // Used by the printing subclasses. See |VectorPlatformDeviceEmf|.
+ virtual bool AlphaBlendUsed() const;
+
+#if defined(OS_WIN)
+ // Loads a SkPath into the GDI context. The path can there after be used for
+ // clipping or as a stroke. Returns false if the path failed to be loaded.
+ static bool LoadPathToDC(HDC context, const SkPath& path);
+
+ // Loads a SkRegion into the GDI context.
+ static void LoadClippingRegionToDC(HDC context, const SkRegion& region,
+ const SkMatrix& transformation);
+#elif defined(OS_MACOSX)
+ // Loads a SkPath into the CG context. The path can there after be used for
+ // clipping or as a stroke.
+ static void LoadPathToCGContext(CGContextRef context, const SkPath& path);
+
+ // Initializes the default settings and colors in a device context.
+ static void InitializeCGContext(CGContextRef context);
+
+ // Loads a SkRegion into the CG context.
+ static void LoadClippingRegionToCGContext(CGContextRef context,
+ const SkRegion& region,
+ const SkMatrix& transformation);
+#endif
+
+ protected:
+#if defined(OS_WIN)
+ // Arrays must be inside structures.
+ struct CubicPoints {
+ SkPoint p[4];
+ };
+ typedef std::vector<CubicPoints> CubicPath;
+ typedef std::vector<CubicPath> CubicPaths;
+
+ // Loads the specified Skia transform into the device context, excluding
+ // perspective (which GDI doesn't support).
+ static void LoadTransformToDC(HDC dc, const SkMatrix& matrix);
+
+ // Transforms SkPath's paths into a series of cubic path.
+ static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath);
+#elif defined(OS_MACOSX)
+ // Loads the specified Skia transform into the device context
+ static void LoadTransformToCGContext(CGContextRef context,
+ const SkMatrix& matrix);
+#endif
+};
+
+} // namespace skia
+
#endif
diff --git a/skia/ext/platform_device_linux.cc b/skia/ext/platform_device_linux.cc
index f633758..f72e614 100644
--- a/skia/ext/platform_device_linux.cc
+++ b/skia/ext/platform_device_linux.cc
@@ -6,23 +6,12 @@
namespace skia {
-PlatformDevice::PlatformDevice(const SkBitmap& bitmap)
- : SkDevice(bitmap) {
- SetPlatformDevice(this, this);
-}
-
-bool PlatformDevice::IsNativeFontRenderingAllowed() {
- return true;
+PlatformSurface PlatformDevice::BeginPlatformPaint() {
+ return NULL;
}
void PlatformDevice::EndPlatformPaint() {
// We don't need to do anything on Linux here.
}
-void PlatformDevice::DrawToNativeContext(PlatformSurface surface, int x, int y,
- const PlatformRect* src_rect) {
- // Should never be called on Linux.
- SkASSERT(false);
-}
-
} // namespace skia
diff --git a/skia/ext/platform_device_linux.h b/skia/ext/platform_device_linux.h
deleted file mode 100644
index 51c292f..0000000
--- a/skia/ext/platform_device_linux.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SKIA_EXT_PLATFORM_DEVICE_LINUX_H_
-#define SKIA_EXT_PLATFORM_DEVICE_LINUX_H_
-#pragma once
-
-#include "skia/ext/platform_device.h"
-#include "third_party/skia/include/core/SkDevice.h"
-
-namespace skia {
-
-// Blindly copying the mac hierarchy.
-class PlatformDevice : public SkDevice {
- public:
- typedef cairo_t* PlatformSurface;
-
- // Returns if native platform APIs are allowed to render text to this device.
- virtual bool IsNativeFontRenderingAllowed();
-
- virtual PlatformSurface BeginPlatformPaint() = 0;
- virtual void EndPlatformPaint();
-
- virtual void DrawToNativeContext(PlatformSurface surface, int x, int y,
- const PlatformRect* src_rect );
-
- // Sets the opacity of each pixel in the specified region to be opaque.
- virtual void MakeOpaque(int x, int y, int width, int height) { }
-
- protected:
- // Forwards |bitmap| to SkDevice's constructor.
- explicit PlatformDevice(const SkBitmap& bitmap);
-};
-
-} // namespace skia
-
-#endif // SKIA_EXT_PLATFORM_DEVICE_LINUX_H_
diff --git a/skia/ext/platform_device_mac.cc b/skia/ext/platform_device_mac.cc
index 9d2695f..6ff017d 100644
--- a/skia/ext/platform_device_mac.cc
+++ b/skia/ext/platform_device_mac.cc
@@ -22,15 +22,6 @@ CGContextRef GetBitmapContext(SkDevice* device) {
return NULL;
}
-PlatformDevice::PlatformDevice(const SkBitmap& bitmap)
- : SkDevice(bitmap) {
- SetPlatformDevice(this, this);
-}
-
-bool PlatformDevice::IsNativeFontRenderingAllowed() {
- return true;
-}
-
CGContextRef PlatformDevice::BeginPlatformPaint() {
return GetBitmapContext();
}
@@ -162,4 +153,3 @@ void PlatformDevice::LoadClippingRegionToCGContext(
}
} // namespace skia
-
diff --git a/skia/ext/platform_device_mac.h b/skia/ext/platform_device_mac.h
deleted file mode 100644
index 610f07f..0000000
--- a/skia/ext/platform_device_mac.h
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SKIA_EXT_PLATFORM_DEVICE_MAC_H_
-#define SKIA_EXT_PLATFORM_DEVICE_MAC_H_
-#pragma once
-
-#include "third_party/skia/include/core/SkDevice.h"
-
-typedef struct CGContext* CGContextRef;
-typedef struct CGRect CGRect;
-
-class SkMatrix;
-class SkPath;
-class SkRegion;
-
-namespace skia {
-
-// Returns the CGContext that backing the SkDevice. Forwards to the bound
-// PlatformDevice. Returns NULL if no PlatformDevice is bound.
-SK_API CGContextRef GetBitmapContext(SkDevice* device);
-
-// A device is basically a wrapper around SkBitmap that provides a surface for
-// SkCanvas to draw into. Our device provides a surface CoreGraphics can also
-// write to. It also provides functionality to play well with CG drawing
-// functions.
-// This class is abstract and must be subclassed. It provides the basic
-// interface to implement it either with or without a bitmap backend.
-class PlatformDevice : public SkDevice {
- public:
- typedef CGContextRef PlatformSurface;
-
- // The CGContext that corresponds to the bitmap, used for CoreGraphics
- // operations drawing into the bitmap. This is possibly heavyweight, so it
- // should exist only during one pass of rendering.
- virtual CGContextRef GetBitmapContext() = 0;
-
- // Draws to the given graphics context. If the bitmap context doesn't exist,
- // this will temporarily create it. However, if you have created the bitmap
- // context, it will be more efficient if you don't free it until after this
- // call so it doesn't have to be created twice. If src_rect is null, then
- // the entirety of the source device will be copied.
- virtual void DrawToNativeContext(CGContextRef context, int x, int y,
- const CGRect* src_rect) = 0;
-
- // Sets the opacity of each pixel in the specified region to be opaque.
- virtual void MakeOpaque(int x, int y, int width, int height) { }
-
- // Returns if native platform APIs are allowed to render text to this device.
- virtual bool IsNativeFontRenderingAllowed();
-
- virtual PlatformSurface BeginPlatformPaint();
- virtual void EndPlatformPaint();
-
- // Initializes the default settings and colors in a device context.
- static void InitializeCGContext(CGContextRef context);
-
- // Loads a SkPath into the CG context. The path can there after be used for
- // clipping or as a stroke.
- static void LoadPathToCGContext(CGContextRef context, const SkPath& path);
-
- // Loads a SkRegion into the CG context.
- static void LoadClippingRegionToCGContext(CGContextRef context,
- const SkRegion& region,
- const SkMatrix& transformation);
-
- protected:
- // Forwards |bitmap| to SkDevice's constructor.
- PlatformDevice(const SkBitmap& bitmap);
-
- // Loads the specified Skia transform into the device context
- static void LoadTransformToCGContext(CGContextRef context,
- const SkMatrix& matrix);
-};
-
-} // namespace skia
-
-#endif // SKIA_EXT_PLATFORM_DEVICE_MAC_H_
-
diff --git a/skia/ext/platform_device_win.cc b/skia/ext/platform_device_win.cc
index ea72165..100a811 100644
--- a/skia/ext/platform_device_win.cc
+++ b/skia/ext/platform_device_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -51,9 +51,8 @@ void InitializeDC(HDC context) {
SkASSERT(res != 0);
}
-PlatformDevice::PlatformDevice(const SkBitmap& bitmap)
- : SkDevice(bitmap) {
- SetPlatformDevice(this, this);
+PlatformSurface PlatformDevice::BeginPlatformPaint() {
+ return 0;
}
void PlatformDevice::EndPlatformPaint() {
@@ -61,6 +60,10 @@ void PlatformDevice::EndPlatformPaint() {
// Flushing will be done in onAccessBitmap.
}
+void PlatformDevice::DrawToNativeContext(PlatformSurface surface, int x, int y,
+ const PlatformRect* src_rect) {
+}
+
// static
bool PlatformDevice::LoadPathToDC(HDC context, const SkPath& path) {
switch (path.getFillType()) {
@@ -233,4 +236,3 @@ void PlatformDevice::LoadClippingRegionToDC(HDC context,
}
} // namespace skia
-
diff --git a/skia/ext/platform_device_win.h b/skia/ext/platform_device_win.h
deleted file mode 100644
index f21ca1f..0000000
--- a/skia/ext/platform_device_win.h
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SKIA_EXT_PLATFORM_DEVICE_WIN_H_
-#define SKIA_EXT_PLATFORM_DEVICE_WIN_H_
-#pragma once
-
-#include <windows.h>
-
-#include <vector>
-
-#include "third_party/skia/include/core/SkDevice.h"
-
-class SkMatrix;
-class SkPath;
-class SkRegion;
-
-namespace skia {
-
-// Initializes the default settings and colors in a device context.
-SK_API void InitializeDC(HDC context);
-
-// A device is basically a wrapper around SkBitmap that provides a surface for
-// SkCanvas to draw into. Our device provides a surface Windows can also write
-// to. It also provides functionality to play well with GDI drawing functions.
-// This class is abstract and must be subclassed. It provides the basic
-// interface to implement it either with or without a bitmap backend.
-class SK_API PlatformDevice : public SkDevice {
- public:
- typedef HDC PlatformSurface;
-
- // The DC that corresponds to the bitmap, used for GDI operations drawing
- // into the bitmap. This is possibly heavyweight, so it should be existant
- // only during one pass of rendering.
- virtual PlatformSurface BeginPlatformPaint() = 0;
-
- // Finish a previous call to beginPlatformPaint.
- virtual void EndPlatformPaint();
-
- // Draws to the given screen DC, if the bitmap DC doesn't exist, this will
- // temporarily create it. However, if you have created the bitmap DC, it will
- // be more efficient if you don't free it until after this call so it doesn't
- // have to be created twice. If src_rect is null, then the entirety of the
- // source device will be copied.
- virtual void DrawToNativeContext(HDC dc, int x, int y,
- const RECT* src_rect) = 0;
-
- // Sets the opacity of each pixel in the specified region to be opaque.
- virtual void MakeOpaque(int x, int y, int width, int height) { }
-
- // Returns if GDI is allowed to render text to this device.
- virtual bool IsNativeFontRenderingAllowed() { return true; }
-
- // True if AlphaBlend() was called during a
- // BeginPlatformPaint()/EndPlatformPaint() pair.
- // Used by the printing subclasses. See |VectorPlatformDeviceEmf|.
- virtual bool AlphaBlendUsed() const { return false; }
-
- // Loads a SkPath into the GDI context. The path can there after be used for
- // clipping or as a stroke. Returns false if the path failed to be loaded.
- static bool LoadPathToDC(HDC context, const SkPath& path);
-
- // Loads a SkRegion into the GDI context.
- static void LoadClippingRegionToDC(HDC context, const SkRegion& region,
- const SkMatrix& transformation);
-
- protected:
- // Arrays must be inside structures.
- struct CubicPoints {
- SkPoint p[4];
- };
- typedef std::vector<CubicPoints> CubicPath;
- typedef std::vector<CubicPath> CubicPaths;
-
- // Forwards |bitmap| to SkDevice's constructor.
- PlatformDevice(const SkBitmap& bitmap);
-
- // Loads the specified Skia transform into the device context, excluding
- // perspective (which GDI doesn't support).
- static void LoadTransformToDC(HDC dc, const SkMatrix& matrix);
-
- // Transforms SkPath's paths into a series of cubic path.
- static bool SkPathToCubicPaths(CubicPaths* paths, const SkPath& skpath);
-};
-
-} // namespace skia
-
-#endif // SKIA_EXT_PLATFORM_DEVICE_WIN_H_
-
diff --git a/skia/ext/vector_platform_device_cairo_linux.cc b/skia/ext/vector_platform_device_cairo_linux.cc
index f4a4e0b..1d31cf6 100644
--- a/skia/ext/vector_platform_device_cairo_linux.cc
+++ b/skia/ext/vector_platform_device_cairo_linux.cc
@@ -69,9 +69,8 @@ bool IsContextValid(cairo_t* context) {
namespace skia {
// static
-PlatformDevice* VectorPlatformDeviceCairo::CreateDevice(cairo_t* context,
- int width, int height,
- bool isOpaque) {
+SkDevice* VectorPlatformDeviceCairo::CreateDevice(cairo_t* context, int width,
+ int height, bool isOpaque) {
// TODO(myhuang): Here we might also have similar issues as those on Windows
// (vector_canvas_win.cc, http://crbug.com/18382 & http://crbug.com/18383).
// Please note that is_opaque is true when we use this class for printing.
@@ -92,10 +91,12 @@ PlatformDevice* VectorPlatformDeviceCairo::CreateDevice(cairo_t* context,
VectorPlatformDeviceCairo::VectorPlatformDeviceCairo(PlatformSurface context,
const SkBitmap& bitmap)
- : PlatformDevice(bitmap),
+ : SkDevice(bitmap),
context_(context) {
SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config);
+ SetPlatformDevice(this, this);
+
// Increase the reference count to keep the context alive.
cairo_reference(context_);
@@ -107,11 +108,16 @@ VectorPlatformDeviceCairo::~VectorPlatformDeviceCairo() {
cairo_destroy(context_);
}
-PlatformDevice::PlatformSurface
-VectorPlatformDeviceCairo::BeginPlatformPaint() {
+PlatformSurface VectorPlatformDeviceCairo::BeginPlatformPaint() {
return context_;
}
+void VectorPlatformDeviceCairo::DrawToNativeContext(
+ PlatformSurface surface, int x, int y, const PlatformRect* src_rect) {
+ // Should never be called on Linux.
+ SkASSERT(false);
+}
+
SkDevice* VectorPlatformDeviceCairo::onCreateCompatibleDevice(
SkBitmap::Config config,
int width, int height,
diff --git a/skia/ext/vector_platform_device_cairo_linux.h b/skia/ext/vector_platform_device_cairo_linux.h
index 72a90f6..36be0c76 100644
--- a/skia/ext/vector_platform_device_cairo_linux.h
+++ b/skia/ext/vector_platform_device_cairo_linux.h
@@ -19,12 +19,13 @@ namespace skia {
// cooresponding Cairo APIs and outputs to a Cairo surface. Please NOTE that
// since it is completely vectorial, the bitmap content in it is thus
// meaningless.
-class SK_API VectorPlatformDeviceCairo : public PlatformDevice {
+class SK_API VectorPlatformDeviceCairo : public PlatformDevice,
+ public SkDevice {
public:
virtual ~VectorPlatformDeviceCairo();
- static PlatformDevice* CreateDevice(cairo_t* context, int width, int height,
- bool isOpaque);
+ static SkDevice* CreateDevice(cairo_t* context, int width, int height,
+ bool isOpaque);
// Clean up cached fonts. It is an error to call this while some
// VectorPlatformDeviceCairo callee is still using fonts created for it by
@@ -67,17 +68,19 @@ class SK_API VectorPlatformDeviceCairo : public PlatformDevice {
const SkPaint&) OVERRIDE;
virtual void setMatrixClip(const SkMatrix& transform, const SkRegion& region,
- const SkClipStack&);
+ const SkClipStack&) OVERRIDE;
// Overridden from PlatformDevice
- virtual PlatformSurface BeginPlatformPaint();
+ virtual PlatformSurface BeginPlatformPaint() OVERRIDE;
+ virtual void DrawToNativeContext(PlatformSurface surface, int x, int y,
+ const PlatformRect* src_rect) OVERRIDE;
protected:
VectorPlatformDeviceCairo(PlatformSurface context, const SkBitmap& bitmap);
virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width,
int height, bool isOpaque,
- Usage usage);
+ Usage usage) OVERRIDE;
private:
// Apply paint's color in the context.
diff --git a/skia/ext/vector_platform_device_emf_win.cc b/skia/ext/vector_platform_device_emf_win.cc
index eac7977..9741a83 100644
--- a/skia/ext/vector_platform_device_emf_win.cc
+++ b/skia/ext/vector_platform_device_emf_win.cc
@@ -15,9 +15,8 @@
namespace skia {
//static
-PlatformDevice* VectorPlatformDeviceEmf::CreateDevice(int width, int height,
- bool is_opaque,
- HANDLE shared_section) {
+SkDevice* VectorPlatformDeviceEmf::CreateDevice(
+ int width, int height, bool is_opaque, HANDLE shared_section) {
if (!is_opaque) {
// TODO(maruel): http://crbug.com/18382 When restoring a semi-transparent
// layer, i.e. merging it, we need to rasterize it because GDI doesn't
@@ -40,7 +39,7 @@ PlatformDevice* VectorPlatformDeviceEmf::CreateDevice(int width, int height,
// SkScalarRound(value) as SkScalarRound(value * 10). Safari is already
// doing the same for text rendering.
SkASSERT(shared_section);
- PlatformDevice* device = VectorPlatformDeviceEmf::create(
+ SkDevice* device = VectorPlatformDeviceEmf::create(
reinterpret_cast<HDC>(shared_section), width, height);
return device;
}
@@ -59,9 +58,7 @@ static void FillBitmapInfoHeader(int width, int height, BITMAPINFOHEADER* hdr) {
hdr->biClrImportant = 0;
}
-VectorPlatformDeviceEmf* VectorPlatformDeviceEmf::create(HDC dc,
- int width,
- int height) {
+SkDevice* VectorPlatformDeviceEmf::create(HDC dc, int width, int height) {
InitializeDC(dc);
// Link the SkBitmap to the current selected bitmap in the device context.
@@ -96,12 +93,13 @@ VectorPlatformDeviceEmf* VectorPlatformDeviceEmf::create(HDC dc,
}
VectorPlatformDeviceEmf::VectorPlatformDeviceEmf(HDC dc, const SkBitmap& bitmap)
- : PlatformDevice(bitmap),
+ : SkDevice(bitmap),
hdc_(dc),
previous_brush_(NULL),
previous_pen_(NULL),
alpha_blend_used_(false) {
transform_.reset();
+ SetPlatformDevice(this, this);
}
VectorPlatformDeviceEmf::~VectorPlatformDeviceEmf() {
@@ -865,4 +863,3 @@ void VectorPlatformDeviceEmf::InternalDrawBitmap(const SkBitmap& bitmap,
}
} // namespace skia
-
diff --git a/skia/ext/vector_platform_device_emf_win.h b/skia/ext/vector_platform_device_emf_win.h
index 61283ff..1d7e5a9a 100644
--- a/skia/ext/vector_platform_device_emf_win.h
+++ b/skia/ext/vector_platform_device_emf_win.h
@@ -18,14 +18,13 @@ namespace skia {
// SkCanvas to draw into. This specific device is not not backed by a surface
// and is thus unreadable. This is because the backend is completely vectorial.
// This device is a simple wrapper over a Windows device context (HDC) handle.
-class VectorPlatformDeviceEmf : public PlatformDevice {
+class VectorPlatformDeviceEmf : public PlatformDevice, public SkDevice {
public:
- SK_API static PlatformDevice* CreateDevice(int width, int height,
- bool isOpaque,
- HANDLE shared_section);
+ SK_API static SkDevice* CreateDevice(int width, int height, bool isOpaque,
+ HANDLE shared_section);
// Factory function. The DC is kept as the output context.
- static VectorPlatformDeviceEmf* create(HDC dc, int width, int height);
+ static SkDevice* create(HDC dc, int width, int height);
VectorPlatformDeviceEmf(HDC dc, const SkBitmap& bitmap);
virtual ~VectorPlatformDeviceEmf();
@@ -137,4 +136,3 @@ class VectorPlatformDeviceEmf : public PlatformDevice {
} // namespace skia
#endif // SKIA_EXT_VECTOR_PLATFORM_DEVICE_EMF_WIN_H_
-
diff --git a/skia/ext/vector_platform_device_skia.cc b/skia/ext/vector_platform_device_skia.cc
index 0971d1a..a320526 100644
--- a/skia/ext/vector_platform_device_skia.cc
+++ b/skia/ext/vector_platform_device_skia.cc
@@ -19,9 +19,12 @@ static inline SkBitmap makeABitmap(int width, int height) {
return bitmap;
}
-VectorPlatformDeviceSkia::VectorPlatformDeviceSkia(SkPDFDevice* pdf_device)
- : PlatformDevice(makeABitmap(pdf_device->width(), pdf_device->height())),
- pdf_device_(pdf_device) {
+VectorPlatformDeviceSkia::VectorPlatformDeviceSkia(
+ const SkISize& pageSize,
+ const SkISize& contentSize,
+ const SkMatrix& initialTransform)
+ : SkPDFDevice(pageSize, contentSize, initialTransform) {
+ SetPlatformDevice(this, this);
}
VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() {
@@ -31,7 +34,7 @@ bool VectorPlatformDeviceSkia::IsNativeFontRenderingAllowed() {
return false;
}
-PlatformDevice::PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() {
+PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() {
// Even when drawing a vector representation of the page, we have to
// provide a raster surface for plugins to render into - they don't have
// a vector interface. Therefore we create a BitmapPlatformDevice here
@@ -39,13 +42,13 @@ PlatformDevice::PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() {
// image in EndPlatformPaint.
DCHECK(raster_surface_ == NULL);
#if defined(OS_WIN)
- raster_surface_ = BitmapPlatformDevice::create(pdf_device_->width(),
- pdf_device_->height(),
+ raster_surface_ = BitmapPlatformDevice::create(width(),
+ height(),
false, /* not opaque */
NULL);
#elif defined(OS_POSIX) && !defined(OS_MACOSX)
- raster_surface_ = BitmapPlatformDevice::Create(pdf_device_->width(),
- pdf_device_->height(),
+ raster_surface_ = BitmapPlatformDevice::Create(width(),
+ height(),
false /* not opaque */);
#endif
raster_surface_->unref(); // SkRefPtr and create both took a reference.
@@ -60,143 +63,14 @@ void VectorPlatformDeviceSkia::EndPlatformPaint() {
// SkPDFDevice checks the passed SkDraw for an empty clip (only). Fake
// it out by setting a non-empty clip.
SkDraw draw;
- SkRegion clip(SkIRect::MakeWH(pdf_device_->width(), pdf_device_->height()));
+ SkRegion clip(SkIRect::MakeWH(width(), height()));
draw.fClip=&clip;
- pdf_device_->drawSprite(draw, raster_surface_->accessBitmap(false), 0, 0,
- paint);
+ drawSprite(draw, raster_surface_->accessBitmap(false), 0, 0, paint);
// BitmapPlatformDevice matches begin and end calls.
raster_surface_->EndPlatformPaint();
raster_surface_ = NULL;
}
-uint32_t VectorPlatformDeviceSkia::getDeviceCapabilities() {
- return SkDevice::getDeviceCapabilities() | kVector_Capability;
-}
-
-int VectorPlatformDeviceSkia::width() const {
- return pdf_device_->width();
-}
-
-int VectorPlatformDeviceSkia::height() const {
- return pdf_device_->height();
-}
-
-void VectorPlatformDeviceSkia::setMatrixClip(const SkMatrix& matrix,
- const SkRegion& region,
- const SkClipStack& stack) {
- pdf_device_->setMatrixClip(matrix, region, stack);
-}
-
-bool VectorPlatformDeviceSkia::readPixels(const SkIRect& srcRect,
- SkBitmap* bitmap) {
- return false;
-}
-
-void VectorPlatformDeviceSkia::drawPaint(const SkDraw& draw,
- const SkPaint& paint) {
- pdf_device_->drawPaint(draw, paint);
-}
-
-void VectorPlatformDeviceSkia::drawPoints(const SkDraw& draw,
- SkCanvas::PointMode mode,
- size_t count, const SkPoint pts[],
- const SkPaint& paint) {
- pdf_device_->drawPoints(draw, mode, count, pts, paint);
-}
-
-void VectorPlatformDeviceSkia::drawRect(const SkDraw& draw,
- const SkRect& rect,
- const SkPaint& paint) {
- pdf_device_->drawRect(draw, rect, paint);
-}
-
-void VectorPlatformDeviceSkia::drawPath(const SkDraw& draw,
- const SkPath& path,
- const SkPaint& paint,
- const SkMatrix* prePathMatrix,
- bool pathIsMutable) {
- pdf_device_->drawPath(draw, path, paint, prePathMatrix, pathIsMutable);
-}
-
-void VectorPlatformDeviceSkia::drawBitmap(const SkDraw& draw,
- const SkBitmap& bitmap,
- const SkIRect* srcRectOrNull,
- const SkMatrix& matrix,
- const SkPaint& paint) {
- pdf_device_->drawBitmap(draw, bitmap, srcRectOrNull, matrix, paint);
-}
-
-void VectorPlatformDeviceSkia::drawSprite(const SkDraw& draw,
- const SkBitmap& bitmap,
- int x, int y,
- const SkPaint& paint) {
- pdf_device_->drawSprite(draw, bitmap, x, y, paint);
-}
-
-void VectorPlatformDeviceSkia::drawText(const SkDraw& draw,
- const void* text,
- size_t byteLength,
- SkScalar x,
- SkScalar y,
- const SkPaint& paint) {
- pdf_device_->drawText(draw, text, byteLength, x, y, paint);
-}
-
-void VectorPlatformDeviceSkia::drawPosText(const SkDraw& draw,
- const void* text,
- size_t len,
- const SkScalar pos[],
- SkScalar constY,
- int scalarsPerPos,
- const SkPaint& paint) {
- pdf_device_->drawPosText(draw, text, len, pos, constY, scalarsPerPos, paint);
-}
-
-void VectorPlatformDeviceSkia::drawTextOnPath(const SkDraw& draw,
- const void* text,
- size_t len,
- const SkPath& path,
- const SkMatrix* matrix,
- const SkPaint& paint) {
- pdf_device_->drawTextOnPath(draw, text, len, path, matrix, paint);
-}
-
-void VectorPlatformDeviceSkia::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) {
- pdf_device_->drawVertices(draw, vmode, vertexCount, vertices, texs, colors,
- xmode, indices, indexCount, paint);
-}
-
-void VectorPlatformDeviceSkia::drawDevice(const SkDraw& draw,
- SkDevice* device,
- int x,
- int y,
- const SkPaint& paint) {
- SkDevice* real_device = device;
- if ((device->getDeviceCapabilities() & kVector_Capability)) {
- // Assume that a vectorial device means a VectorPlatformDeviceSkia, we need
- // to unwrap the embedded SkPDFDevice.
- VectorPlatformDeviceSkia* vector_device =
- static_cast<VectorPlatformDeviceSkia*>(device);
- vector_device->pdf_device_->setOrigin(vector_device->getOrigin().fX,
- vector_device->getOrigin().fY);
- real_device = vector_device->pdf_device_.get();
- }
- pdf_device_->drawDevice(draw, real_device, x, y, paint);
-}
-
-void VectorPlatformDeviceSkia::setDrawingArea(SkPDFDevice::DrawingArea area) {
- pdf_device_->setDrawingArea(area);
-}
-
#if defined(OS_WIN)
void VectorPlatformDeviceSkia::DrawToNativeContext(HDC dc,
int x,
@@ -214,16 +88,12 @@ CGContextRef VectorPlatformDeviceSkia::GetBitmapContext() {
SkASSERT(false);
return NULL;
}
-
-#endif
-
-SkDevice* VectorPlatformDeviceSkia::onCreateCompatibleDevice(
- SkBitmap::Config config, int width, int height, bool isOpaque,
- Usage /*usage*/) {
- SkAutoTUnref<SkDevice> dev(pdf_device_->createCompatibleDevice(config, width,
- height,
- isOpaque));
- return new VectorPlatformDeviceSkia(static_cast<SkPDFDevice*>(dev.get()));
+#elif defined(OS_LINUX)
+void VectorPlatformDeviceSkia::DrawToNativeContext(
+ PlatformSurface surface, int x, int y, const PlatformRect* src_rect) {
+ // Should never be called on Linux.
+ SkASSERT(false);
}
+#endif
} // namespace skia
diff --git a/skia/ext/vector_platform_device_skia.h b/skia/ext/vector_platform_device_skia.h
index 238996b..005d798 100644
--- a/skia/ext/vector_platform_device_skia.h
+++ b/skia/ext/vector_platform_device_skia.h
@@ -22,13 +22,13 @@ namespace skia {
class BitmapPlatformDevice;
-class VectorPlatformDeviceSkia : public PlatformDevice {
+class VectorPlatformDeviceSkia : public PlatformDevice, public SkPDFDevice {
public:
- SK_API VectorPlatformDeviceSkia(SkPDFDevice* pdf_device);
+ SK_API VectorPlatformDeviceSkia(const SkISize& pageSize,
+ const SkISize& contentSize,
+ const SkMatrix& initialTransform);
virtual ~VectorPlatformDeviceSkia();
- SkPDFDevice* PdfDevice() { return pdf_device_.get(); }
-
// PlatformDevice methods.
virtual bool IsNativeFontRenderingAllowed();
@@ -40,56 +40,12 @@ class VectorPlatformDeviceSkia : public PlatformDevice {
virtual void DrawToNativeContext(CGContext* context, int x, int y,
const CGRect* src_rect);
virtual CGContextRef GetBitmapContext();
+#elif defined(OS_LINUX)
+ virtual void DrawToNativeContext(PlatformSurface surface, int x, int y,
+ const PlatformRect* src_rect);
#endif
- // SkDevice methods.
- virtual uint32_t getDeviceCapabilities();
- virtual int width() const;
- virtual int height() const;
- virtual void setMatrixClip(const SkMatrix& matrix, const SkRegion& region,
- const SkClipStack& stack);
- virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
-
- 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& rect,
- const SkPaint& paint);
- virtual void drawPath(const SkDraw& draw, const SkPath& path,
- const SkPaint& paint, const SkMatrix* prePathMatrix,
- bool pathIsMutable);
- virtual void drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
- const SkIRect* srcRectOrNull, 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&);
-
- // Sets the drawing area for the device. Subsequent draw calls are
- // directed to the specific drawing area (margin or content area).
- SK_API void setDrawingArea(SkPDFDevice::DrawingArea area);
-
- protected:
- virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config, int width,
- int height, bool isOpaque,
- Usage usage);
-
private:
- SkRefPtr<SkPDFDevice> pdf_device_;
SkRefPtr<BitmapPlatformDevice> raster_surface_;
DISALLOW_COPY_AND_ASSIGN(VectorPlatformDeviceSkia);
diff --git a/skia/skia.gyp b/skia/skia.gyp
index 076df75..f83c360 100644
--- a/skia/skia.gyp
+++ b/skia/skia.gyp
@@ -685,11 +685,8 @@
'ext/platform_device.cc',
'ext/platform_device.h',
'ext/platform_device_linux.cc',
- 'ext/platform_device_linux.h',
'ext/platform_device_mac.cc',
- 'ext/platform_device_mac.h',
'ext/platform_device_win.cc',
- 'ext/platform_device_win.h',
'ext/SkMemory_new_handler.cpp',
'ext/skia_utils_mac.mm',
'ext/skia_utils_mac.h',