OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "skia/ext/platform_device.h" | 6 #include "skia/ext/platform_device.h" |
7 | 7 |
8 #include "third_party/skia/include/core/SkMetaData.h" | 8 #include "third_party/skia/include/core/SkMetaData.h" |
9 | 9 |
10 namespace skia { | |
11 | |
12 namespace { | 10 namespace { |
13 | 11 |
14 const char kDevicePlatformBehaviour[] = "CrDevicePlatformBehaviour"; | 12 const char kDevicePlatformBehaviour[] = "CrDevicePlatformBehaviour"; |
15 | 13 |
16 #if defined(OS_MACOSX) | |
17 const char kIsPreviewMetafileKey[] = "CrIsPreviewMetafile"; | |
18 | |
19 void SetBoolMetaData(const SkCanvas& canvas, const char* key, bool value) { | |
20 SkMetaData& meta = skia::getMetaData(canvas); | |
21 meta.setBool(key, value); | |
22 } | |
23 | |
24 bool GetBoolMetaData(const SkCanvas& canvas, const char* key) { | |
25 bool value; | |
26 SkMetaData& meta = skia::getMetaData(canvas); | |
27 if (!meta.findBool(key, &value)) | |
28 value = false; | |
29 return value; | |
30 } | |
31 #endif | |
32 | |
33 } // namespace | 14 } // namespace |
34 | 15 |
35 void SetPlatformDevice(SkBaseDevice* device, | 16 namespace skia { |
36 PlatformDevice* platform_behaviour) { | 17 |
| 18 void SetPlatformDevice(SkBaseDevice* device, PlatformDevice* platform_behaviour)
{ |
37 SkMetaData& meta_data = device->getMetaData(); | 19 SkMetaData& meta_data = device->getMetaData(); |
38 meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); | 20 meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); |
39 } | 21 } |
40 | 22 |
41 PlatformDevice* GetPlatformDevice(SkBaseDevice* device) { | 23 PlatformDevice* GetPlatformDevice(SkBaseDevice* device) { |
42 if (device) { | 24 if (device) { |
43 SkMetaData& meta_data = device->getMetaData(); | 25 SkMetaData& meta_data = device->getMetaData(); |
44 PlatformDevice* device_behaviour = NULL; | 26 PlatformDevice* device_behaviour = NULL; |
45 if (meta_data.findPtr(kDevicePlatformBehaviour, | 27 if (meta_data.findPtr(kDevicePlatformBehaviour, |
46 reinterpret_cast<void**>(&device_behaviour))) | 28 reinterpret_cast<void**>(&device_behaviour))) |
47 return device_behaviour; | 29 return device_behaviour; |
48 } | 30 } |
49 return NULL; | 31 return NULL; |
50 } | 32 } |
51 | 33 |
52 SkMetaData& getMetaData(const SkCanvas& canvas) { | |
53 SkBaseDevice* device = canvas.getDevice(); | |
54 DCHECK(device != NULL); | |
55 return device->getMetaData(); | |
56 } | |
57 | |
58 #if defined(OS_MACOSX) | |
59 void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) { | |
60 SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview); | |
61 } | |
62 | |
63 bool IsPreviewMetafile(const SkCanvas& canvas) { | |
64 return GetBoolMetaData(canvas, kIsPreviewMetafileKey); | |
65 } | |
66 #endif | |
67 | |
68 bool PlatformDevice::SupportsPlatformPaint() { | 34 bool PlatformDevice::SupportsPlatformPaint() { |
69 return true; | 35 return true; |
70 } | 36 } |
71 | 37 |
72 } // namespace skia | 38 } // namespace skia |
OLD | NEW |