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