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