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 "skia/ext/platform_device.h" | 5 #include "skia/ext/platform_device.h" |
6 | 6 |
7 #include "third_party/skia/include/core/SkMetaData.h" | 7 #include "third_party/skia/include/core/SkMetaData.h" |
8 | 8 |
9 namespace skia { | 9 namespace skia { |
10 | 10 |
11 namespace { | 11 namespace { |
| 12 |
12 const char* kDevicePlatformBehaviour = "CrDevicePlatformBehaviour"; | 13 const char* kDevicePlatformBehaviour = "CrDevicePlatformBehaviour"; |
| 14 |
| 15 void* PlatformDevicePtrProc(void* ptr, bool doRef) { |
| 16 SkASSERT(ptr); |
| 17 PlatformDevice* platform_device = reinterpret_cast<PlatformDevice*>(ptr); |
| 18 |
| 19 if (!doRef) { |
| 20 delete platform_device; |
| 21 return NULL; |
| 22 } |
| 23 |
| 24 return ptr; |
13 } | 25 } |
14 | 26 |
15 void SetPlatformDevice(SkDevice* device, PlatformDevice* platform_behaviour) { | 27 } |
| 28 |
| 29 void SetPlatformDevice(SkDevice* device, PlatformDevice* platform_behaviour, |
| 30 bool transfer_ownership) { |
16 SkMetaData& meta_data = device->getMetaData(); | 31 SkMetaData& meta_data = device->getMetaData(); |
17 meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); | 32 if (transfer_ownership) { |
| 33 meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour, |
| 34 PlatformDevicePtrProc); |
| 35 } else { |
| 36 meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); |
| 37 } |
18 } | 38 } |
19 | 39 |
20 PlatformDevice* GetPlatformDevice(SkDevice* device) { | 40 PlatformDevice* GetPlatformDevice(SkDevice* device) { |
21 SkMetaData& meta_data = device->getMetaData(); | 41 SkMetaData& meta_data = device->getMetaData(); |
22 PlatformDevice* device_behaviour = NULL; | 42 PlatformDevice* device_behaviour = NULL; |
23 if (meta_data.findPtr(kDevicePlatformBehaviour, | 43 if (meta_data.findPtr(kDevicePlatformBehaviour, |
24 reinterpret_cast<void**>(&device_behaviour))) | 44 reinterpret_cast<void**>(&device_behaviour))) |
25 return device_behaviour; | 45 return device_behaviour; |
26 | 46 |
27 return NULL; | 47 return NULL; |
28 } | 48 } |
29 | 49 |
30 } // namespace skia | 50 } // namespace skia |
31 | 51 |
OLD | NEW |