1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/logging.h"
6 #include "skia/ext/platform_device.h"
8 #include "third_party/skia/include/core/SkMetaData.h"
14 const char* kDevicePlatformBehaviour
= "CrDevicePlatformBehaviour";
15 const char* kDraftModeKey
= "CrDraftMode";
17 #if defined(OS_MACOSX) || defined(OS_WIN)
18 const char* kIsPreviewMetafileKey
= "CrIsPreviewMetafile";
21 void SetBoolMetaData(const SkCanvas
& canvas
, const char* key
, bool value
) {
22 SkMetaData
& meta
= skia::getMetaData(canvas
);
23 meta
.setBool(key
, value
);
26 bool GetBoolMetaData(const SkCanvas
& canvas
, const char* key
) {
28 SkMetaData
& meta
= skia::getMetaData(canvas
);
29 if (!meta
.findBool(key
, &value
))
36 void SetPlatformDevice(SkBaseDevice
* device
, PlatformDevice
* platform_behaviour
) {
37 SkMetaData
& meta_data
= device
->getMetaData();
38 meta_data
.setPtr(kDevicePlatformBehaviour
, platform_behaviour
);
41 PlatformDevice
* GetPlatformDevice(SkBaseDevice
* device
) {
43 SkMetaData
& meta_data
= device
->getMetaData();
44 PlatformDevice
* device_behaviour
= NULL
;
45 if (meta_data
.findPtr(kDevicePlatformBehaviour
,
46 reinterpret_cast<void**>(&device_behaviour
)))
47 return device_behaviour
;
52 SkMetaData
& getMetaData(const SkCanvas
& canvas
) {
53 SkBaseDevice
* device
= canvas
.getDevice();
54 DCHECK(device
!= NULL
);
55 return device
->getMetaData();
58 void SetIsDraftMode(const SkCanvas
& canvas
, bool draft_mode
) {
59 SetBoolMetaData(canvas
, kDraftModeKey
, draft_mode
);
62 bool IsDraftMode(const SkCanvas
& canvas
) {
63 return GetBoolMetaData(canvas
, kDraftModeKey
);
66 #if defined(OS_MACOSX) || defined(OS_WIN)
67 void SetIsPreviewMetafile(const SkCanvas
& canvas
, bool is_preview
) {
68 SetBoolMetaData(canvas
, kIsPreviewMetafileKey
, is_preview
);
71 bool IsPreviewMetafile(const SkCanvas
& canvas
) {
72 return GetBoolMetaData(canvas
, kIsPreviewMetafileKey
);
76 bool PlatformDevice::SupportsPlatformPaint() {