tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
tomhudson | 48dc6dc | 2015-03-24 12:46:40 -0700 | [diff] [blame] | 11 | #include "SkAndroidSDKCanvas.h" |
tomhudson | 97cd070 | 2015-03-11 12:21:08 -0700 | [diff] [blame] | 12 | #include "SkCanvas.h" |
tomhudson | 573ae01 | 2015-03-27 12:22:01 -0700 | [diff] [blame] | 13 | #include "SkHwuiRenderer.h" |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 14 | #include "SkiaCanvasProxy.h" |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 15 | #include "SkStream.h" |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 16 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 17 | /* These functions are only compiled in the Android Framework. */ |
| 18 | |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 19 | namespace DM { |
| 20 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 21 | Error HWUISink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const { |
tomhudson | 573ae01 | 2015-03-27 12:22:01 -0700 | [diff] [blame] | 22 | SkHwuiRenderer renderer; |
| 23 | renderer.initialize(src.size()); |
| 24 | SkCanvas* canvas = renderer.prepareToDraw(); |
| 25 | Error err = src.draw(canvas); |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 26 | if (!err.isEmpty()) { |
| 27 | return err; |
| 28 | } |
tomhudson | 573ae01 | 2015-03-27 12:22:01 -0700 | [diff] [blame] | 29 | renderer.finishDrawing(); |
| 30 | renderer.proxy->fence(); |
| 31 | renderer.capturePixels(dst); |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 32 | return ""; |
| 33 | } |
| 34 | |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 35 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 36 | |
| 37 | ViaAndroidSDK::ViaAndroidSDK(Sink* sink) : fSink(sink) { } |
| 38 | |
| 39 | Error 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 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 48 | Error draw(SkCanvas* canvas) const override { |
tomhudson | 97cd070 | 2015-03-11 12:21:08 -0700 | [diff] [blame] | 49 | // Pass through HWUI's upper layers to get operational transforms |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 50 | SkAutoTDelete<android::Canvas> ac (android::Canvas::create_canvas(canvas)); |
| 51 | SkAutoTUnref<android::uirenderer::SkiaCanvasProxy> scProxy |
| 52 | (new android::uirenderer::SkiaCanvasProxy(ac)); |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 53 | |
tomhudson | 97cd070 | 2015-03-11 12:21:08 -0700 | [diff] [blame] | 54 | // Pass through another proxy to get paint transforms |
tomhudson | 48dc6dc | 2015-03-24 12:46:40 -0700 | [diff] [blame] | 55 | SkAndroidSDKCanvas fc; |
| 56 | fc.reset(scProxy); |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 57 | |
tomhudson | 97cd070 | 2015-03-11 12:21:08 -0700 | [diff] [blame] | 58 | fSrc.draw(&fc); |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 59 | |
| 60 | return ""; |
| 61 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 62 | SkISize size() const override { return fSrc.size(); } |
| 63 | Name name() const override { sk_throw(); return ""; } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 64 | } proxy(src); |
| 65 | |
| 66 | return fSink->draw(proxy, bitmap, stream, log); |
| 67 | } |
| 68 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 69 | } // namespace DM |