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" | |
f(malita)
2015/11/24 23:13:23
Is this needed/used?
Tom Hudson
2015/11/25 15:50:35
Yeah, we're getting DCHECK from there. We could mi
f(malita)
2015/11/25 20:33:04
Ah, got you. DCHECK is fine.
| |
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 NULL; |
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 != NULL); | |
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 SK_API CGContextRef GetBitmapContext(const SkCanvas& canvas) { | |
f(malita)
2015/11/24 23:13:23
I don't think we need SK_API here.
Tom Hudson
2015/11/25 15:50:35
I think we do, see header file for the 5 invocatio
f(malita)
2015/11/25 20:33:04
Hmm, how about SetIsPreviewMetafile & IsPreviewMet
Tom Hudson
2015/11/30 16:14:42
D'oh, yes. Done.
| |
125 SkBaseDevice* device = GetTopDevice(canvas); | |
126 PlatformDevice* platform_device = GetPlatformDevice(device); | |
127 if (platform_device) | |
128 return platform_device->GetBitmapContext(); | |
129 | |
130 return NULL; | |
f(malita)
2015/11/24 23:13:23
Nit: nullptr?
Nit^2: maybe
return platform_dev
Tom Hudson
2015/11/25 15:50:35
Done.
Also changed other NULLs in this file to nu
| |
131 | |
132 } | |
133 | |
134 #endif | |
135 | |
136 | |
85 } // namespace skia | 137 } // namespace skia |
OLD | NEW |