aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMSrcSinkAndroid.cpp
blob: 3958e484fd7fca4a94f06cde206b487249ad6a68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "DMSrcSink.h"
#include "DMSrcSinkAndroid.h"

#include "SkAndroidSDKCanvas.h"
#include "SkCanvas.h"
#include "SkiaCanvasProxy.h"
#include "SkStream.h"
#include <utils/TestWindowContext.h>

/* These functions are only compiled in the Android Framework. */

namespace DM {

Error HWUISink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
    android::uirenderer::TestWindowContext renderer;
    renderer.initialize(src.size().width(), src.size().height());
    SkCanvas* canvas = renderer.prepareToDraw();
    Error err = src.draw(canvas);
    if (!err.isEmpty()) {
        return err;
    }
    renderer.finishDrawing();
    renderer.fence();
    renderer.capturePixels(dst);
    return "";
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

ViaAndroidSDK::ViaAndroidSDK(Sink* sink) : fSink(sink) { }

Error ViaAndroidSDK::draw(const Src& src,
                          SkBitmap* bitmap,
                          SkWStream* stream,
                          SkString* log) const {
    struct ProxySrc : public Src {
        const Src& fSrc;
        ProxySrc(const Src& src)
            : fSrc(src) {}

        Error draw(SkCanvas* canvas) const override {
            // Pass through HWUI's upper layers to get operational transforms
            SkAutoTDelete<android::Canvas> ac (android::Canvas::create_canvas(canvas));
            SkAutoTUnref<android::uirenderer::SkiaCanvasProxy> scProxy
                (new android::uirenderer::SkiaCanvasProxy(ac));

            // Pass through another proxy to get paint transforms
            SkAndroidSDKCanvas fc;
            fc.reset(scProxy);

            fSrc.draw(&fc);

            return "";
        }
        SkISize size() const override { return fSrc.size(); }
        Name name() const override { sk_throw(); return ""; }
    } proxy(src);

    return fSink->draw(proxy, bitmap, stream, log);
}

}  // namespace DM