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" |
| 16 #include "SkiaCanvasProxy.h" |
| 17 #include "SkMaskFilter.h" |
| 18 #include "SkPictureRecorder.h" |
| 19 #include "SkStream.h" |
15 #include "android/rect.h" | 20 #include "android/rect.h" |
16 #include "android/native_window.h" | 21 #include "android/native_window.h" |
17 #include "gui/BufferQueue.h" | 22 #include "gui/BufferQueue.h" |
18 #include "gui/CpuConsumer.h" | 23 #include "gui/CpuConsumer.h" |
19 #include "gui/IGraphicBufferConsumer.h" | 24 #include "gui/IGraphicBufferConsumer.h" |
20 #include "gui/IGraphicBufferProducer.h" | 25 #include "gui/IGraphicBufferProducer.h" |
21 #include "gui/Surface.h" | 26 #include "gui/Surface.h" |
22 #include "renderthread/RenderProxy.h" | 27 #include "renderthread/RenderProxy.h" |
23 #include "renderthread/TimeLord.h" | 28 #include "renderthread/TimeLord.h" |
24 | 29 |
25 namespace DM { | |
26 | |
27 /* These functions are only compiled in the Android Framework. */ | 30 /* These functions are only compiled in the Android Framework. */ |
28 | 31 |
| 32 namespace { |
| 33 |
| 34 /** Discard SkShaders not exposed by the Android Java API. */ |
| 35 |
| 36 void CheckShader(SkPaint* paint) { |
| 37 SkShader* shader = paint->getShader(); |
| 38 if (!shader) { |
| 39 return; |
| 40 } |
| 41 |
| 42 if (shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefault_BitmapType) { |
| 43 return; |
| 44 } |
| 45 if (shader->asACompose(NULL)) { |
| 46 return; |
| 47 } |
| 48 SkShader::GradientType gtype = shader->asAGradient(NULL); |
| 49 if (gtype == SkShader::kLinear_GradientType || |
| 50 gtype == SkShader::kRadial_GradientType || |
| 51 gtype == SkShader::kSweep_GradientType) { |
| 52 return; |
| 53 } |
| 54 paint->setShader(NULL); |
| 55 } |
| 56 |
| 57 /** |
| 58 * An SkDrawFilter implementation which removes all flags and features |
| 59 * not exposed by the Android SDK. |
| 60 */ |
| 61 class ViaAndroidSDKFilter : public SkDrawFilter { |
| 62 |
| 63 bool filter(SkPaint* paint, Type drawType) SK_OVERRIDE { |
| 64 |
| 65 uint32_t flags = paint->getFlags(); |
| 66 flags &= ~SkPaint::kLCDRenderText_Flag; |
| 67 paint->setFlags(flags); |
| 68 |
| 69 // Force bilinear scaling or none |
| 70 if (paint->getFilterQuality() != kNone_SkFilterQuality) { |
| 71 paint->setFilterQuality(kLow_SkFilterQuality); |
| 72 } |
| 73 |
| 74 CheckShader(paint); |
| 75 |
| 76 // Android SDK only supports mode & matrix color filters |
| 77 SkColorFilter* cf = paint->getColorFilter(); |
| 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 |
| 87 SkPathEffect* pe = paint->getPathEffect(); |
| 88 if (pe && !pe->exposedInAndroidJavaAPI()) { |
| 89 paint->setPathEffect(NULL); |
| 90 } |
| 91 |
| 92 // TODO: Android doesn't support all the flags that can be passed to |
| 93 // blur filters; we need plumbing to get them out. |
| 94 |
| 95 paint->setImageFilter(NULL); |
| 96 paint->setLooper(NULL); |
| 97 |
| 98 return true; |
| 99 }; |
| 100 }; |
| 101 |
| 102 /** |
| 103 * Helper class for setting up android::uirenderer::renderthread::RenderProxy. |
| 104 */ |
29 class ContextFactory : public android::uirenderer::IContextFactory { | 105 class ContextFactory : public android::uirenderer::IContextFactory { |
30 public: | 106 public: |
31 android::uirenderer::AnimationContext* createAnimationContext | 107 android::uirenderer::AnimationContext* createAnimationContext |
32 (android::uirenderer::renderthread::TimeLord& clock) SK_OVERRIDE { | 108 (android::uirenderer::renderthread::TimeLord& clock) SK_OVERRIDE { |
33 return new android::uirenderer::AnimationContext(clock); | 109 return new android::uirenderer::AnimationContext(clock); |
34 } | 110 } |
35 }; | 111 }; |
36 | 112 |
| 113 } // namespace |
| 114 |
| 115 namespace DM { |
| 116 |
37 Error HWUISink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const
{ | 117 Error HWUISink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const
{ |
38 // Do all setup in this function because we don't know the size | 118 // Do all setup in this function because we don't know the size |
39 // for the RenderNode and RenderProxy during the constructor. | 119 // for the RenderNode and RenderProxy during the constructor. |
40 // In practice this doesn't seem too expensive. | 120 // In practice this doesn't seem too expensive. |
41 const SkISize size = src.size(); | 121 const SkISize size = src.size(); |
42 | 122 |
43 // Based on android::SurfaceTexture_init() | 123 // Based on android::SurfaceTexture_init() |
44 android::sp<android::IGraphicBufferProducer> producer; | 124 android::sp<android::IGraphicBufferProducer> producer; |
45 android::sp<android::IGraphicBufferConsumer> consumer; | 125 android::sp<android::IGraphicBufferConsumer> consumer; |
46 android::BufferQueue::createBufferQueue(&producer, &consumer); | 126 android::BufferQueue::createBufferQueue(&producer, &consumer); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 success = | 228 success = |
149 nativeWrapper.readPixels(destinationConfig, dst->getPixels(), dst->rowBy
tes(), 0, 0); | 229 nativeWrapper.readPixels(destinationConfig, dst->getPixels(), dst->rowBy
tes(), 0, 0); |
150 if (!success) { | 230 if (!success) { |
151 return "Failed to extract pixels from HWUI buffer"; | 231 return "Failed to extract pixels from HWUI buffer"; |
152 } | 232 } |
153 | 233 |
154 cpuConsumer->unlockBuffer(nativeBuffer); | 234 cpuConsumer->unlockBuffer(nativeBuffer); |
155 return ""; | 235 return ""; |
156 } | 236 } |
157 | 237 |
| 238 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 239 |
| 240 ViaAndroidSDK::ViaAndroidSDK(Sink* sink) : fSink(sink) { } |
| 241 |
| 242 Error ViaAndroidSDK::draw(const Src& src, |
| 243 SkBitmap* bitmap, |
| 244 SkWStream* stream, |
| 245 SkString* log) const { |
| 246 struct ProxySrc : public Src { |
| 247 const Src& fSrc; |
| 248 ProxySrc(const Src& src) |
| 249 : fSrc(src) {} |
| 250 |
| 251 Error draw(SkCanvas* canvas) const SK_OVERRIDE { |
| 252 // Route through HWUI's upper layers to get operational transforms |
| 253 SkAutoTDelete<android::Canvas> ac (android::Canvas::create_canvas(ca
nvas)); |
| 254 SkAutoTUnref<android::uirenderer::SkiaCanvasProxy> scProxy |
| 255 (new android::uirenderer::SkiaCanvasProxy(ac)); |
| 256 ViaAndroidSDKFilter filter; |
| 257 |
| 258 // Route through a draw filter to get paint transforms |
| 259 scProxy->setDrawFilter(&filter); |
| 260 |
| 261 fSrc.draw(scProxy); |
| 262 |
| 263 return ""; |
| 264 } |
| 265 SkISize size() const SK_OVERRIDE { return fSrc.size(); } |
| 266 Name name() const SK_OVERRIDE { sk_throw(); return ""; } |
| 267 } proxy(src); |
| 268 |
| 269 return fSink->draw(proxy, bitmap, stream, log); |
| 270 } |
| 271 |
158 } // namespace DM | 272 } // namespace DM |
OLD | NEW |