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-27 19:22:01 +00:00
|
|
|
#include "SkHwuiRenderer.h"
|
2015-03-05 16:01:07 +00:00
|
|
|
#include "SkiaCanvasProxy.h"
|
|
|
|
#include "SkStream.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-03-27 19:22:01 +00:00
|
|
|
SkHwuiRenderer renderer;
|
|
|
|
renderer.initialize(src.size());
|
|
|
|
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();
|
|
|
|
renderer.proxy->fence();
|
|
|
|
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
|
2015-03-05 16:01:07 +00:00
|
|
|
SkAutoTDelete<android::Canvas> ac (android::Canvas::create_canvas(canvas));
|
|
|
|
SkAutoTUnref<android::uirenderer::SkiaCanvasProxy> scProxy
|
|
|
|
(new android::uirenderer::SkiaCanvasProxy(ac));
|
|
|
|
|
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;
|
|
|
|
fc.reset(scProxy);
|
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
|