skia2/dm/DMSrcSinkAndroid.cpp
tomhudson 573ae01295 Move HWUI boilerplate into utils/android
Duplicate code from the HWUI backends for DM and nanobench
moves into a single place, saving a hundred lines or more of
cut-and-paste.

There's some indication that this increases the incidence of
SkCanvas "Unable to find device for layer." warnings, but no
clear degradation in test results.

R=djsollen@google.com,mtklein@google.com
BUG=skia:3589

Review URL: https://codereview.chromium.org/1036303002
2015-03-27 12:22:01 -07:00

70 lines
2.0 KiB
C++

/*
* 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 "SkHwuiRenderer.h"
#include "SkiaCanvasProxy.h"
#include "SkStream.h"
/* These functions are only compiled in the Android Framework. */
namespace DM {
Error HWUISink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
SkHwuiRenderer renderer;
renderer.initialize(src.size());
SkCanvas* canvas = renderer.prepareToDraw();
Error err = src.draw(canvas);
if (!err.isEmpty()) {
return err;
}
renderer.finishDrawing();
renderer.proxy->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