Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: src/utils/android/SkHwuiRenderer.cpp

Issue 1036303002: Move HWUI boilerplate into utils/android (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/utils/android/SkHwuiRenderer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "nanobenchAndroid.h" 8 #include "SkHwuiRenderer.h"
9 9
10 #include "AnimationContext.h" 10 #include "AnimationContext.h"
11 #include "IContextFactory.h" 11 #include "IContextFactory.h"
12 #include "SkiaCanvasProxy.h" 12 #include "SkBitmap.h"
13 #include "android/rect.h" 13 #include "gui/BufferQueue.h"
14 #include "android/native_window.h"
15 #include "renderthread/TimeLord.h"
16 14
17 namespace { 15 namespace {
18 16
19 /** 17 /**
20 * Helper class for setting up android::uirenderer::renderthread::RenderProxy. 18 * Helper class for setting up android::uirenderer::renderthread::RenderProxy.
21 */ 19 */
22 class ContextFactory : public android::uirenderer::IContextFactory { 20 class ContextFactory : public android::uirenderer::IContextFactory {
23 public: 21 public:
24 android::uirenderer::AnimationContext* createAnimationContext 22 android::uirenderer::AnimationContext* createAnimationContext
25 (android::uirenderer::renderthread::TimeLord& clock) override { 23 (android::uirenderer::renderthread::TimeLord& clock) override {
26 return new android::uirenderer::AnimationContext(clock); 24 return new android::uirenderer::AnimationContext(clock);
27 } 25 }
28 }; 26 };
29 27
30 } 28 }
31 29
32 HWUITarget::HWUITarget(const Config& c, Benchmark* bench) : Target(c) { } 30 void SkHwuiRenderer::initialize(SkISize size) {
33 31 this->size = size;
34 void HWUITarget::setup() {
35 this->proxy->fence();
36 }
37
38 SkCanvas* HWUITarget::beginTiming(SkCanvas* canvas) {
39 this->renderer->prepare();
40 this->renderer->clipRect(0, 0, this->size.width(), this->size.height(),
41 SkRegion::Op::kReplace_Op);
42 SkCanvas* targetCanvas = this->renderer->asSkCanvas();
43 if (targetCanvas) {
44 this->fc.reset(targetCanvas);
45 canvas = &this->fc;
46 // This might minimally distort timing, but canvas isn't valid outside t he timer.
47 canvas->clear(SK_ColorWHITE);
48 }
49 return canvas;
50 }
51
52 void HWUITarget::endTiming() {
53 this->renderer->finish();
54 this->rootNode->setStagingDisplayList(this->renderer->finishRecording());
55 this->proxy->syncAndDrawFrame();
56 // Surprisingly, calling this->proxy->fence() here appears to make no differ ence to
57 // the timings we record.
58 }
59
60 void HWUITarget::fence() {
61 this->proxy->fence();
62 }
63
64 bool HWUITarget::needsFrameTiming() const {
65 return true;
66 }
67
68 bool HWUITarget::init(SkImageInfo info, Benchmark* bench) {
69 // extracted from DMSrcSinkAndroid.cpp's HWUISink::draw()
70 size.set(bench->getSize().x(), bench->getSize().y());
71 android::BufferQueue::createBufferQueue(&this->producer, &this->consumer); 32 android::BufferQueue::createBufferQueue(&this->producer, &this->consumer);
72 this->cpuConsumer = new android::CpuConsumer(this->consumer, 1); 33 this->cpuConsumer = new android::CpuConsumer(this->consumer, 1);
73 this->cpuConsumer->setName(android::String8("SkiaBenchmarkClient")); 34 this->cpuConsumer->setName(android::String8("SkiaBenchmarkClient"));
74 this->cpuConsumer->setDefaultBufferSize(size.width(), size.height()); 35 this->cpuConsumer->setDefaultBufferSize(size.width(), size.height());
75 this->androidSurface = new android::Surface(this->producer); 36 this->androidSurface = new android::Surface(this->producer);
76 native_window_set_buffers_dimensions(this->androidSurface.get(), 37 native_window_set_buffers_dimensions(this->androidSurface.get(),
77 size.width(), size.height()); 38 size.width(), size.height());
78 native_window_set_buffers_format(this->androidSurface.get(), 39 native_window_set_buffers_format(this->androidSurface.get(),
79 android::PIXEL_FORMAT_RGBA_8888); 40 android::PIXEL_FORMAT_RGBA_8888);
80 native_window_set_usage(this->androidSurface.get(), GRALLOC_USAGE_SW_READ_OF TEN | 41 native_window_set_usage(this->androidSurface.get(), GRALLOC_USAGE_SW_READ_OF TEN |
81 GRALLOC_USAGE_SW_WRITE_NEVER | 42 GRALLOC_USAGE_SW_WRITE_NEVER |
82 GRALLOC_USAGE_HW_RENDER); 43 GRALLOC_USAGE_HW_RENDER);
83 this->rootNode.reset(new android::uirenderer::RenderNode()); 44 this->rootNode.reset(new android::uirenderer::RenderNode());
84 this->rootNode->incStrong(nullptr); 45 this->rootNode->incStrong(nullptr);
85 this->rootNode->mutateStagingProperties().setLeftTopRightBottom 46 this->rootNode->mutateStagingProperties().setLeftTopRightBottom
86 (0, 0, size.width(), size.height()); 47 (0, 0, size.width(), size.height());
87 this->rootNode->mutateStagingProperties().setClipToBounds(false); 48 this->rootNode->mutateStagingProperties().setClipToBounds(false);
88 this->rootNode->setPropertyFieldsDirty(android::uirenderer::RenderNode::GENE RIC); 49 this->rootNode->setPropertyFieldsDirty(android::uirenderer::RenderNode::GENE RIC);
89 ContextFactory factory; 50 ContextFactory factory;
90 this->proxy.reset 51 this->proxy.reset
91 (new android::uirenderer::renderthread::RenderProxy(false, this->rootNod e, &factory)); 52 (new android::uirenderer::renderthread::RenderProxy(false, this->rootNod e, &factory));
92 this->proxy->loadSystemProperties(); 53 this->proxy->loadSystemProperties();
93 this->proxy->initialize(this->androidSurface.get()); 54 this->proxy->initialize(this->androidSurface.get());
94 float lightX = size.width() / 2.0f; 55 float lightX = size.width() / 2.0f;
95 android::uirenderer::Vector3 lightVector { lightX, -200.0f, 800.0f }; 56 android::uirenderer::Vector3 lightVector { lightX, -200.0f, 800.0f };
96 this->proxy->setup(size.width(), size.height(), lightVector, 800.0f, 57 this->proxy->setup(size.width(), size.height(), lightVector, 800.0f,
97 255 * 0.075f, 255 * 0.15f); 58 255 * 0.075f, 255 * 0.15f);
98 this->renderer.reset(new android::uirenderer::DisplayListRenderer()); 59 this->renderer.reset(new android::uirenderer::DisplayListRenderer());
99 this->renderer->setViewport(size.width(), size.height()); 60 this->renderer->setViewport(size.width(), size.height());
100
101 // Since we have no SkSurface for HWUI, other parts of the code base have to
102 // explicitly work around the fact that it may be invalid / have no SkCanvas .
103
104 return true;
105 } 61 }
106 62
107 bool HWUITarget::capturePixels(SkBitmap* bmp) { 63 SkCanvas* SkHwuiRenderer::prepareToDraw() {
64 this->renderer->prepare();
65 this->renderer->clipRect(0, 0, this->size.width(), this->size.height(),
66 SkRegion::Op::kReplace_Op);
67 return this->renderer->asSkCanvas();
68 }
69
70 void SkHwuiRenderer::finishDrawing() {
71 this->renderer->finish();
72 this->rootNode->setStagingDisplayList(this->renderer->finishRecording());
73 this->proxy->syncAndDrawFrame();
74 // Surprisingly, calling this->proxy->fence() here appears to make no differ ence to
75 // the timings we record.
76 }
77
78 bool SkHwuiRenderer::capturePixels(SkBitmap* bmp) {
108 SkImageInfo destinationConfig = 79 SkImageInfo destinationConfig =
109 SkImageInfo::Make(this->size.width(), this->size.height(), 80 SkImageInfo::Make(this->size.width(), this->size.height(),
110 kRGBA_8888_SkColorType, kPremul_SkAlphaType); 81 kRGBA_8888_SkColorType, kPremul_SkAlphaType);
111 bmp->allocPixels(destinationConfig); 82 bmp->allocPixels(destinationConfig);
112 sk_memset32((uint32_t*) bmp->getPixels(), SK_ColorRED, 83 sk_memset32((uint32_t*) bmp->getPixels(), SK_ColorRED,
113 this->size.width() * this->size.height()); 84 this->size.width() * this->size.height());
114 85
115 android::CpuConsumer::LockedBuffer nativeBuffer; 86 android::CpuConsumer::LockedBuffer nativeBuffer;
116 android::status_t retval = this->cpuConsumer->lockNextBuffer(&nativeBuffer); 87 android::status_t retval = this->cpuConsumer->lockNextBuffer(&nativeBuffer);
117 if (retval == android::BAD_VALUE) { 88 if (retval == android::BAD_VALUE) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (!success) { 121 if (!success) {
151 SkDebugf("Failed to extract pixels from HWUI buffer"); 122 SkDebugf("Failed to extract pixels from HWUI buffer");
152 return false; 123 return false;
153 } 124 }
154 125
155 this->cpuConsumer->unlockBuffer(nativeBuffer); 126 this->cpuConsumer->unlockBuffer(nativeBuffer);
156 127
157 return true; 128 return true;
158 } 129 }
159 130
160
OLDNEW
« no previous file with comments | « src/utils/android/SkHwuiRenderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698