Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: dm/DMSrcSinkAndroid.cpp

Issue 997183003: Proxy canvas instead of DrawFilter for Android DM (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix unintended extra patch Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "DMSrcSink.h" 8 #include "DMSrcSink.h"
9 #include "DMSrcSinkAndroid.h" 9 #include "DMSrcSinkAndroid.h"
10 10
11 #include "AnimationContext.h" 11 #include "AnimationContext.h"
12 #include "DisplayListRenderer.h" 12 #include "DisplayListRenderer.h"
13 #include "IContextFactory.h" 13 #include "IContextFactory.h"
14 #include "RenderNode.h" 14 #include "RenderNode.h"
15 #include "SkDrawFilter.h" 15 #include "SkCanvas.h"
16 #include "SkiaCanvasProxy.h" 16 #include "SkiaCanvasProxy.h"
17 #include "SkTLazy.h"
17 #include "SkMaskFilter.h" 18 #include "SkMaskFilter.h"
18 #include "SkPictureRecorder.h" 19 #include "SkPictureRecorder.h"
19 #include "SkStream.h" 20 #include "SkStream.h"
20 #include "android/rect.h" 21 #include "android/rect.h"
21 #include "android/native_window.h" 22 #include "android/native_window.h"
22 #include "gui/BufferQueue.h" 23 #include "gui/BufferQueue.h"
23 #include "gui/CpuConsumer.h" 24 #include "gui/CpuConsumer.h"
24 #include "gui/IGraphicBufferConsumer.h" 25 #include "gui/IGraphicBufferConsumer.h"
25 #include "gui/IGraphicBufferProducer.h" 26 #include "gui/IGraphicBufferProducer.h"
26 #include "gui/Surface.h" 27 #include "gui/Surface.h"
27 #include "renderthread/RenderProxy.h" 28 #include "renderthread/RenderProxy.h"
28 #include "renderthread/TimeLord.h" 29 #include "renderthread/TimeLord.h"
29 30
30 /* These functions are only compiled in the Android Framework. */ 31 /* These functions are only compiled in the Android Framework. */
31 32
32 namespace { 33 namespace {
33 34
35 typedef SkTLazy<SkPaint> SkLazyPaint;
djsollen 2015/03/11 19:02:27 don't see the need to typedef this for one instanc
36
34 /** Discard SkShaders not exposed by the Android Java API. */ 37 /** Discard SkShaders not exposed by the Android Java API. */
35 38
36 void CheckShader(SkPaint* paint) { 39 void CheckShader(SkPaint* paint) {
37 SkShader* shader = paint->getShader(); 40 SkShader* shader = paint->getShader();
38 if (!shader) { 41 if (!shader) {
39 return; 42 return;
40 } 43 }
41 44
42 if (shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefault_BitmapType) { 45 if (shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefault_BitmapType) {
43 return; 46 return;
44 } 47 }
45 if (shader->asACompose(NULL)) { 48 if (shader->asACompose(NULL)) {
46 return; 49 return;
47 } 50 }
48 SkShader::GradientType gtype = shader->asAGradient(NULL); 51 SkShader::GradientType gtype = shader->asAGradient(NULL);
49 if (gtype == SkShader::kLinear_GradientType || 52 if (gtype == SkShader::kLinear_GradientType ||
50 gtype == SkShader::kRadial_GradientType || 53 gtype == SkShader::kRadial_GradientType ||
51 gtype == SkShader::kSweep_GradientType) { 54 gtype == SkShader::kSweep_GradientType) {
52 return; 55 return;
53 } 56 }
54 paint->setShader(NULL); 57 paint->setShader(NULL);
55 } 58 }
56 59
57 /** 60 /** Simplify a paint. */
58 * An SkDrawFilter implementation which removes all flags and features
59 * not exposed by the Android SDK.
60 */
61 class ViaAndroidSDKFilter : public SkDrawFilter {
62 61
63 bool filter(SkPaint* paint, Type drawType) SK_OVERRIDE { 62 void Filter(SkPaint* paint) {
64 63
65 uint32_t flags = paint->getFlags(); 64 uint32_t flags = paint->getFlags();
66 flags &= ~SkPaint::kLCDRenderText_Flag; 65 flags &= ~SkPaint::kLCDRenderText_Flag;
67 paint->setFlags(flags); 66 paint->setFlags(flags);
68 67
69 // Force bilinear scaling or none 68 // Android doesn't support Xfermodes above kLighten_Mode
70 if (paint->getFilterQuality() != kNone_SkFilterQuality) { 69 SkXfermode::Mode mode;
71 paint->setFilterQuality(kLow_SkFilterQuality); 70 SkXfermode::AsMode(paint->getXfermode(), &mode);
71 if (mode > SkXfermode::kLighten_Mode) {
72 paint->setXfermode(NULL);
73 }
74
75 // Force bilinear scaling or none
76 if (paint->getFilterQuality() != kNone_SkFilterQuality) {
77 paint->setFilterQuality(kLow_SkFilterQuality);
78 }
79
80 CheckShader(paint);
81
82 // Android SDK only supports mode & matrix color filters
83 // (and, again, no modes above kLighten_Mode).
84 SkColorFilter* cf = paint->getColorFilter();
85 if (cf) {
86 SkColor color;
87 SkXfermode::Mode mode;
88 SkScalar srcColorMatrix[20];
89 bool isMode = cf->asColorMode(&color, &mode);
90 if (isMode && mode > SkXfermode::kLighten_Mode) {
91 paint->setColorFilter(
92 SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcOver_Mode ));
93 } else if (!isMode && !cf->asColorMatrix(srcColorMatrix)) {
94 paint->setColorFilter(NULL);
72 } 95 }
96 }
73 97
74 CheckShader(paint); 98 SkPathEffect* pe = paint->getPathEffect();
99 if (pe && !pe->exposedInAndroidJavaAPI()) {
100 paint->setPathEffect(NULL);
101 }
75 102
76 // Android SDK only supports mode & matrix color filters 103 // TODO: Android doesn't support all the flags that can be passed to
77 SkColorFilter* cf = paint->getColorFilter(); 104 // blur filters; we need plumbing to get them out.
78 if (cf) {
79 SkColor color;
80 SkXfermode::Mode mode;
81 SkScalar srcColorMatrix[20];
82 if (!cf->asColorMode(&color, &mode) && !cf->asColorMatrix(srcColorMa trix)) {
83 paint->setColorFilter(NULL);
84 }
85 }
86 105
87 SkPathEffect* pe = paint->getPathEffect(); 106 paint->setImageFilter(NULL);
88 if (pe && !pe->exposedInAndroidJavaAPI()) { 107 paint->setLooper(NULL);
89 paint->setPathEffect(NULL); 108 };
90 }
91 109
92 // TODO: Android doesn't support all the flags that can be passed to 110 /** SkDrawFilter is likely to be deprecated; this is a proxy
93 // blur filters; we need plumbing to get them out. 111 canvas that does the same thing: alter SkPaint fields.
94 112
95 paint->setImageFilter(NULL); 113 onDraw*() functions may have their SkPaint modified, and are then
96 paint->setLooper(NULL); 114 passed on to the same function on proxyTarget.
97 115
98 return true; 116 This still suffers one of the same architectural flaws as SkDrawFilter:
99 }; 117 TextBlob paints are incomplete when filter is called.
118 */
119
120 #define FILTER(p) \
121 SkPaint filteredPaint(p); \
122 Filter(&filteredPaint);
123
124 #define FILTER_PTR(p) \
125 SkLazyPaint lazyPaint; \
126 SkPaint* filteredPaint = (SkPaint*) p; \
127 if (p) { \
128 filteredPaint = lazyPaint.set(*p); \
129 Filter(filteredPaint); \
130 }
131
132
133 class FilteringCanvas : public SkCanvas {
134 public:
135 FilteringCanvas(SkCanvas* proxyTarget) : fProxyTarget(proxyTarget) { }
136
137 protected:
138 void onDrawPaint(const SkPaint& paint) SK_OVERRIDE {
139 FILTER(paint);
140 fProxyTarget->drawPaint(filteredPaint);
141 }
142 void onDrawPoints(PointMode pMode, size_t count, const SkPoint pts[],
143 const SkPaint& paint) SK_OVERRIDE {
144 FILTER(paint);
145 fProxyTarget->drawPoints(pMode, count, pts, filteredPaint);
146 }
147 void onDrawOval(const SkRect& r, const SkPaint& paint) SK_OVERRIDE {
148 FILTER(paint);
149 fProxyTarget->drawOval(r, filteredPaint);
150 }
151 void onDrawRect(const SkRect& r, const SkPaint& paint) SK_OVERRIDE {
152 FILTER(paint);
153 fProxyTarget->drawRect(r, filteredPaint);
154 }
155 void onDrawRRect(const SkRRect& r, const SkPaint& paint) SK_OVERRIDE {
156 FILTER(paint);
157 fProxyTarget->drawRRect(r, filteredPaint);
158 }
159 void onDrawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE {
160 FILTER(paint);
161 fProxyTarget->drawPath(path, filteredPaint);
162 }
163 void onDrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
164 const SkPaint* paint) SK_OVERRIDE {
165 FILTER_PTR(paint);
166 fProxyTarget->drawBitmap(bitmap, left, top, filteredPaint);
167 }
168 void onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRec t& dst,
169 const SkPaint* paint, DrawBitmapRectFlags flags) SK_OV ERRIDE {
170 FILTER_PTR(paint);
171 fProxyTarget->drawBitmapRectToRect(bitmap, src, dst, filteredPaint, flag s);
172 }
173 void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
174 const SkRect& dst, const SkPaint* paint) SK_OVERRIDE {
175 FILTER_PTR(paint);
176 fProxyTarget->drawBitmapNine(bitmap, center, dst, filteredPaint);
177 }
178 void onDrawSprite(const SkBitmap& bitmap, int left, int top,
179 const SkPaint* paint) SK_OVERRIDE {
180 FILTER_PTR(paint);
181 fProxyTarget->drawSprite(bitmap, left, top, filteredPaint);
182 }
183 void onDrawVertices(VertexMode vMode, int vertexCount, const SkPoint vertice s[],
184 const SkPoint texs[], const SkColor colors[], SkXfermode * xMode,
185 const uint16_t indices[], int indexCount,
186 const SkPaint& paint) SK_OVERRIDE {
187 FILTER(paint);
188 fProxyTarget->drawVertices(vMode, vertexCount, vertices, texs, colors,
189 xMode, indices, indexCount, filteredPaint);
190 }
191
192 void onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
193 const SkPaint& paint) SK_OVERRIDE {
194 FILTER(paint);
195 fProxyTarget->drawDRRect(outer, inner, filteredPaint);
196 }
197
198 void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
199 const SkPaint& paint) SK_OVERRIDE {
200 FILTER(paint);
201 fProxyTarget->drawText(text, byteLength, x, y, filteredPaint);
202 }
203 void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
204 const SkPaint& paint) SK_OVERRIDE {
205 FILTER(paint);
206 fProxyTarget->drawPosText(text, byteLength, pos, filteredPaint);
207 }
208 void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos [],
209 SkScalar constY, const SkPaint& paint) SK_OVERRIDE {
210 FILTER(paint);
211 fProxyTarget->drawPosTextH(text, byteLength, xpos, constY, filteredPaint );
212 }
213 void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& pat h,
214 const SkMatrix* matrix, const SkPaint& paint) SK_OVERR IDE {
215 FILTER(paint);
216 fProxyTarget->drawTextOnPath(text, byteLength, path, matrix, filteredPai nt);
217 }
218 void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
219 const SkPaint& paint) SK_OVERRIDE {
220 FILTER(paint);
221 fProxyTarget->drawTextBlob(blob, x, y, filteredPaint);
222 }
223
224 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
225 const SkPoint texCoords[4], SkXfermode* xmode,
226 const SkPaint& paint) SK_OVERRIDE {
227 FILTER(paint);
228 fProxyTarget->drawPatch(cubics, colors, texCoords, xmode, filteredPaint) ;
229 }
230
231 protected:
232 SkCanvas* fProxyTarget;
100 }; 233 };
101 234
102 /** 235 /**
103 * Helper class for setting up android::uirenderer::renderthread::RenderProxy. 236 * Helper class for setting up android::uirenderer::renderthread::RenderProxy.
104 */ 237 */
105 class ContextFactory : public android::uirenderer::IContextFactory { 238 class ContextFactory : public android::uirenderer::IContextFactory {
106 public: 239 public:
107 android::uirenderer::AnimationContext* createAnimationContext 240 android::uirenderer::AnimationContext* createAnimationContext
108 (android::uirenderer::renderthread::TimeLord& clock) SK_OVERRIDE { 241 (android::uirenderer::renderthread::TimeLord& clock) SK_OVERRIDE {
109 return new android::uirenderer::AnimationContext(clock); 242 return new android::uirenderer::AnimationContext(clock);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 Error ViaAndroidSDK::draw(const Src& src, 375 Error ViaAndroidSDK::draw(const Src& src,
243 SkBitmap* bitmap, 376 SkBitmap* bitmap,
244 SkWStream* stream, 377 SkWStream* stream,
245 SkString* log) const { 378 SkString* log) const {
246 struct ProxySrc : public Src { 379 struct ProxySrc : public Src {
247 const Src& fSrc; 380 const Src& fSrc;
248 ProxySrc(const Src& src) 381 ProxySrc(const Src& src)
249 : fSrc(src) {} 382 : fSrc(src) {}
250 383
251 Error draw(SkCanvas* canvas) const SK_OVERRIDE { 384 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
252 // Route through HWUI's upper layers to get operational transforms 385 // Pass through HWUI's upper layers to get operational transforms
253 SkAutoTDelete<android::Canvas> ac (android::Canvas::create_canvas(ca nvas)); 386 SkAutoTDelete<android::Canvas> ac (android::Canvas::create_canvas(ca nvas));
254 SkAutoTUnref<android::uirenderer::SkiaCanvasProxy> scProxy 387 SkAutoTUnref<android::uirenderer::SkiaCanvasProxy> scProxy
255 (new android::uirenderer::SkiaCanvasProxy(ac)); 388 (new android::uirenderer::SkiaCanvasProxy(ac));
256 ViaAndroidSDKFilter filter;
257 389
258 // Route through a draw filter to get paint transforms 390 // Pass through another proxy to get paint transforms
259 scProxy->setDrawFilter(&filter); 391 FilteringCanvas fc(scProxy);
260 392
261 fSrc.draw(scProxy); 393 fSrc.draw(&fc);
262 394
263 return ""; 395 return "";
264 } 396 }
265 SkISize size() const SK_OVERRIDE { return fSrc.size(); } 397 SkISize size() const SK_OVERRIDE { return fSrc.size(); }
266 Name name() const SK_OVERRIDE { sk_throw(); return ""; } 398 Name name() const SK_OVERRIDE { sk_throw(); return ""; }
267 } proxy(src); 399 } proxy(src);
268 400
269 return fSink->draw(proxy, bitmap, stream, log); 401 return fSink->draw(proxy, bitmap, stream, log);
270 } 402 }
271 403
272 } // namespace DM 404 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698