summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authortomhudson <tomhudson@google.com>2015-11-30 09:36:51 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-30 17:37:27 +0000
commit31521a8fe53dda37a9a838402693b4d2060ec432 (patch)
tree79459a5d0657b62294dca204c877082e10f583ce /skia
parent7bd67e23e178d871212183270fb1c577025e296d (diff)
downloadchromium_src-31521a8fe53dda37a9a838402693b4d2060ec432.zip
chromium_src-31521a8fe53dda37a9a838402693b4d2060ec432.tar.gz
chromium_src-31521a8fe53dda37a9a838402693b4d2060ec432.tar.bz2
The API of the metadata helpers doesn't depend on PlatformDevice.
Neither do the typedefs moved to the new platform_surface.h. Some #includes of platform_device.h were already unnecessary. All changes outside skia/ext/ should be purely mechanical renamings or trimming of include lists. R=fmalita@chromium.org TBR=thestig@chromium.org,danakj@chromium.org,piman@chromium.org BUG=543755 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1462163002 Cr-Commit-Position: refs/heads/master@{#362151}
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/platform_canvas.cc51
-rw-r--r--skia/ext/platform_canvas.h17
-rw-r--r--skia/ext/platform_device.cc40
-rw-r--r--skia/ext/platform_device.h38
-rw-r--r--skia/ext/platform_device_mac.cc12
-rw-r--r--skia/ext/platform_device_win.cc1
-rw-r--r--skia/ext/platform_surface.h39
-rw-r--r--skia/ext/skia_utils_mac.mm4
8 files changed, 111 insertions, 91 deletions
diff --git a/skia/ext/platform_canvas.cc b/skia/ext/platform_canvas.cc
index cf362b3..0df6496 100644
--- a/skia/ext/platform_canvas.cc
+++ b/skia/ext/platform_canvas.cc
@@ -4,9 +4,33 @@
#include "skia/ext/platform_canvas.h"
+#include "base/logging.h"
#include "skia/ext/bitmap_platform_device.h"
+#include "skia/ext/platform_device.h"
+#include "third_party/skia/include/core/SkMetaData.h"
#include "third_party/skia/include/core/SkTypes.h"
+namespace {
+
+#if defined(OS_MACOSX)
+const char kIsPreviewMetafileKey[] = "CrIsPreviewMetafile";
+#endif
+
+void SetBoolMetaData(const SkCanvas& canvas, const char* key, bool value) {
+ SkMetaData& meta = skia::GetMetaData(canvas);
+ meta.setBool(key, value);
+}
+
+bool GetBoolMetaData(const SkCanvas& canvas, const char* key) {
+ bool value;
+ SkMetaData& meta = skia::GetMetaData(canvas);
+ if (!meta.findBool(key, &value))
+ value = false;
+ return value;
+}
+
+} // namespace
+
namespace skia {
SkBaseDevice* GetTopDevice(const SkCanvas& canvas) {
@@ -77,9 +101,34 @@ SkCanvas* CreateCanvas(const skia::RefPtr<SkBaseDevice>& device, OnFailureType f
if (!device) {
if (CRASH_ON_FAILURE == failureType)
SK_CRASH();
- return NULL;
+ return nullptr;
}
return new SkCanvas(device.get());
}
+SkMetaData& GetMetaData(const SkCanvas& canvas) {
+ SkBaseDevice* device = canvas.getDevice();
+ DCHECK(device != nullptr);
+ return device->getMetaData();
+}
+
+#if defined(OS_MACOSX)
+void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) {
+ SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview);
+}
+
+bool IsPreviewMetafile(const SkCanvas& canvas) {
+ return GetBoolMetaData(canvas, kIsPreviewMetafileKey);
+}
+
+CGContextRef GetBitmapContext(const SkCanvas& canvas) {
+ SkBaseDevice* device = GetTopDevice(canvas);
+ PlatformDevice* platform_device = GetPlatformDevice(device);
+ return platform_device ? platform_device->GetBitmapContext() :
+ nullptr;
+}
+
+#endif
+
+
} // namespace skia
diff --git a/skia/ext/platform_canvas.h b/skia/ext/platform_canvas.h
index c46d6c4..61f5a87 100644
--- a/skia/ext/platform_canvas.h
+++ b/skia/ext/platform_canvas.h
@@ -8,13 +8,15 @@
// The platform-specific device will include the necessary platform headers
// to get the surface type.
#include "base/basictypes.h"
-#include "skia/ext/platform_device.h"
+#include "skia/ext/platform_surface.h"
#include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPixelRef.h"
#include "third_party/skia/include/core/SkPixmap.h"
+class SkBaseDevice;
+
namespace skia {
typedef SkCanvas PlatformCanvas;
@@ -171,6 +173,19 @@ class SK_API ScopedPlatformPaint {
ScopedPlatformPaint& operator=(const ScopedPlatformPaint&);
};
+// Following routines are used in print preview workflow to mark the
+// preview metafile.
+SK_API SkMetaData& GetMetaData(const SkCanvas& canvas);
+
+#if defined(OS_MACOSX)
+SK_API void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview);
+SK_API bool IsPreviewMetafile(const SkCanvas& canvas);
+
+// Returns the CGContext that backing the SkCanvas.
+// Returns NULL if none is bound.
+SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas);
+#endif
+
} // namespace skia
#endif // SKIA_EXT_PLATFORM_CANVAS_H_
diff --git a/skia/ext/platform_device.cc b/skia/ext/platform_device.cc
index e13e1dc..cd4aa09 100644
--- a/skia/ext/platform_device.cc
+++ b/skia/ext/platform_device.cc
@@ -7,33 +7,15 @@
#include "third_party/skia/include/core/SkMetaData.h"
-namespace skia {
-
namespace {
const char kDevicePlatformBehaviour[] = "CrDevicePlatformBehaviour";
-#if defined(OS_MACOSX)
-const char kIsPreviewMetafileKey[] = "CrIsPreviewMetafile";
-
-void SetBoolMetaData(const SkCanvas& canvas, const char* key, bool value) {
- SkMetaData& meta = skia::getMetaData(canvas);
- meta.setBool(key, value);
-}
-
-bool GetBoolMetaData(const SkCanvas& canvas, const char* key) {
- bool value;
- SkMetaData& meta = skia::getMetaData(canvas);
- if (!meta.findBool(key, &value))
- value = false;
- return value;
-}
-#endif
-
} // namespace
-void SetPlatformDevice(SkBaseDevice* device,
- PlatformDevice* platform_behaviour) {
+namespace skia {
+
+void SetPlatformDevice(SkBaseDevice* device, PlatformDevice* platform_behaviour) {
SkMetaData& meta_data = device->getMetaData();
meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour);
}
@@ -49,22 +31,6 @@ PlatformDevice* GetPlatformDevice(SkBaseDevice* device) {
return NULL;
}
-SkMetaData& getMetaData(const SkCanvas& canvas) {
- SkBaseDevice* device = canvas.getDevice();
- DCHECK(device != NULL);
- return device->getMetaData();
-}
-
-#if defined(OS_MACOSX)
-void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) {
- SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview);
-}
-
-bool IsPreviewMetafile(const SkCanvas& canvas) {
- return GetBoolMetaData(canvas, kIsPreviewMetafileKey);
-}
-#endif
-
bool PlatformDevice::SupportsPlatformPaint() {
return true;
}
diff --git a/skia/ext/platform_device.h b/skia/ext/platform_device.h
index fa60afb..5b718d2 100644
--- a/skia/ext/platform_device.h
+++ b/skia/ext/platform_device.h
@@ -12,41 +12,18 @@
#include <vector>
#endif
-#include "third_party/skia/include/core/SkColor.h"
+#include "skia/ext/platform_surface.h"
#include "third_party/skia/include/core/SkBitmapDevice.h"
#include "third_party/skia/include/core/SkTypes.h"
class SkMatrix;
-class SkMetaData;
class SkPath;
class SkRegion;
-#if defined(USE_CAIRO)
-typedef struct _cairo cairo_t;
-typedef struct _cairo_rectangle cairo_rectangle_t;
-#elif defined(OS_MACOSX)
-typedef struct CGContext* CGContextRef;
-typedef struct CGRect CGRect;
-#endif
-
namespace skia {
class PlatformDevice;
-#if defined(OS_WIN)
-typedef HDC PlatformSurface;
-typedef RECT PlatformRect;
-#elif defined(USE_CAIRO)
-typedef cairo_t* PlatformSurface;
-typedef cairo_rectangle_t PlatformRect;
-#elif defined(OS_MACOSX)
-typedef CGContextRef PlatformSurface;
-typedef CGRect PlatformRect;
-#else
-typedef void* PlatformSurface;
-typedef SkIRect* PlatformRect;
-#endif
-
// The following routines provide accessor points for the functionality
// exported by the various PlatformDevice ports.
// All calls to PlatformDevice::* should be routed through these
@@ -65,19 +42,6 @@ SK_API PlatformDevice* GetPlatformDevice(SkBaseDevice* device);
#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 SkBaseDevice. Forwards to the bound
-// PlatformDevice. Returns NULL if no PlatformDevice is bound.
-SK_API CGContextRef GetBitmapContext(SkBaseDevice* device);
-#endif
-
-// Following routines are used in print preview workflow to mark the
-// preview metafile.
-SK_API SkMetaData& getMetaData(const SkCanvas& canvas);
-
-#if defined(OS_MACOSX)
-SK_API void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview);
-SK_API bool IsPreviewMetafile(const SkCanvas& canvas);
#endif
// A SkBitmapDevice is basically a wrapper around SkBitmap that provides a
diff --git a/skia/ext/platform_device_mac.cc b/skia/ext/platform_device_mac.cc
index 065b767..5dfa211 100644
--- a/skia/ext/platform_device_mac.cc
+++ b/skia/ext/platform_device_mac.cc
@@ -7,21 +7,9 @@
#import <ApplicationServices/ApplicationServices.h>
#include "skia/ext/skia_utils_mac.h"
-#include "third_party/skia/include/core/SkMatrix.h"
-#include "third_party/skia/include/core/SkPath.h"
-#include "third_party/skia/include/core/SkTypes.h"
-#include "third_party/skia/include/core/SkUtils.h"
namespace skia {
-CGContextRef GetBitmapContext(SkBaseDevice* device) {
- PlatformDevice* platform_device = GetPlatformDevice(device);
- if (platform_device)
- return platform_device->GetBitmapContext();
-
- return NULL;
-}
-
CGContextRef PlatformDevice::BeginPlatformPaint() {
return GetBitmapContext();
}
diff --git a/skia/ext/platform_device_win.cc b/skia/ext/platform_device_win.cc
index ef48fbd..79b2c30 100644
--- a/skia/ext/platform_device_win.cc
+++ b/skia/ext/platform_device_win.cc
@@ -8,7 +8,6 @@
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkRegion.h"
-#include "third_party/skia/include/core/SkUtils.h"
namespace skia {
diff --git a/skia/ext/platform_surface.h b/skia/ext/platform_surface.h
new file mode 100644
index 0000000..b0d5173
--- /dev/null
+++ b/skia/ext/platform_surface.h
@@ -0,0 +1,39 @@
+// Copyright (c) 2015 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_SURFACE_H_
+#define SKIA_EXT_PLATFORM_SURFACE_H_
+
+#include "build/build_config.h"
+
+#include "third_party/skia/include/core/SkTypes.h"
+#include "third_party/skia/include/core/SkRect.h"
+
+#if defined(USE_CAIRO)
+typedef struct _cairo cairo_t;
+typedef struct _cairo_rectangle cairo_rectangle_t;
+#elif defined(OS_MACOSX)
+typedef struct CGContext* CGContextRef;
+typedef struct CGRect CGRect;
+#endif
+
+namespace skia {
+
+#if defined(OS_WIN)
+typedef HDC PlatformSurface;
+typedef RECT PlatformRect;
+#elif defined(USE_CAIRO)
+typedef cairo_t* PlatformSurface;
+typedef cairo_rectangle_t PlatformRect;
+#elif defined(OS_MACOSX)
+typedef CGContextRef PlatformSurface;
+typedef CGRect PlatformRect;
+#else
+typedef void* PlatformSurface;
+typedef SkIRect* PlatformRect;
+#endif
+
+} // namespace skia
+
+#endif // SKIA_EXT_PLATFORM_SURFACE_H_
diff --git a/skia/ext/skia_utils_mac.mm b/skia/ext/skia_utils_mac.mm
index fe05464c..32466f1 100644
--- a/skia/ext/skia_utils_mac.mm
+++ b/skia/ext/skia_utils_mac.mm
@@ -190,10 +190,10 @@ SkBitmap CGImageToSkBitmap(CGImageRef image) {
int width = CGImageGetWidth(image);
int height = CGImageGetHeight(image);
- scoped_ptr<SkBaseDevice> device(
+ scoped_ptr<skia::BitmapPlatformDevice> device(
skia::BitmapPlatformDevice::Create(NULL, width, height, false));
- CGContextRef context = skia::GetBitmapContext(device.get());
+ CGContextRef context = device->GetBitmapContext();
// We need to invert the y-axis of the canvas so that Core Graphics drawing
// happens right-side up. Skia has an upper-left origin and CG has a lower-