blob: 3958e484fd7fca4a94f06cde206b487249ad6a68 [file] [log] [blame]
tomhudsoneebc39a2015-02-23 12:18:05 -08001/*
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
tomhudson48dc6dc2015-03-24 12:46:40 -070011#include "SkAndroidSDKCanvas.h"
tomhudson97cd0702015-03-11 12:21:08 -070012#include "SkCanvas.h"
tomhudson64de1e12015-03-05 08:01:07 -080013#include "SkiaCanvasProxy.h"
tomhudson64de1e12015-03-05 08:01:07 -080014#include "SkStream.h"
tomhudson3c8ceb72015-10-26 07:21:31 -070015#include <utils/TestWindowContext.h>
tomhudsoneebc39a2015-02-23 12:18:05 -080016
tomhudsoneebc39a2015-02-23 12:18:05 -080017/* These functions are only compiled in the Android Framework. */
18
tomhudson64de1e12015-03-05 08:01:07 -080019namespace DM {
20
tomhudsoneebc39a2015-02-23 12:18:05 -080021Error HWUISink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
tomhudson3c8ceb72015-10-26 07:21:31 -070022 android::uirenderer::TestWindowContext renderer;
23 renderer.initialize(src.size().width(), src.size().height());
tomhudson573ae012015-03-27 12:22:01 -070024 SkCanvas* canvas = renderer.prepareToDraw();
25 Error err = src.draw(canvas);
tomhudsoneebc39a2015-02-23 12:18:05 -080026 if (!err.isEmpty()) {
27 return err;
28 }
tomhudson573ae012015-03-27 12:22:01 -070029 renderer.finishDrawing();
tomhudson3c8ceb72015-10-26 07:21:31 -070030 renderer.fence();
tomhudson573ae012015-03-27 12:22:01 -070031 renderer.capturePixels(dst);
tomhudsoneebc39a2015-02-23 12:18:05 -080032 return "";
33}
34
tomhudson64de1e12015-03-05 08:01:07 -080035/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
36
37ViaAndroidSDK::ViaAndroidSDK(Sink* sink) : fSink(sink) { }
38
39Error 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
mtklein36352bf2015-03-25 18:17:31 -070048 Error draw(SkCanvas* canvas) const override {
tomhudson97cd0702015-03-11 12:21:08 -070049 // Pass through HWUI's upper layers to get operational transforms
tomhudson64de1e12015-03-05 08:01:07 -080050 SkAutoTDelete<android::Canvas> ac (android::Canvas::create_canvas(canvas));
51 SkAutoTUnref<android::uirenderer::SkiaCanvasProxy> scProxy
52 (new android::uirenderer::SkiaCanvasProxy(ac));
tomhudson64de1e12015-03-05 08:01:07 -080053
tomhudson97cd0702015-03-11 12:21:08 -070054 // Pass through another proxy to get paint transforms
tomhudson48dc6dc2015-03-24 12:46:40 -070055 SkAndroidSDKCanvas fc;
56 fc.reset(scProxy);
tomhudson64de1e12015-03-05 08:01:07 -080057
tomhudson97cd0702015-03-11 12:21:08 -070058 fSrc.draw(&fc);
tomhudson64de1e12015-03-05 08:01:07 -080059
60 return "";
61 }
mtklein36352bf2015-03-25 18:17:31 -070062 SkISize size() const override { return fSrc.size(); }
63 Name name() const override { sk_throw(); return ""; }
tomhudson64de1e12015-03-05 08:01:07 -080064 } proxy(src);
65
66 return fSink->draw(proxy, bitmap, stream, log);
67}
68
tomhudsoneebc39a2015-02-23 12:18:05 -080069} // namespace DM