OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "skia/ext/platform_device.h" |
| 6 |
| 7 #include "third_party/skia/include/core/SkMetaData.h" |
| 8 |
| 9 namespace skia { |
| 10 |
| 11 namespace platform_util { |
| 12 |
| 13 namespace { |
| 14 const char* kDevicePlatformBehaviour = "CrDevicePlatformBehaviour"; |
| 15 } |
| 16 |
| 17 void SetPlatformDevice(SkDevice* device, PlatformDevice* platform_behaviour) { |
| 18 SkMetaData& meta_data = device->getMetaData(); |
| 19 meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); |
| 20 } |
| 21 |
| 22 PlatformDevice* GetPlatformDevice(SkDevice* device) { |
| 23 SkMetaData& meta_data = device->getMetaData(); |
| 24 PlatformDevice* device_behaviour = NULL; |
| 25 if (meta_data.findPtr(kDevicePlatformBehaviour, |
| 26 reinterpret_cast<void**>(&device_behaviour))) |
| 27 return device_behaviour; |
| 28 |
| 29 return NULL; |
| 30 } |
| 31 |
| 32 PlatformSurface BeginPlatformPaint(SkDevice* device) { |
| 33 PlatformDevice* platform_device = GetPlatformDevice(device); |
| 34 if (platform_device) |
| 35 return platform_device->BeginPlatformPaint(); |
| 36 |
| 37 return 0; |
| 38 } |
| 39 |
| 40 void EndPlatformPaint(SkDevice* device) { |
| 41 PlatformDevice* platform_device = GetPlatformDevice(device); |
| 42 if (platform_device) |
| 43 return platform_device->EndPlatformPaint(); |
| 44 } |
| 45 |
| 46 // Returns the color value at the specified location. |
| 47 SkColor GetColorAt(SkDevice* device, int x, int y) { |
| 48 const SkBitmap& bitmap = device->accessBitmap(false); |
| 49 SkAutoLockPixels lock(bitmap); |
| 50 uint32_t* data = bitmap.getAddr32(0, 0); |
| 51 return static_cast<SkColor>(data[x + y * device->width()]); |
| 52 } |
| 53 |
| 54 bool IsVectorial(SkDevice* device) { |
| 55 PlatformDevice* platform_device = GetPlatformDevice(device); |
| 56 if (platform_device) |
| 57 return platform_device->IsVectorial(); |
| 58 |
| 59 return device->getDeviceCapabilities() & SkDevice::kVector_Capability; |
| 60 } |
| 61 |
| 62 bool IsNativeFontRenderingAllowed(SkDevice* device) { |
| 63 PlatformDevice* platform_device = GetPlatformDevice(device); |
| 64 if (platform_device) |
| 65 return platform_device->IsNativeFontRenderingAllowed(); |
| 66 |
| 67 return false; |
| 68 } |
| 69 |
| 70 } // namespace platform_util |
| 71 |
| 72 } // namespace skia |
| 73 |
OLD | NEW |