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

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

Issue 1943963003: WIP Handle AwContents needing multiple live functors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from PS17 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/render_thread_manager.h"
13 #include "android_webview/browser/test/rendering_test.h" 13 #include "android_webview/browser/test/rendering_test.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/threading/thread_task_runner_handle.h"
16 #include "cc/output/compositor_frame.h" 17 #include "cc/output/compositor_frame.h"
17 #include "content/public/test/test_synchronous_compositor_android.h" 18 #include "content/public/test/test_synchronous_compositor_android.h"
18 19
19 namespace android_webview { 20 namespace android_webview {
20 21
21 class SmokeTest : public RenderingTest { 22 class SmokeTest : public RenderingTest {
22 void StartTest() override { browser_view_renderer_->PostInvalidate(); } 23 void StartTest() override { browser_view_renderer_->PostInvalidate(); }
23 24
24 void DidDrawOnRT() override { EndTest(); } 25 void DidDrawOnRT() override { EndTest(); }
25 }; 26 };
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return false; 117 return false;
117 118
118 return !constraints1.is_layer || 119 return !constraints1.is_layer ||
119 constraints1.surface_rect_empty == constraints2.surface_rect_empty; 120 constraints1.surface_rect_empty == constraints2.surface_rect_empty;
120 } 121 }
121 122
122 void OnParentDrawConstraintsUpdated() override { 123 void OnParentDrawConstraintsUpdated() override {
123 ParentCompositorDrawConstraints constraints = 124 ParentCompositorDrawConstraints constraints =
124 GetCompositorFrameConsumer()->GetParentDrawConstraintsOnUI(); 125 GetCompositorFrameConsumer()->GetParentDrawConstraintsOnUI();
125 switch (on_draw_count_) { 126 switch (on_draw_count_) {
127 case 0u:
128 // This OnParentDrawConstraintsUpdated is generated by
129 // connecting the compositor frame consumer to the producer.
130 break;
126 case 1u: 131 case 1u:
127 EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_)); 132 EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_));
128 break; 133 break;
129 case 3u: 134 case 3u:
130 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_)); 135 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_));
131 EndTest(); 136 EndTest();
132 break; 137 break;
133 // There will be a following 4th onDraw. But the hardware renderer won't 138 // There will be a following 4th onDraw. But the hardware renderer won't
134 // post back the draw constraints in DrawGL because the constraints 139 // post back the draw constraints in DrawGL because the constraints
135 // don't change. 140 // don't change.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest { 255 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest {
251 struct FrameInfo { 256 struct FrameInfo {
252 uint32_t output_surface_id; 257 uint32_t output_surface_id;
253 cc::ResourceId resource_id; // Each frame contains a single resource. 258 cc::ResourceId resource_id; // Each frame contains a single resource.
254 }; 259 };
255 260
256 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame( 261 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame(
257 int frame_number) override { 262 int frame_number) override {
258 static const FrameInfo infos[] = { 263 static const FrameInfo infos[] = {
259 // First output surface. 264 // First output surface.
260 {0u, 1u}, 265 {0u, 1u}, {0u, 1u}, {0u, 2u}, {0u, 2u}, {0u, 3u}, {0u, 3u}, {0u, 4u},
261 {0u, 1u},
262 {0u, 2u},
263 {0u, 2u},
264 {0u, 3u},
265 {0u, 3u},
266 {0u, 4u},
267 // Second output surface. 266 // Second output surface.
268 {1u, 1u}, 267 {1u, 1u}, {1u, 1u}, {1u, 2u}, {1u, 2u}, {1u, 3u}, {1u, 3u}, {1u, 4u},
269 {1u, 1u},
270 {1u, 2u},
271 {1u, 2u},
272 {1u, 3u},
273 {1u, 3u},
274 {1u, 4u},
275 }; 268 };
276 if (frame_number >= static_cast<int>(arraysize(infos))) { 269 if (frame_number >= static_cast<int>(arraysize(infos))) {
277 return nullptr; 270 return nullptr;
278 } 271 }
279 272
280 std::unique_ptr<content::SynchronousCompositor::Frame> frame( 273 std::unique_ptr<content::SynchronousCompositor::Frame> frame(
281 new content::SynchronousCompositor::Frame); 274 new content::SynchronousCompositor::Frame);
282 frame->output_surface_id = infos[frame_number].output_surface_id; 275 frame->output_surface_id = infos[frame_number].output_surface_id;
283 frame->frame = ConstructFrame(infos[frame_number].resource_id); 276 frame->frame = ConstructFrame(infos[frame_number].resource_id);
284 277
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 std::unique_ptr<content::SynchronousCompositor::Frame> frame( 320 std::unique_ptr<content::SynchronousCompositor::Frame> frame(
328 new content::SynchronousCompositor::Frame); 321 new content::SynchronousCompositor::Frame);
329 frame->output_surface_id = output_surface_id; 322 frame->output_surface_id = output_surface_id;
330 frame->frame = ConstructFrame(resource_id); 323 frame->frame = ConstructFrame(resource_id);
331 ++expected_return_count_[output_surface_id][resource_id]; 324 ++expected_return_count_[output_surface_id][resource_id];
332 return frame; 325 return frame;
333 } 326 }
334 327
335 void CheckResults() override { 328 void CheckResults() override {
336 OutputSurfaceResourceCountMap resource_counts; 329 OutputSurfaceResourceCountMap resource_counts;
337 render_thread_manager_.reset(); 330 functor_.reset();
338 // Make sure resources for the last frame are returned. 331 // Make sure resources for the last frame are returned.
339 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts()); 332 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts());
340 EndTest(); 333 EndTest();
341 } 334 }
342 335
343 private: 336 private:
344 OutputSurfaceResourceCountMap expected_return_count_; 337 OutputSurfaceResourceCountMap expected_return_count_;
345 }; 338 };
346 339
347 RENDERING_TEST_F(RenderThreadManagerDeletionTest); 340 RENDERING_TEST_F(RenderThreadManagerDeletionTest);
348 341
342 class RenderThreadManagerSwitchTest : public ResourceRenderingTest {
343 std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame(
344 int frame_number) override {
345 switch (frame_number) {
346 case 0: {
347 // Draw a frame with initial RTM.
348 break;
349 }
350 case 1: {
351 // Switch to new RTM.
352 std::unique_ptr<FakeFunctor> functor(new FakeFunctor);
353 functor->Init(window_.get(),
354 base::WrapUnique(new RenderThreadManager(
355 functor.get(), base::ThreadTaskRunnerHandle::Get())));
356 browser_view_renderer_->SetCurrentCompositorFrameConsumer(
357 functor->GetCompositorFrameConsumer());
358 saved_functor_ = std::move(functor_);
359 functor_ = std::move(functor);
360 break;
361 }
362 case 2: {
363 // Draw a frame with the new RTM, but also redraw the initial RTM.
364 window_->RequestDrawGL(saved_functor_.get());
365 break;
366 }
367 case 3: {
368 // Switch back to the initial RTM, allowing the new RTM to be destroyed.
369 functor_ = std::move(saved_functor_);
370 browser_view_renderer_->SetCurrentCompositorFrameConsumer(
371 functor_->GetCompositorFrameConsumer());
372 break;
373 }
374 default:
375 return nullptr;
376 }
377
378 const uint32_t output_surface_id = 0u;
379 const cc::ResourceId resource_id =
380 static_cast<cc::ResourceId>(frame_number);
381
382 std::unique_ptr<content::SynchronousCompositor::Frame> frame(
383 new content::SynchronousCompositor::Frame);
384 frame->output_surface_id = output_surface_id;
385 frame->frame = ConstructFrame(resource_id);
386 ++expected_return_count_[output_surface_id][resource_id];
387 return frame;
388 }
389
390 void CheckResults() override {
391 OutputSurfaceResourceCountMap resource_counts;
392 functor_.reset();
393 // Make sure resources for all frames are returned.
394 EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts());
395 EndTest();
396 }
397
398 private:
399 std::unique_ptr<FakeFunctor> saved_functor_;
400 OutputSurfaceResourceCountMap expected_return_count_;
401 };
402
403 RENDERING_TEST_F(RenderThreadManagerSwitchTest);
404
349 } // namespace android_webview 405 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/browser_view_renderer.cc ('k') | android_webview/browser/compositor_frame_consumer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698