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

Side by Side Diff: dm/DMSrcSinkAndroid.cpp

Issue 974913002: ViaAndroidSDK for DM (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
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"
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 should only be compiled in the Android Framework. */
26 31
27 /* These functions are only compiled in the Android Framework. */ 32 namespace {
28 33
34 /**
35 * An SkDrawFilter implementation which removes all flags and features
36 * not exposed by the Android SDK.
37 */
38 class ViaAndroidSDKFilter : public SkDrawFilter {
39
40 inline void checkShader(SkPaint* paint, SkShader* shader) {
mtklein 2015/03/03 15:55:14 I think this can be static void CheckShader(SkPain
mtklein 2015/03/03 15:55:14 Just FYI, this inline is redundant here.
tomhudson 2015/03/05 14:53:52 Done.
tomhudson 2015/03/05 14:53:52 Yeah, I was offended by calling SkPaint::getShader
41 if (shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefault_BitmapType ) {
42 return;
43 }
44 if (shader->asACompose(NULL)) {
45 return;
46 }
47 SkShader::GradientType gtype = shader->asAGradient(NULL);
48 if (gtype == SkShader::kLinear_GradientType ||
49 gtype == SkShader::kRadial_GradientType ||
50 gtype == SkShader::kSweep_GradientType) {
51 return;
52 }
53 paint->setShader(NULL);
54 }
55
56 virtual bool filter(SkPaint* paint, Type drawType) SK_OVERRIDE {
mtklein 2015/03/03 15:55:14 We've been using just SK_OVERRIDE for overrides la
tomhudson 2015/03/05 14:53:51 Done.
57
58 uint32_t flags = paint->getFlags();
59 flags &= ~SkPaint::kLCDRenderText_Flag;
60 paint->setFlags(flags);
61
62 // Force bilinear scaling or none
63 if (paint->getFilterQuality() != kNone_SkFilterQuality) {
64 paint->setFilterQuality(kLow_SkFilterQuality);
65 }
66
67 SkShader * shader = paint->getShader();
mtklein 2015/03/03 15:55:14 Can't decide where to put your *s?
tomhudson 2015/03/05 14:53:52 Done.
68 if (shader) {
mtklein 2015/03/03 15:55:14 Might want to write these checks like this, to sco
tomhudson 2015/03/05 14:53:52 Acknowledged.
69 checkShader(paint, shader);
mtklein 2015/03/03 15:55:14 this->
tomhudson 2015/03/05 14:53:52 Acknowledged.
70 }
71
72 // GlopBuilder only supports mode & matrix color filters
73 SkColorFilter * cf = paint->getColorFilter();
74 if (cf) {
75 SkColor color;
76 SkXfermode::Mode mode;
77 SkScalar srcColorMatrix[20];
78 if (!cf->asColorMode(&color, &mode) && !cf->asColorMatrix(srcColorMa trix)) {
79 paint->setColorFilter(NULL);
80 }
81 }
82
83 SkPathEffect* pe = paint->getPathEffect();
84 if (pe && !pe->exposedInAndroidJavaAPI()) {
85 paint->setPathEffect(NULL);
86 }
87
88 // TODO: Android doesn't support all the flags that can be passed to
89 // blur filters; we need plumbing to get them out.
90
91 paint->setImageFilter(NULL);
92 paint->setLooper(NULL);
93
94 return true;
95 };
96 };
97
98 /**
99 * Helper class for setting up android::uirenderer::renderthread::RenderProxy.
100 */
29 class ContextFactory : public android::uirenderer::IContextFactory { 101 class ContextFactory : public android::uirenderer::IContextFactory {
30 public: 102 public:
31 android::uirenderer::AnimationContext* createAnimationContext 103 android::uirenderer::AnimationContext* createAnimationContext
32 (android::uirenderer::renderthread::TimeLord& clock) SK_OVERRIDE { 104 (android::uirenderer::renderthread::TimeLord& clock) SK_OVERRIDE {
33 return new android::uirenderer::AnimationContext(clock); 105 return new android::uirenderer::AnimationContext(clock);
34 } 106 }
35 }; 107 };
36 108
109 } // namespace
110
111 namespace DM {
112
37 Error HWUISink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const { 113 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 114 // Do all setup in this function because we don't know the size
39 // for the RenderNode and RenderProxy during the constructor. 115 // for the RenderNode and RenderProxy during the constructor.
40 // In practice this doesn't seem too expensive. 116 // In practice this doesn't seem too expensive.
41 const SkISize size = src.size(); 117 const SkISize size = src.size();
42 118
43 // Based on android::SurfaceTexture_init() 119 // Based on android::SurfaceTexture_init()
44 android::sp<android::IGraphicBufferProducer> producer; 120 android::sp<android::IGraphicBufferProducer> producer;
45 android::sp<android::IGraphicBufferConsumer> consumer; 121 android::sp<android::IGraphicBufferConsumer> consumer;
46 android::BufferQueue::createBufferQueue(&producer, &consumer); 122 android::BufferQueue::createBufferQueue(&producer, &consumer);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 success = 224 success =
149 nativeWrapper.readPixels(destinationConfig, dst->getPixels(), dst->rowBy tes(), 0, 0); 225 nativeWrapper.readPixels(destinationConfig, dst->getPixels(), dst->rowBy tes(), 0, 0);
150 if (!success) { 226 if (!success) {
151 return "Failed to extract pixels from HWUI buffer"; 227 return "Failed to extract pixels from HWUI buffer";
152 } 228 }
153 229
154 cpuConsumer->unlockBuffer(nativeBuffer); 230 cpuConsumer->unlockBuffer(nativeBuffer);
155 return ""; 231 return "";
156 } 232 }
157 233
234 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
235
236 ViaAndroidSDK::ViaAndroidSDK(Sink* sink) : fSink(sink), fFilter (new ViaAndroidS DKFilter()) { }
237
238 Error ViaAndroidSDK::draw(const Src& src,
239 SkBitmap* bitmap,
240 SkWStream* stream,
241 SkString* log) const {
242 SkISize size = src.size();
243 SkPictureRecorder recorder;
244 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
245 if (!err.isEmpty()) {
246 return err;
247 }
248 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
249
250 struct ProxySrc : public Src {
251 const Src& fSrc;
252 const SkPicture* fPic;
253 const SkDrawFilter* fFilter;
254
255 ProxySrc(const Src& src, const SkPicture* pic, SkDrawFilter* filter)
256 : fSrc(src), fPic(pic), fFilter(filter) {}
257
258 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
259 // Route through HWUI's upper layers to change draw operations
260 android::Canvas* ac = android::Canvas::create_canvas(canvas);
mtklein 2015/03/03 15:55:14 SkAutoTDelete?
tomhudson 2015/03/05 14:53:52 Done.
261 SkAutoTUnref<android::uirenderer::SkiaCanvasProxy> scProxy
262 (new android::uirenderer::SkiaCanvasProxy(ac));
263
264 // Route through a draw filter to change paint fields
265 scProxy->setDrawFilter((ViaAndroidSDKFilter*) fFilter);
266
267 scProxy->drawPicture(fPic);
mtklein 2015/03/03 15:55:14 Let's try fSrc.draw(scProxy) and drop the picture.
tomhudson 2015/03/05 14:53:51 Done.
268
269 delete ac;
270 return "";
271 }
272 SkISize size() const SK_OVERRIDE { return fSrc.size(); }
273 Name name() const SK_OVERRIDE { sk_throw(); return ""; }
274 } proxy(src, pic, fFilter.get());
275
276 return fSink->draw(proxy, bitmap, stream, log);
277 }
278
158 } // namespace DM 279 } // namespace DM
OLDNEW
« dm/DMSrcSinkAndroid.h ('K') | « dm/DMSrcSinkAndroid.h ('k') | include/core/SkPathEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698