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_canvas.h" | 5 #include "skia/ext/platform_canvas.h" |
6 | 6 |
| 7 #include "base/logging.h" |
7 #include "skia/ext/bitmap_platform_device.h" | 8 #include "skia/ext/bitmap_platform_device.h" |
| 9 #include "skia/ext/platform_device.h" |
| 10 #include "third_party/skia/include/core/SkMetaData.h" |
8 #include "third_party/skia/include/core/SkTypes.h" | 11 #include "third_party/skia/include/core/SkTypes.h" |
9 | 12 |
| 13 namespace { |
| 14 |
| 15 #if defined(OS_MACOSX) |
| 16 const char kIsPreviewMetafileKey[] = "CrIsPreviewMetafile"; |
| 17 #endif |
| 18 |
| 19 void SetBoolMetaData(const SkCanvas& canvas, const char* key, bool value) { |
| 20 SkMetaData& meta = skia::GetMetaData(canvas); |
| 21 meta.setBool(key, value); |
| 22 } |
| 23 |
| 24 bool GetBoolMetaData(const SkCanvas& canvas, const char* key) { |
| 25 bool value; |
| 26 SkMetaData& meta = skia::GetMetaData(canvas); |
| 27 if (!meta.findBool(key, &value)) |
| 28 value = false; |
| 29 return value; |
| 30 } |
| 31 |
| 32 } // namespace |
| 33 |
10 namespace skia { | 34 namespace skia { |
11 | 35 |
12 SkBaseDevice* GetTopDevice(const SkCanvas& canvas) { | 36 SkBaseDevice* GetTopDevice(const SkCanvas& canvas) { |
13 return canvas.getTopDevice(true); | 37 return canvas.getTopDevice(true); |
14 } | 38 } |
15 | 39 |
16 SkBitmap ReadPixels(SkCanvas* canvas) { | 40 SkBitmap ReadPixels(SkCanvas* canvas) { |
17 SkBitmap bitmap; | 41 SkBitmap bitmap; |
18 bitmap.setInfo(canvas->imageInfo()); | 42 bitmap.setInfo(canvas->imageInfo()); |
19 canvas->readPixels(&bitmap, 0, 0); | 43 canvas->readPixels(&bitmap, 0, 0); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 94 } |
71 | 95 |
72 size_t PlatformCanvasStrideForWidth(unsigned width) { | 96 size_t PlatformCanvasStrideForWidth(unsigned width) { |
73 return 4 * width; | 97 return 4 * width; |
74 } | 98 } |
75 | 99 |
76 SkCanvas* CreateCanvas(const skia::RefPtr<SkBaseDevice>& device, OnFailureType f
ailureType) { | 100 SkCanvas* CreateCanvas(const skia::RefPtr<SkBaseDevice>& device, OnFailureType f
ailureType) { |
77 if (!device) { | 101 if (!device) { |
78 if (CRASH_ON_FAILURE == failureType) | 102 if (CRASH_ON_FAILURE == failureType) |
79 SK_CRASH(); | 103 SK_CRASH(); |
80 return NULL; | 104 return nullptr; |
81 } | 105 } |
82 return new SkCanvas(device.get()); | 106 return new SkCanvas(device.get()); |
83 } | 107 } |
84 | 108 |
| 109 SkMetaData& GetMetaData(const SkCanvas& canvas) { |
| 110 SkBaseDevice* device = canvas.getDevice(); |
| 111 DCHECK(device != nullptr); |
| 112 return device->getMetaData(); |
| 113 } |
| 114 |
| 115 #if defined(OS_MACOSX) |
| 116 void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) { |
| 117 SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview); |
| 118 } |
| 119 |
| 120 bool IsPreviewMetafile(const SkCanvas& canvas) { |
| 121 return GetBoolMetaData(canvas, kIsPreviewMetafileKey); |
| 122 } |
| 123 |
| 124 CGContextRef GetBitmapContext(const SkCanvas& canvas) { |
| 125 SkBaseDevice* device = GetTopDevice(canvas); |
| 126 PlatformDevice* platform_device = GetPlatformDevice(device); |
| 127 return platform_device ? platform_device->GetBitmapContext() : |
| 128 nullptr; |
| 129 } |
| 130 |
| 131 #endif |
| 132 |
| 133 |
85 } // namespace skia | 134 } // namespace skia |
OLD | NEW |