2015-02-23 20:18:05 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2015-03-24 19:46:40 +00:00
|
|
|
#include "SkAndroidSDKCanvas.h"
|
2015-03-11 19:21:08 +00:00
|
|
|
#include "SkCanvas.h"
|
2015-03-05 16:01:07 +00:00
|
|
|
#include "SkiaCanvasProxy.h"
|
|
|
|
#include "SkStream.h"
|
2015-10-26 14:21:31 +00:00
|
|
|
#include <utils/TestWindowContext.h>
|
2015-02-23 20:18:05 +00:00
|
|
|
|
|
|
|
/* These functions are only compiled in the Android Framework. */
|
|
|
|
|
2015-03-05 16:01:07 +00:00
|
|
|
namespace DM {
|
|
|
|
|
2015-02-23 20:18:05 +00:00
|
|
|
Error HWUISink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
|
2015-10-26 14:21:31 +00:00
|
|
|
android::uirenderer::TestWindowContext renderer;
|
|
|
|
renderer.initialize(src.size().width(), src.size().height());
|
2015-03-27 19:22:01 +00:00
|
|
|
SkCanvas* canvas = renderer.prepareToDraw();
|
|
|
|
Error err = src.draw(canvas);
|
2015-02-23 20:18:05 +00:00
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
2015-03-27 19:22:01 +00:00
|
|
|
renderer.finishDrawing();
|
2015-10-26 14:21:31 +00:00
|
|
|
renderer.fence();
|
2015-03-27 19:22:01 +00:00
|
|
|
renderer.capturePixels(dst);
|
2015-02-23 20:18:05 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-03-05 16:01:07 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
|
|
|
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) {}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
Error draw(SkCanvas* canvas) const override {
|
2015-03-11 19:21:08 +00:00
|
|
|
// Pass through HWUI's upper layers to get operational transforms
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<android::Canvas> ac(android::Canvas::create_canvas(canvas));
|
2016-11-28 13:57:01 +00:00
|
|
|
std::unique_ptr<android::uirenderer::SkiaCanvasProxy> scProxy
|
2016-11-03 18:40:50 +00:00
|
|
|
(new android::uirenderer::SkiaCanvasProxy(ac.get()));
|
2015-03-05 16:01:07 +00:00
|
|
|
|
2015-03-11 19:21:08 +00:00
|
|
|
// Pass through another proxy to get paint transforms
|
2015-03-24 19:46:40 +00:00
|
|
|
SkAndroidSDKCanvas fc;
|
2016-11-07 16:37:57 +00:00
|
|
|
fc.reset(scProxy.get());
|
2015-03-05 16:01:07 +00:00
|
|
|
|
2015-03-11 19:21:08 +00:00
|
|
|
fSrc.draw(&fc);
|
2015-03-05 16:01:07 +00:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize size() const override { return fSrc.size(); }
|
|
|
|
Name name() const override { sk_throw(); return ""; }
|
2015-03-05 16:01:07 +00:00
|
|
|
} proxy(src);
|
|
|
|
|
|
|
|
return fSink->draw(proxy, bitmap, stream, log);
|
|
|
|
}
|
|
|
|
|
2015-02-23 20:18:05 +00:00
|
|
|
} // namespace DM
|