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

Side by Side Diff: android_webview/browser/browser_view_renderer_unittest.cc

Issue 1920843002: Test: deleting RTM before BVR does not leak resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: undo over-zealous git cl format Created 4 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <map> 5 #include <map>
6 #include <queue> 6 #include <queue>
7 #include <utility> 7 #include <utility>
8 8
9 #include "android_webview/browser/browser_view_renderer.h" 9 #include "android_webview/browser/browser_view_renderer.h"
10 #include "android_webview/browser/child_frame.h" 10 #include "android_webview/browser/child_frame.h"
11 #include "android_webview/browser/compositor_frame_consumer.h" 11 #include "android_webview/browser/compositor_frame_consumer.h"
12 #include "android_webview/browser/render_thread_manager.h"
12 #include "android_webview/browser/test/rendering_test.h" 13 #include "android_webview/browser/test/rendering_test.h"
13 #include "base/location.h" 14 #include "base/location.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
15 #include "cc/output/compositor_frame.h" 16 #include "cc/output/compositor_frame.h"
16 #include "content/public/test/test_synchronous_compositor_android.h" 17 #include "content/public/test/test_synchronous_compositor_android.h"
17 18
18 namespace android_webview { 19 namespace android_webview {
19 20
20 class SmokeTest : public RenderingTest { 21 class SmokeTest : public RenderingTest {
21 void StartTest() override { browser_view_renderer_->PostInvalidate(); } 22 void StartTest() override { browser_view_renderer_->PostInvalidate(); }
22 23
23 void DidDrawOnRT(RenderThreadManager* functor) override { 24 void DidDrawOnRT() override { EndTest(); }
24 EndTest();
25 }
26 }; 25 };
27 26
28 RENDERING_TEST_F(SmokeTest); 27 RENDERING_TEST_F(SmokeTest);
29 28
30 class ClearViewTest : public RenderingTest { 29 class ClearViewTest : public RenderingTest {
31 public: 30 public:
32 ClearViewTest() : on_draw_count_(0) {} 31 ClearViewTest() : on_draw_count_(0) {}
33 32
34 void StartTest() override { 33 void StartTest() override {
35 browser_view_renderer_->PostInvalidate(); 34 browser_view_renderer_->PostInvalidate();
36 browser_view_renderer_->ClearView(); 35 browser_view_renderer_->ClearView();
37 } 36 }
38 37
39 void DidOnDraw(bool success) override { 38 void DidOnDraw(bool success) override {
40 on_draw_count_++; 39 on_draw_count_++;
41 if (on_draw_count_ == 1) { 40 if (on_draw_count_ == 1) {
42 // First OnDraw should be skipped due to ClearView. 41 // First OnDraw should be skipped due to ClearView.
43 EXPECT_FALSE(success); 42 EXPECT_FALSE(success);
44 browser_view_renderer_->DidUpdateContent(); // Unset ClearView. 43 browser_view_renderer_->DidUpdateContent(); // Unset ClearView.
45 browser_view_renderer_->PostInvalidate(); 44 browser_view_renderer_->PostInvalidate();
46 } else { 45 } else {
47 // Following OnDraws should succeed. 46 // Following OnDraws should succeed.
48 EXPECT_TRUE(success); 47 EXPECT_TRUE(success);
49 } 48 }
50 } 49 }
51 50
52 void DidDrawOnRT(RenderThreadManager* functor) override { 51 void DidDrawOnRT() override { EndTest(); }
53 EndTest(); 52
54 }
55 private: 53 private:
56 int on_draw_count_; 54 int on_draw_count_;
57 }; 55 };
58 56
59 RENDERING_TEST_F(ClearViewTest); 57 RENDERING_TEST_F(ClearViewTest);
60 58
61 class TestAnimateInAndOutOfScreen : public RenderingTest { 59 class TestAnimateInAndOutOfScreen : public RenderingTest {
62 public: 60 public:
63 TestAnimateInAndOutOfScreen() : on_draw_count_(0), draw_gl_count_on_rt_(0) {} 61 TestAnimateInAndOutOfScreen() : on_draw_count_(0), draw_gl_count_on_rt_(0) {}
64 62
(...skipping 15 matching lines...) Expand all
80 // draw constraints of BVR is updated to initial constraints. 78 // draw constraints of BVR is updated to initial constraints.
81 if (on_draw_count_ == 1 || on_draw_count_ == 2) 79 if (on_draw_count_ == 1 || on_draw_count_ == 2)
82 browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect()); 80 browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect());
83 } 81 }
84 82
85 void DidOnDraw(bool success) override { 83 void DidOnDraw(bool success) override {
86 EXPECT_TRUE(success); 84 EXPECT_TRUE(success);
87 on_draw_count_++; 85 on_draw_count_++;
88 } 86 }
89 87
90 bool WillDrawOnRT(RenderThreadManager* functor, 88 bool WillDrawOnRT(AwDrawGLInfo* draw_info) override {
91 AwDrawGLInfo* draw_info) override {
92 if (draw_gl_count_on_rt_ == 1) { 89 if (draw_gl_count_on_rt_ == 1) {
93 draw_gl_count_on_rt_++; 90 draw_gl_count_on_rt_++;
94 ui_task_runner_->PostTask( 91 ui_task_runner_->PostTask(
95 FROM_HERE, 92 FROM_HERE,
96 base::Bind(&RenderingTest::PostInvalidate, base::Unretained(this))); 93 base::Bind(&RenderingTest::PostInvalidate, base::Unretained(this)));
97 return false; 94 return false;
98 } 95 }
99 96
100 draw_info->width = window_->surface_size().width(); 97 draw_info->width = window_->surface_size().width();
101 draw_info->height = window_->surface_size().height(); 98 draw_info->height = window_->surface_size().height();
102 draw_info->is_layer = false; 99 draw_info->is_layer = false;
103 100
104 gfx::Transform transform; 101 gfx::Transform transform;
105 if (draw_gl_count_on_rt_ == 0) 102 if (draw_gl_count_on_rt_ == 0)
106 transform = new_constraints_.transform; 103 transform = new_constraints_.transform;
107 104
108 transform.matrix().asColMajorf(draw_info->transform); 105 transform.matrix().asColMajorf(draw_info->transform);
109 return true; 106 return true;
110 } 107 }
111 108
112 void DidDrawOnRT(RenderThreadManager* functor) override { 109 void DidDrawOnRT() override { draw_gl_count_on_rt_++; }
113 draw_gl_count_on_rt_++;
114 }
115 110
116 bool DrawConstraintsEquals( 111 bool DrawConstraintsEquals(
117 const ParentCompositorDrawConstraints& constraints1, 112 const ParentCompositorDrawConstraints& constraints1,
118 const ParentCompositorDrawConstraints& constraints2) { 113 const ParentCompositorDrawConstraints& constraints2) {
119 if (constraints1.is_layer != constraints2.is_layer || 114 if (constraints1.is_layer != constraints2.is_layer ||
120 constraints1.transform != constraints2.transform) 115 constraints1.transform != constraints2.transform)
121 return false; 116 return false;
122 117
123 return !constraints1.is_layer || 118 return !constraints1.is_layer ||
124 constraints1.surface_rect_empty == constraints2.surface_rect_empty; 119 constraints1.surface_rect_empty == constraints2.surface_rect_empty;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 182 }
188 on_draw_count_++; 183 on_draw_count_++;
189 } 184 }
190 185
191 private: 186 private:
192 int on_draw_count_; 187 int on_draw_count_;
193 }; 188 };
194 189
195 RENDERING_TEST_F(CompositorNoFrameTest); 190 RENDERING_TEST_F(CompositorNoFrameTest);
196 191
197 class SwitchOutputSurfaceIdTest : public RenderingTest { 192 class ResourceRenderingTest : public RenderingTest {
198 public: 193 public:
194 typedef std::map<uint32_t, std::map<cc::ResourceId, int>> ResourceCountMap;
boliu 2016/04/25 19:56:53 add some comments, what's the key here again?
Tobias Sargeant 2016/04/26 15:29:51 After adding the aliases, I don't think this is ne
195
196 virtual std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame(
197 int frame_number) = 0;
198
199 void StartTest() override {
200 frame_number_ = 0;
201 next_frame_ = GetFrame(frame_number_++);
boliu 2016/04/25 19:56:54 maybe factor these 4 lines in to a helper?
Tobias Sargeant 2016/04/26 15:29:51 Done.
202 if (next_frame_) {
203 browser_view_renderer_->PostInvalidate();
204 }
205 }
206
207 void WillOnDraw() override {
208 compositor_->SetHardwareFrame(next_frame_->output_surface_id,
boliu 2016/04/25 19:56:53 Hmm, might need to handle the next_frame_ being nu
209 std::move(next_frame_->frame));
210 }
211
212 void DidOnDraw(bool success) override {
213 EXPECT_TRUE(success);
214
215 next_frame_ = GetFrame(frame_number_++);
216 if (next_frame_) {
217 browser_view_renderer_->PostInvalidate();
218 } else {
219 ui_task_runner_->PostTask(FROM_HERE,
220 base::Bind(&ResourceRenderingTest::CheckResults,
221 base::Unretained(this)));
222 }
223 }
224
225 ResourceCountMap GetReturnedResourceCounts() {
226 ResourceCountMap counts;
227 content::TestSynchronousCompositor::FrameAckArray returned_resources_array;
228 compositor_->SwapReturnedResources(&returned_resources_array);
229 for (const auto& resources : returned_resources_array) {
230 for (const auto& returned_resource : resources.resources) {
231 ++counts[resources.output_surface_id][returned_resource.id];
232 }
233 }
234 return counts;
235 }
236
237 virtual void CheckResults() { EndTest(); }
boliu 2016/04/25 19:56:53 tihs should be = 0 too
Tobias Sargeant 2016/04/26 15:29:51 Done.
238
239 private:
240 std::unique_ptr<content::SynchronousCompositor::Frame> next_frame_;
241 int frame_number_;
242 };
243
244 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest {
199 struct FrameInfo { 245 struct FrameInfo {
200 uint32_t output_surface_id; 246 uint32_t output_surface_id;
201 cc::ResourceId resource_id; // Each frame contains a single resource. 247 cc::ResourceId resource_id; // Each frame contains a single resource.
202 }; 248 };
203 249
204 void StartTest() override { 250 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame(
205 last_output_surface_id_ = 0; 251 int frame_number) override {
206 FrameInfo infos[] = { 252 static const FrameInfo infos[] = {
207 // First output surface. 253 // First output surface.
208 {0u, 1u}, {0u, 1u}, {0u, 2u}, {0u, 2u}, {0u, 3u}, {0u, 3u}, {0u, 4u}, 254 {0u, 1u}, {0u, 1u}, {0u, 2u}, {0u, 2u}, {0u, 3u}, {0u, 3u}, {0u, 4u},
209 // Second output surface. 255 // Second output surface.
210 {1u, 1u}, {1u, 1u}, {1u, 2u}, {1u, 2u}, {1u, 3u}, {1u, 3u}, {1u, 4u}, 256 {1u, 1u}, {1u, 1u}, {1u, 2u}, {1u, 2u}, {1u, 3u}, {1u, 3u}, {1u, 4u},
211 }; 257 };
212 for (const auto& info : infos) { 258 static const int nFrames = int(sizeof(infos) / sizeof(infos[0]));
boliu 2016/04/25 19:56:53 nFrames is java style also base has arraysize: ht
Tobias Sargeant 2016/04/26 15:29:51 Done. I figured there was a define for this somew
213 content::SynchronousCompositor::Frame frame;
214 frame.output_surface_id = info.output_surface_id;
215 frame.frame = ConstructEmptyFrame();
216 cc::TransferableResource resource;
217 resource.id = info.resource_id;
218 frame.frame->delegated_frame_data->resource_list.push_back(resource);
219 frames_.push(std::move(frame));
220 259
221 // Keep a id -> count map for the last ouptut_surface_id. 260 if (frame_number >= nFrames) {
222 if (last_output_surface_id_ != info.output_surface_id) { 261 return nullptr;
223 expected_return_count_.clear();
224 last_output_surface_id_ = info.output_surface_id;
225 }
226 if (expected_return_count_.count(info.resource_id)) {
227 expected_return_count_[info.resource_id]++;
228 } else {
229 expected_return_count_[info.resource_id] = 1;
230 }
231 } 262 }
232 263
233 browser_view_renderer_->PostInvalidate(); 264 std::unique_ptr<content::SynchronousCompositor::Frame> frame(
265 new content::SynchronousCompositor::Frame);
266 frame->output_surface_id = infos[frame_number].output_surface_id;
267 frame->frame = ConstructFrame(infos[frame_number].resource_id);
268
269 if (last_output_surface_id_ != infos[frame_number].output_surface_id) {
270 expected_return_count_.clear();
boliu 2016/04/25 19:56:53 and then you need to count the current frame and
Tobias Sargeant 2016/04/26 15:29:51 Oops, yeah. The old code was fine, but refactoring
271 } else {
272 ++expected_return_count_[infos[frame_number].resource_id];
273 }
274 return frame;
234 } 275 }
235 276
236 void WillOnDraw() override { 277 void StartTest() override {
237 if (!frames_.empty()) { 278 last_output_surface_id_ = -1U;
238 compositor_->SetHardwareFrame(frames_.front().output_surface_id, 279 ResourceRenderingTest::StartTest();
239 std::move(frames_.front().frame));
240 }
241 } 280 }
242 281
243 void DidOnDraw(bool success) override { 282 void CheckResults() override {
244 EXPECT_TRUE(success); 283 GetCompositorFrameConsumer()->DeleteHardwareRendererOnUI();
245 if (frames_.empty()) {
246 ui_task_runner_->PostTask(
247 FROM_HERE, base::Bind(&SwitchOutputSurfaceIdTest::CheckResults,
248 base::Unretained(this)));
249 } else {
250 frames_.pop();
251 browser_view_renderer_->PostInvalidate();
252 }
253 }
254
255 void CheckResults() {
256 window_->Detach(); 284 window_->Detach();
257 window_.reset(); 285 window_.reset();
258 286
259 // Make sure resources for the last output surface are returned. 287 // Make sure resources for the last output surface are returned.
260 content::TestSynchronousCompositor::FrameAckArray returned_resources_array; 288 EXPECT_EQ(expected_return_count_,
261 compositor_->SwapReturnedResources(&returned_resources_array); 289 GetReturnedResourceCounts()[last_output_surface_id_]);
Tobias Sargeant 2016/04/25 17:00:20 Is it ok to do this? I suspect that if it fails, t
boliu 2016/04/25 19:56:54 should be fine, previous thing wasn't that useful
Tobias Sargeant 2016/04/26 15:29:51 Actually, it gives really good output: C 63.323
262 for (const auto& resources : returned_resources_array) {
263 if (resources.output_surface_id != last_output_surface_id_)
264 continue;
265 for (const auto& returned_resource : resources.resources) {
266 EXPECT_TRUE(!!expected_return_count_.count(returned_resource.id));
267 EXPECT_GE(expected_return_count_[returned_resource.id],
268 returned_resource.count);
269 expected_return_count_[returned_resource.id] -=
270 returned_resource.count;
271 if (!expected_return_count_[returned_resource.id])
272 expected_return_count_.erase(returned_resource.id);
273 }
274 }
275 EXPECT_TRUE(expected_return_count_.empty());
276
277 EndTest(); 290 EndTest();
278 } 291 }
279 292
280 private: 293 private:
281 std::queue<content::SynchronousCompositor::Frame> frames_;
282 uint32_t last_output_surface_id_; 294 uint32_t last_output_surface_id_;
283 std::map<cc::ResourceId, int> expected_return_count_; 295 std::map<cc::ResourceId, int> expected_return_count_;
boliu 2016/04/25 19:56:53 alias this
Tobias Sargeant 2016/04/26 15:29:51 Done.
284 }; 296 };
285 297
286 RENDERING_TEST_F(SwitchOutputSurfaceIdTest); 298 RENDERING_TEST_F(SwitchOutputSurfaceIdTest);
287 299
300 class RenderThreadManagerDeletionTest : public ResourceRenderingTest {
301 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame(
302 int frame_number) override {
303 if (frame_number >= 2) {
304 return nullptr;
305 }
306
307 std::unique_ptr<content::SynchronousCompositor::Frame> frame(
308 new content::SynchronousCompositor::Frame);
309 frame->output_surface_id = 0U;
310 frame->frame = ConstructFrame((cc::ResourceId)frame_number);
boliu 2016/04/25 19:56:54 static_cast c-style casts are banned
Tobias Sargeant 2016/04/26 15:29:51 Done.
311 return frame;
312 }
313
314 void CheckResults() override {
315 ResourceCountMap resource_counts;
316 resource_counts = GetReturnedResourceCounts();
boliu 2016/04/25 19:56:53 I don't think you want to assume first frame has b
Tobias Sargeant 2016/04/26 15:29:51 Won't the ReturnResourceFromParent call in OnDrawH
boliu 2016/04/26 15:47:49 Oh definitely not. In OnDrawHardware for from N+1,
317 EXPECT_EQ(resource_counts[0U].size(), 1U);
318 EXPECT_EQ(resource_counts[0U][0], 1);
319
320 render_thread_manager_.reset();
321 // Make sure resources for the last frame are returned.
322 resource_counts = GetReturnedResourceCounts();
323 EXPECT_EQ(resource_counts[0U].size(), 1U);
324 EXPECT_EQ(resource_counts[0U][1], 1);
325 EndTest();
326 }
327 };
328
329 RENDERING_TEST_F(RenderThreadManagerDeletionTest);
330
288 } // namespace android_webview 331 } // namespace android_webview
OLDNEW
« no previous file with comments | « no previous file | android_webview/browser/render_thread_manager.cc » ('j') | android_webview/browser/test/fake_window.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698