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 "base/logging.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "skia/ext/platform_device.h" | 9 #include "skia/ext/platform_device.h" |
10 #include "third_party/skia/include/core/SkMetaData.h" | 10 #include "third_party/skia/include/core/SkMetaData.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 if (!meta.findBool(key, &value)) | 26 if (!meta.findBool(key, &value)) |
27 value = false; | 27 value = false; |
28 return value; | 28 return value; |
29 } | 29 } |
30 #endif | 30 #endif |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 namespace skia { | 34 namespace skia { |
35 | 35 |
36 SkBaseDevice* GetTopDevice(const SkCanvas& canvas) { | |
37 return canvas.getTopDevice(true); | |
38 } | |
39 | |
40 SkBitmap ReadPixels(SkCanvas* canvas) { | 36 SkBitmap ReadPixels(SkCanvas* canvas) { |
41 SkBitmap bitmap; | 37 SkBitmap bitmap; |
42 bitmap.setInfo(canvas->imageInfo()); | 38 bitmap.setInfo(canvas->imageInfo()); |
43 canvas->readPixels(&bitmap, 0, 0); | 39 canvas->readPixels(&bitmap, 0, 0); |
44 return bitmap; | 40 return bitmap; |
45 } | 41 } |
46 | 42 |
47 bool GetWritablePixels(SkCanvas* canvas, SkPixmap* result) { | 43 bool GetWritablePixels(SkCanvas* canvas, SkPixmap* result) { |
48 if (!canvas || !result) { | 44 if (!canvas || !result) { |
49 return false; | 45 return false; |
50 } | 46 } |
51 | 47 |
52 SkImageInfo info; | 48 SkImageInfo info; |
53 size_t row_bytes; | 49 size_t row_bytes; |
54 void* pixels = canvas->accessTopLayerPixels(&info, &row_bytes); | 50 void* pixels = canvas->accessTopLayerPixels(&info, &row_bytes); |
55 if (!pixels) { | 51 if (!pixels) { |
56 result->reset(); | 52 result->reset(); |
57 return false; | 53 return false; |
58 } | 54 } |
59 | 55 |
60 result->reset(info, pixels, row_bytes); | 56 result->reset(info, pixels, row_bytes); |
61 return true; | 57 return true; |
62 } | 58 } |
63 | 59 |
64 bool SupportsPlatformPaint(const SkCanvas* canvas) { | 60 bool SupportsPlatformPaint(const SkCanvas* canvas) { |
65 return GetPlatformDevice(GetTopDevice(*canvas)) != nullptr; | 61 return GetPlatformDevice(canvas->getTopDevice(true)) != nullptr; |
66 } | 62 } |
67 | 63 |
68 size_t PlatformCanvasStrideForWidth(unsigned width) { | 64 size_t PlatformCanvasStrideForWidth(unsigned width) { |
69 return 4 * width; | 65 return 4 * width; |
70 } | 66 } |
71 | 67 |
72 SkCanvas* CreateCanvas(const sk_sp<SkBaseDevice>& device, | 68 SkCanvas* CreateCanvas(const sk_sp<SkBaseDevice>& device, |
73 OnFailureType failureType) { | 69 OnFailureType failureType) { |
74 if (!device) { | 70 if (!device) { |
75 if (CRASH_ON_FAILURE == failureType) | 71 if (CRASH_ON_FAILURE == failureType) |
(...skipping 12 matching lines...) Expand all Loading... |
88 #if defined(OS_MACOSX) | 84 #if defined(OS_MACOSX) |
89 void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) { | 85 void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) { |
90 SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview); | 86 SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview); |
91 } | 87 } |
92 | 88 |
93 bool IsPreviewMetafile(const SkCanvas& canvas) { | 89 bool IsPreviewMetafile(const SkCanvas& canvas) { |
94 return GetBoolMetaData(canvas, kIsPreviewMetafileKey); | 90 return GetBoolMetaData(canvas, kIsPreviewMetafileKey); |
95 } | 91 } |
96 | 92 |
97 CGContextRef GetBitmapContext(const SkCanvas& canvas) { | 93 CGContextRef GetBitmapContext(const SkCanvas& canvas) { |
98 SkBaseDevice* device = GetTopDevice(canvas); | 94 PlatformDevice* platform_device = |
99 PlatformDevice* platform_device = GetPlatformDevice(device); | 95 GetPlatformDevice(canvas.getTopDevice(true)); |
100 SkIRect clip_bounds; | 96 SkIRect clip_bounds; |
101 canvas.getClipDeviceBounds(&clip_bounds); | 97 canvas.getClipDeviceBounds(&clip_bounds); |
102 return platform_device ? | 98 return platform_device ? |
103 platform_device->GetBitmapContext( | 99 platform_device->GetBitmapContext( |
104 canvas.getTotalMatrix(), clip_bounds) : | 100 canvas.getTotalMatrix(), clip_bounds) : |
105 nullptr; | 101 nullptr; |
106 } | 102 } |
107 | 103 |
108 #endif | 104 #endif |
109 | 105 |
110 ScopedPlatformPaint::ScopedPlatformPaint(SkCanvas* canvas) : | 106 ScopedPlatformPaint::ScopedPlatformPaint(SkCanvas* canvas) : |
111 canvas_(canvas), | 107 canvas_(canvas), |
112 platform_surface_(nullptr) { | 108 platform_surface_(nullptr) { |
113 // TODO(tomhudson) we're assuming non-null canvas? | 109 // TODO(tomhudson) we're assuming non-null canvas? |
114 PlatformDevice* platform_device = GetPlatformDevice(GetTopDevice(*canvas)); | 110 PlatformDevice* platform_device = GetPlatformDevice(canvas->getTopDevice(true)
); |
115 if (platform_device) { | 111 if (platform_device) { |
116 // Compensate for drawing to a layer rather than the entire canvas | 112 // Compensate for drawing to a layer rather than the entire canvas |
117 SkMatrix ctm; | 113 SkMatrix ctm; |
118 SkIRect clip_bounds; | 114 SkIRect clip_bounds; |
119 canvas->temporary_internal_describeTopLayer(&ctm, &clip_bounds); | 115 canvas->temporary_internal_describeTopLayer(&ctm, &clip_bounds); |
120 platform_surface_ = platform_device->BeginPlatformPaint(ctm, clip_bounds); | 116 platform_surface_ = platform_device->BeginPlatformPaint(ctm, clip_bounds); |
121 } | 117 } |
122 } | 118 } |
123 | 119 |
124 } // namespace skia | 120 } // namespace skia |
OLD | NEW |