| 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 |
| 33 if (transfer_ownership) { |
| 34 meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour, |
| 35 PlatformDevicePtrProc); |
| 36 } else { |
| 37 meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); |
| 38 } |
| 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 |
| 30 } // namespace skia | 51 } // namespace skia |
| 31 | 52 |
| OLD | NEW |