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 "skia/ext/platform_device.h" | 6 #include "skia/ext/platform_device.h" |
6 | 7 |
7 #include "third_party/skia/include/core/SkMetaData.h" | 8 #include "third_party/skia/include/core/SkMetaData.h" |
8 | 9 |
9 namespace skia { | 10 namespace skia { |
10 | 11 |
11 namespace { | 12 namespace { |
13 | |
12 const char* kDevicePlatformBehaviour = "CrDevicePlatformBehaviour"; | 14 const char* kDevicePlatformBehaviour = "CrDevicePlatformBehaviour"; |
15 const char* kDraftModeKey = "CrDraftMode"; | |
16 | |
17 #if defined(OS_MACOSX) || defined(OS_WIN) | |
18 const char* kIsPreviewMetafileKey = "CrIsPreviewMetafile"; | |
19 #endif | |
20 | |
21 void SetBoolMetaData(const SkCanvas* canvas, const char* key, bool value) { | |
22 SkMetaData& meta = skia::getMetaData(canvas); | |
23 meta.setBool(key, value); | |
13 } | 24 } |
14 | 25 |
26 bool GetBoolMetaData(const SkCanvas* canvas, const char* key) { | |
27 bool value; | |
28 SkMetaData& meta = skia::getMetaData(canvas); | |
29 if (!meta.findBool(key, &value)) | |
30 value = false; | |
31 return value; | |
32 } | |
33 | |
34 } // namespace | |
35 | |
15 void SetPlatformDevice(SkDevice* device, PlatformDevice* platform_behaviour) { | 36 void SetPlatformDevice(SkDevice* device, PlatformDevice* platform_behaviour) { |
16 SkMetaData& meta_data = device->getMetaData(); | 37 SkMetaData& meta_data = device->getMetaData(); |
17 meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); | 38 meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); |
18 } | 39 } |
19 | 40 |
20 PlatformDevice* GetPlatformDevice(SkDevice* device) { | 41 PlatformDevice* GetPlatformDevice(SkDevice* device) { |
21 SkMetaData& meta_data = device->getMetaData(); | 42 SkMetaData& meta_data = device->getMetaData(); |
22 PlatformDevice* device_behaviour = NULL; | 43 PlatformDevice* device_behaviour = NULL; |
23 if (meta_data.findPtr(kDevicePlatformBehaviour, | 44 if (meta_data.findPtr(kDevicePlatformBehaviour, |
24 reinterpret_cast<void**>(&device_behaviour))) | 45 reinterpret_cast<void**>(&device_behaviour))) |
25 return device_behaviour; | 46 return device_behaviour; |
26 | 47 |
27 return NULL; | 48 return NULL; |
28 } | 49 } |
29 | 50 |
51 SkMetaData& getMetaData(const SkCanvas* canvas) { | |
52 DCHECK(canvas != NULL); | |
53 | |
vandebo (ex-Chrome)
2011/09/27 16:49:00
nit: extra line
kmadhusu
2011/09/27 18:15:01
Done.
| |
54 SkDevice* device = canvas->getDevice(); | |
55 DCHECK(device != NULL); | |
56 return device->getMetaData(); | |
57 } | |
58 | |
59 void SetIsDraftMode(const SkCanvas* canvas, bool draft_mode) { | |
60 SetBoolMetaData(canvas, kDraftModeKey, draft_mode); | |
61 } | |
62 | |
63 bool IsDraftMode(const SkCanvas* canvas) { | |
64 return GetBoolMetaData(canvas, kDraftModeKey); | |
65 } | |
66 | |
67 #if defined(OS_MACOSX) || defined(OS_WIN) | |
68 void SetIsPreviewMetafile(const SkCanvas* canvas, bool is_preview) { | |
69 SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview); | |
70 } | |
71 | |
72 bool IsPreviewMetafile(const SkCanvas* canvas) { | |
73 return GetBoolMetaData(canvas, kIsPreviewMetafileKey); | |
74 } | |
75 #endif | |
76 | |
30 bool PlatformDevice::IsNativeFontRenderingAllowed() { | 77 bool PlatformDevice::IsNativeFontRenderingAllowed() { |
31 return true; | 78 return true; |
32 } | 79 } |
33 | 80 |
34 bool PlatformDevice::AlphaBlendUsed() const { | 81 bool PlatformDevice::AlphaBlendUsed() const { |
35 return false; | 82 return false; |
36 } | 83 } |
37 | 84 |
38 } // namespace skia | 85 } // namespace skia |
OLD | NEW |