OLD | NEW |
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" |
(...skipping 20 matching lines...) Expand all Loading... |
47 } | 48 } |
48 SkShader::GradientType gtype = shader->asAGradient(NULL); | 49 SkShader::GradientType gtype = shader->asAGradient(NULL); |
49 if (gtype == SkShader::kLinear_GradientType || | 50 if (gtype == SkShader::kLinear_GradientType || |
50 gtype == SkShader::kRadial_GradientType || | 51 gtype == SkShader::kRadial_GradientType || |
51 gtype == SkShader::kSweep_GradientType) { | 52 gtype == SkShader::kSweep_GradientType) { |
52 return; | 53 return; |
53 } | 54 } |
54 paint->setShader(NULL); | 55 paint->setShader(NULL); |
55 } | 56 } |
56 | 57 |
57 /** | 58 /** 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 | 59 |
63 bool filter(SkPaint* paint, Type drawType) SK_OVERRIDE { | 60 void Filter(SkPaint* paint) { |
64 | 61 |
65 uint32_t flags = paint->getFlags(); | 62 uint32_t flags = paint->getFlags(); |
66 flags &= ~SkPaint::kLCDRenderText_Flag; | 63 flags &= ~SkPaint::kLCDRenderText_Flag; |
67 paint->setFlags(flags); | 64 paint->setFlags(flags); |
68 | 65 |
69 // Force bilinear scaling or none | 66 // Android doesn't support Xfermodes above kLighten_Mode |
70 if (paint->getFilterQuality() != kNone_SkFilterQuality) { | 67 SkXfermode::Mode mode; |
71 paint->setFilterQuality(kLow_SkFilterQuality); | 68 SkXfermode::AsMode(paint->getXfermode(), &mode); |
| 69 if (mode > SkXfermode::kLighten_Mode) { |
| 70 paint->setXfermode(NULL); |
| 71 } |
| 72 |
| 73 // Force bilinear scaling or none |
| 74 if (paint->getFilterQuality() != kNone_SkFilterQuality) { |
| 75 paint->setFilterQuality(kLow_SkFilterQuality); |
| 76 } |
| 77 |
| 78 CheckShader(paint); |
| 79 |
| 80 // Android SDK only supports mode & matrix color filters |
| 81 // (and, again, no modes above kLighten_Mode). |
| 82 SkColorFilter* cf = paint->getColorFilter(); |
| 83 if (cf) { |
| 84 SkColor color; |
| 85 SkXfermode::Mode mode; |
| 86 SkScalar srcColorMatrix[20]; |
| 87 bool isMode = cf->asColorMode(&color, &mode); |
| 88 if (isMode && mode > SkXfermode::kLighten_Mode) { |
| 89 paint->setColorFilter( |
| 90 SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcOver_Mode
)); |
| 91 } else if (!isMode && !cf->asColorMatrix(srcColorMatrix)) { |
| 92 paint->setColorFilter(NULL); |
72 } | 93 } |
| 94 } |
73 | 95 |
74 CheckShader(paint); | 96 SkPathEffect* pe = paint->getPathEffect(); |
| 97 if (pe && !pe->exposedInAndroidJavaAPI()) { |
| 98 paint->setPathEffect(NULL); |
| 99 } |
75 | 100 |
76 // Android SDK only supports mode & matrix color filters | 101 // TODO: Android doesn't support all the flags that can be passed to |
77 SkColorFilter* cf = paint->getColorFilter(); | 102 // 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 | 103 |
87 SkPathEffect* pe = paint->getPathEffect(); | 104 paint->setImageFilter(NULL); |
88 if (pe && !pe->exposedInAndroidJavaAPI()) { | 105 paint->setLooper(NULL); |
89 paint->setPathEffect(NULL); | 106 }; |
90 } | |
91 | 107 |
92 // TODO: Android doesn't support all the flags that can be passed to | 108 /** SkDrawFilter is likely to be deprecated; this is a proxy |
93 // blur filters; we need plumbing to get them out. | 109 canvas that does the same thing: alter SkPaint fields. |
94 | 110 |
95 paint->setImageFilter(NULL); | 111 onDraw*() functions may have their SkPaint modified, and are then |
96 paint->setLooper(NULL); | 112 passed on to the same function on proxyTarget. |
97 | 113 |
98 return true; | 114 This still suffers one of the same architectural flaws as SkDrawFilter: |
99 }; | 115 TextBlob paints are incomplete when filter is called. |
| 116 */ |
| 117 |
| 118 #define FILTER(p) \ |
| 119 SkPaint filteredPaint(p); \ |
| 120 Filter(&filteredPaint); |
| 121 |
| 122 #define FILTER_PTR(p) \ |
| 123 SkTLazy<SkPaint> lazyPaint; \ |
| 124 SkPaint* filteredPaint = (SkPaint*) p; \ |
| 125 if (p) { \ |
| 126 filteredPaint = lazyPaint.set(*p); \ |
| 127 Filter(filteredPaint); \ |
| 128 } |
| 129 |
| 130 |
| 131 class FilteringCanvas : public SkCanvas { |
| 132 public: |
| 133 FilteringCanvas(SkCanvas* proxyTarget) : fProxyTarget(proxyTarget) { } |
| 134 |
| 135 protected: |
| 136 void onDrawPaint(const SkPaint& paint) SK_OVERRIDE { |
| 137 FILTER(paint); |
| 138 fProxyTarget->drawPaint(filteredPaint); |
| 139 } |
| 140 void onDrawPoints(PointMode pMode, size_t count, const SkPoint pts[], |
| 141 const SkPaint& paint) SK_OVERRIDE { |
| 142 FILTER(paint); |
| 143 fProxyTarget->drawPoints(pMode, count, pts, filteredPaint); |
| 144 } |
| 145 void onDrawOval(const SkRect& r, const SkPaint& paint) SK_OVERRIDE { |
| 146 FILTER(paint); |
| 147 fProxyTarget->drawOval(r, filteredPaint); |
| 148 } |
| 149 void onDrawRect(const SkRect& r, const SkPaint& paint) SK_OVERRIDE { |
| 150 FILTER(paint); |
| 151 fProxyTarget->drawRect(r, filteredPaint); |
| 152 } |
| 153 void onDrawRRect(const SkRRect& r, const SkPaint& paint) SK_OVERRIDE { |
| 154 FILTER(paint); |
| 155 fProxyTarget->drawRRect(r, filteredPaint); |
| 156 } |
| 157 void onDrawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE { |
| 158 FILTER(paint); |
| 159 fProxyTarget->drawPath(path, filteredPaint); |
| 160 } |
| 161 void onDrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
| 162 const SkPaint* paint) SK_OVERRIDE { |
| 163 FILTER_PTR(paint); |
| 164 fProxyTarget->drawBitmap(bitmap, left, top, filteredPaint); |
| 165 } |
| 166 void onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRec
t& dst, |
| 167 const SkPaint* paint, DrawBitmapRectFlags flags) SK_OV
ERRIDE { |
| 168 FILTER_PTR(paint); |
| 169 fProxyTarget->drawBitmapRectToRect(bitmap, src, dst, filteredPaint, flag
s); |
| 170 } |
| 171 void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 172 const SkRect& dst, const SkPaint* paint) SK_OVERRIDE { |
| 173 FILTER_PTR(paint); |
| 174 fProxyTarget->drawBitmapNine(bitmap, center, dst, filteredPaint); |
| 175 } |
| 176 void onDrawSprite(const SkBitmap& bitmap, int left, int top, |
| 177 const SkPaint* paint) SK_OVERRIDE { |
| 178 FILTER_PTR(paint); |
| 179 fProxyTarget->drawSprite(bitmap, left, top, filteredPaint); |
| 180 } |
| 181 void onDrawVertices(VertexMode vMode, int vertexCount, const SkPoint vertice
s[], |
| 182 const SkPoint texs[], const SkColor colors[], SkXfermode
* xMode, |
| 183 const uint16_t indices[], int indexCount, |
| 184 const SkPaint& paint) SK_OVERRIDE { |
| 185 FILTER(paint); |
| 186 fProxyTarget->drawVertices(vMode, vertexCount, vertices, texs, colors, |
| 187 xMode, indices, indexCount, filteredPaint); |
| 188 } |
| 189 |
| 190 void onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 191 const SkPaint& paint) SK_OVERRIDE { |
| 192 FILTER(paint); |
| 193 fProxyTarget->drawDRRect(outer, inner, filteredPaint); |
| 194 } |
| 195 |
| 196 void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 197 const SkPaint& paint) SK_OVERRIDE { |
| 198 FILTER(paint); |
| 199 fProxyTarget->drawText(text, byteLength, x, y, filteredPaint); |
| 200 } |
| 201 void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 202 const SkPaint& paint) SK_OVERRIDE { |
| 203 FILTER(paint); |
| 204 fProxyTarget->drawPosText(text, byteLength, pos, filteredPaint); |
| 205 } |
| 206 void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos
[], |
| 207 SkScalar constY, const SkPaint& paint) SK_OVERRIDE { |
| 208 FILTER(paint); |
| 209 fProxyTarget->drawPosTextH(text, byteLength, xpos, constY, filteredPaint
); |
| 210 } |
| 211 void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& pat
h, |
| 212 const SkMatrix* matrix, const SkPaint& paint) SK_OVERR
IDE { |
| 213 FILTER(paint); |
| 214 fProxyTarget->drawTextOnPath(text, byteLength, path, matrix, filteredPai
nt); |
| 215 } |
| 216 void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 217 const SkPaint& paint) SK_OVERRIDE { |
| 218 FILTER(paint); |
| 219 fProxyTarget->drawTextBlob(blob, x, y, filteredPaint); |
| 220 } |
| 221 |
| 222 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 223 const SkPoint texCoords[4], SkXfermode* xmode, |
| 224 const SkPaint& paint) SK_OVERRIDE { |
| 225 FILTER(paint); |
| 226 fProxyTarget->drawPatch(cubics, colors, texCoords, xmode, filteredPaint)
; |
| 227 } |
| 228 |
| 229 protected: |
| 230 SkCanvas* fProxyTarget; |
100 }; | 231 }; |
101 | 232 |
102 /** | 233 /** |
103 * Helper class for setting up android::uirenderer::renderthread::RenderProxy. | 234 * Helper class for setting up android::uirenderer::renderthread::RenderProxy. |
104 */ | 235 */ |
105 class ContextFactory : public android::uirenderer::IContextFactory { | 236 class ContextFactory : public android::uirenderer::IContextFactory { |
106 public: | 237 public: |
107 android::uirenderer::AnimationContext* createAnimationContext | 238 android::uirenderer::AnimationContext* createAnimationContext |
108 (android::uirenderer::renderthread::TimeLord& clock) SK_OVERRIDE { | 239 (android::uirenderer::renderthread::TimeLord& clock) SK_OVERRIDE { |
109 return new android::uirenderer::AnimationContext(clock); | 240 return new android::uirenderer::AnimationContext(clock); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 Error ViaAndroidSDK::draw(const Src& src, | 373 Error ViaAndroidSDK::draw(const Src& src, |
243 SkBitmap* bitmap, | 374 SkBitmap* bitmap, |
244 SkWStream* stream, | 375 SkWStream* stream, |
245 SkString* log) const { | 376 SkString* log) const { |
246 struct ProxySrc : public Src { | 377 struct ProxySrc : public Src { |
247 const Src& fSrc; | 378 const Src& fSrc; |
248 ProxySrc(const Src& src) | 379 ProxySrc(const Src& src) |
249 : fSrc(src) {} | 380 : fSrc(src) {} |
250 | 381 |
251 Error draw(SkCanvas* canvas) const SK_OVERRIDE { | 382 Error draw(SkCanvas* canvas) const SK_OVERRIDE { |
252 // Route through HWUI's upper layers to get operational transforms | 383 // Pass through HWUI's upper layers to get operational transforms |
253 SkAutoTDelete<android::Canvas> ac (android::Canvas::create_canvas(ca
nvas)); | 384 SkAutoTDelete<android::Canvas> ac (android::Canvas::create_canvas(ca
nvas)); |
254 SkAutoTUnref<android::uirenderer::SkiaCanvasProxy> scProxy | 385 SkAutoTUnref<android::uirenderer::SkiaCanvasProxy> scProxy |
255 (new android::uirenderer::SkiaCanvasProxy(ac)); | 386 (new android::uirenderer::SkiaCanvasProxy(ac)); |
256 ViaAndroidSDKFilter filter; | |
257 | 387 |
258 // Route through a draw filter to get paint transforms | 388 // Pass through another proxy to get paint transforms |
259 scProxy->setDrawFilter(&filter); | 389 FilteringCanvas fc(scProxy); |
260 | 390 |
261 fSrc.draw(scProxy); | 391 fSrc.draw(&fc); |
262 | 392 |
263 return ""; | 393 return ""; |
264 } | 394 } |
265 SkISize size() const SK_OVERRIDE { return fSrc.size(); } | 395 SkISize size() const SK_OVERRIDE { return fSrc.size(); } |
266 Name name() const SK_OVERRIDE { sk_throw(); return ""; } | 396 Name name() const SK_OVERRIDE { sk_throw(); return ""; } |
267 } proxy(src); | 397 } proxy(src); |
268 | 398 |
269 return fSink->draw(proxy, bitmap, stream, log); | 399 return fSink->draw(proxy, bitmap, stream, log); |
270 } | 400 } |
271 | 401 |
272 } // namespace DM | 402 } // namespace DM |
OLD | NEW |