1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "DMSrcSink.h"
9 #include "DMSrcSinkAndroid.h"
10
11 #include "SkAndroidSDKCanvas.h"
12 #include "SkCanvas.h"
13 #include "SkHwuiRenderer.h"
14 #include "SkiaCanvasProxy.h"
15 #include "SkStream.h"
16
17 /* These functions are only compiled in the Android Framework. */
18
19 namespace DM {
20
draw(const Src & src,SkBitmap * dst,SkWStream *,SkString *) const21 Error HWUISink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
22 SkHwuiRenderer renderer;
23 renderer.initialize(src.size());
24 SkCanvas* canvas = renderer.prepareToDraw();
25 Error err = src.draw(canvas);
26 if (!err.isEmpty()) {
27 return err;
28 }
29 renderer.finishDrawing();
30 renderer.proxy->fence();
31 renderer.capturePixels(dst);
32 return "";
33 }
34
35 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
36
ViaAndroidSDK(Sink * sink)37 ViaAndroidSDK::ViaAndroidSDK(Sink* sink) : fSink(sink) { }
38
draw(const Src & src,SkBitmap * bitmap,SkWStream * stream,SkString * log) const39 Error ViaAndroidSDK::draw(const Src& src,
40 SkBitmap* bitmap,
41 SkWStream* stream,
42 SkString* log) const {
43 struct ProxySrc : public Src {
44 const Src& fSrc;
45 ProxySrc(const Src& src)
46 : fSrc(src) {}
47
48 Error draw(SkCanvas* canvas) const override {
49 // Pass through HWUI's upper layers to get operational transforms
50 SkAutoTDelete<android::Canvas> ac (android::Canvas::create_canvas(canvas));
51 SkAutoTUnref<android::uirenderer::SkiaCanvasProxy> scProxy
52 (new android::uirenderer::SkiaCanvasProxy(ac));
53
54 // Pass through another proxy to get paint transforms
55 SkAndroidSDKCanvas fc;
56 fc.reset(scProxy);
57
58 fSrc.draw(&fc);
59
60 return "";
61 }
62 SkISize size() const override { return fSrc.size(); }
63 Name name() const override { sk_throw(); return ""; }
64 } proxy(src);
65
66 return fSink->draw(proxy, bitmap, stream, log);
67 }
68
69 } // namespace DM
70