| OLD | NEW |
| 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/test/rendering_test.h" | 12 #include "android_webview/browser/test/rendering_test.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "cc/output/compositor_frame.h" | 15 #include "cc/output/compositor_frame.h" |
| 16 #include "content/public/test/test_synchronous_compositor_android.h" | 16 #include "content/public/test/test_synchronous_compositor_android.h" |
| 17 | 17 |
| 18 namespace android_webview { | 18 namespace android_webview { |
| 19 | 19 |
| 20 class SmokeTest : public RenderingTest { | 20 class SmokeTest : public RenderingTest { |
| 21 void StartTest() override { browser_view_renderer_->PostInvalidate(); } | 21 void StartTest() override { browser_view_renderer_->PostInvalidate(); } |
| 22 | 22 |
| 23 void DidDrawOnRT(RenderThreadManager* functor) override { | 23 void DidDrawOnRT() override { EndTest(); } |
| 24 EndTest(); | |
| 25 } | |
| 26 }; | 24 }; |
| 27 | 25 |
| 28 RENDERING_TEST_F(SmokeTest); | 26 RENDERING_TEST_F(SmokeTest); |
| 29 | 27 |
| 30 class ClearViewTest : public RenderingTest { | 28 class ClearViewTest : public RenderingTest { |
| 31 public: | 29 public: |
| 32 ClearViewTest() : on_draw_count_(0) {} | 30 ClearViewTest() : on_draw_count_(0) {} |
| 33 | 31 |
| 34 void StartTest() override { | 32 void StartTest() override { |
| 35 browser_view_renderer_->PostInvalidate(); | 33 browser_view_renderer_->PostInvalidate(); |
| 36 browser_view_renderer_->ClearView(); | 34 browser_view_renderer_->ClearView(); |
| 37 } | 35 } |
| 38 | 36 |
| 39 void DidOnDraw(bool success) override { | 37 void DidOnDraw(bool success) override { |
| 40 on_draw_count_++; | 38 on_draw_count_++; |
| 41 if (on_draw_count_ == 1) { | 39 if (on_draw_count_ == 1) { |
| 42 // First OnDraw should be skipped due to ClearView. | 40 // First OnDraw should be skipped due to ClearView. |
| 43 EXPECT_FALSE(success); | 41 EXPECT_FALSE(success); |
| 44 browser_view_renderer_->DidUpdateContent(); // Unset ClearView. | 42 browser_view_renderer_->DidUpdateContent(); // Unset ClearView. |
| 45 browser_view_renderer_->PostInvalidate(); | 43 browser_view_renderer_->PostInvalidate(); |
| 46 } else { | 44 } else { |
| 47 // Following OnDraws should succeed. | 45 // Following OnDraws should succeed. |
| 48 EXPECT_TRUE(success); | 46 EXPECT_TRUE(success); |
| 49 } | 47 } |
| 50 } | 48 } |
| 51 | 49 |
| 52 void DidDrawOnRT(RenderThreadManager* functor) override { | 50 void DidDrawOnRT() override { EndTest(); } |
| 53 EndTest(); | 51 |
| 54 } | |
| 55 private: | 52 private: |
| 56 int on_draw_count_; | 53 int on_draw_count_; |
| 57 }; | 54 }; |
| 58 | 55 |
| 59 RENDERING_TEST_F(ClearViewTest); | 56 RENDERING_TEST_F(ClearViewTest); |
| 60 | 57 |
| 61 class TestAnimateInAndOutOfScreen : public RenderingTest { | 58 class TestAnimateInAndOutOfScreen : public RenderingTest { |
| 62 public: | 59 public: |
| 63 TestAnimateInAndOutOfScreen() : on_draw_count_(0), draw_gl_count_on_rt_(0) {} | 60 TestAnimateInAndOutOfScreen() : on_draw_count_(0), draw_gl_count_on_rt_(0) {} |
| 64 | 61 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 80 // draw constraints of BVR is updated to initial constraints. | 77 // draw constraints of BVR is updated to initial constraints. |
| 81 if (on_draw_count_ == 1 || on_draw_count_ == 2) | 78 if (on_draw_count_ == 1 || on_draw_count_ == 2) |
| 82 browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect()); | 79 browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect()); |
| 83 } | 80 } |
| 84 | 81 |
| 85 void DidOnDraw(bool success) override { | 82 void DidOnDraw(bool success) override { |
| 86 EXPECT_TRUE(success); | 83 EXPECT_TRUE(success); |
| 87 on_draw_count_++; | 84 on_draw_count_++; |
| 88 } | 85 } |
| 89 | 86 |
| 90 bool WillDrawOnRT(RenderThreadManager* functor, | 87 bool WillDrawOnRT(AwDrawGLInfo* draw_info) override { |
| 91 AwDrawGLInfo* draw_info) override { | |
| 92 if (draw_gl_count_on_rt_ == 1) { | 88 if (draw_gl_count_on_rt_ == 1) { |
| 93 draw_gl_count_on_rt_++; | 89 draw_gl_count_on_rt_++; |
| 94 ui_task_runner_->PostTask( | 90 ui_task_runner_->PostTask( |
| 95 FROM_HERE, | 91 FROM_HERE, |
| 96 base::Bind(&RenderingTest::PostInvalidate, base::Unretained(this))); | 92 base::Bind(&RenderingTest::PostInvalidate, base::Unretained(this))); |
| 97 return false; | 93 return false; |
| 98 } | 94 } |
| 99 | 95 |
| 100 draw_info->width = window_->surface_size().width(); | 96 draw_info->width = window_->surface_size().width(); |
| 101 draw_info->height = window_->surface_size().height(); | 97 draw_info->height = window_->surface_size().height(); |
| 102 draw_info->is_layer = false; | 98 draw_info->is_layer = false; |
| 103 | 99 |
| 104 gfx::Transform transform; | 100 gfx::Transform transform; |
| 105 if (draw_gl_count_on_rt_ == 0) | 101 if (draw_gl_count_on_rt_ == 0) |
| 106 transform = new_constraints_.transform; | 102 transform = new_constraints_.transform; |
| 107 | 103 |
| 108 transform.matrix().asColMajorf(draw_info->transform); | 104 transform.matrix().asColMajorf(draw_info->transform); |
| 109 return true; | 105 return true; |
| 110 } | 106 } |
| 111 | 107 |
| 112 void DidDrawOnRT(RenderThreadManager* functor) override { | 108 void DidDrawOnRT() override { draw_gl_count_on_rt_++; } |
| 113 draw_gl_count_on_rt_++; | |
| 114 } | |
| 115 | 109 |
| 116 bool DrawConstraintsEquals( | 110 bool DrawConstraintsEquals( |
| 117 const ParentCompositorDrawConstraints& constraints1, | 111 const ParentCompositorDrawConstraints& constraints1, |
| 118 const ParentCompositorDrawConstraints& constraints2) { | 112 const ParentCompositorDrawConstraints& constraints2) { |
| 119 if (constraints1.is_layer != constraints2.is_layer || | 113 if (constraints1.is_layer != constraints2.is_layer || |
| 120 constraints1.transform != constraints2.transform) | 114 constraints1.transform != constraints2.transform) |
| 121 return false; | 115 return false; |
| 122 | 116 |
| 123 return !constraints1.is_layer || | 117 return !constraints1.is_layer || |
| 124 constraints1.surface_rect_empty == constraints2.surface_rect_empty; | 118 constraints1.surface_rect_empty == constraints2.surface_rect_empty; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 ui_task_runner_->PostTask( | 240 ui_task_runner_->PostTask( |
| 247 FROM_HERE, base::Bind(&SwitchOutputSurfaceIdTest::CheckResults, | 241 FROM_HERE, base::Bind(&SwitchOutputSurfaceIdTest::CheckResults, |
| 248 base::Unretained(this))); | 242 base::Unretained(this))); |
| 249 } else { | 243 } else { |
| 250 frames_.pop(); | 244 frames_.pop(); |
| 251 browser_view_renderer_->PostInvalidate(); | 245 browser_view_renderer_->PostInvalidate(); |
| 252 } | 246 } |
| 253 } | 247 } |
| 254 | 248 |
| 255 void CheckResults() { | 249 void CheckResults() { |
| 250 GetCompositorFrameConsumer()->DeleteHardwareRendererOnUI(); |
| 256 window_->Detach(); | 251 window_->Detach(); |
| 257 window_.reset(); | 252 window_.reset(); |
| 258 | 253 |
| 259 // Make sure resources for the last output surface are returned. | 254 // Make sure resources for the last output surface are returned. |
| 260 content::TestSynchronousCompositor::FrameAckArray returned_resources_array; | 255 content::TestSynchronousCompositor::FrameAckArray returned_resources_array; |
| 261 compositor_->SwapReturnedResources(&returned_resources_array); | 256 compositor_->SwapReturnedResources(&returned_resources_array); |
| 262 for (const auto& resources : returned_resources_array) { | 257 for (const auto& resources : returned_resources_array) { |
| 263 if (resources.output_surface_id != last_output_surface_id_) | 258 if (resources.output_surface_id != last_output_surface_id_) |
| 264 continue; | 259 continue; |
| 265 for (const auto& returned_resource : resources.resources) { | 260 for (const auto& returned_resource : resources.resources) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 279 | 274 |
| 280 private: | 275 private: |
| 281 std::queue<content::SynchronousCompositor::Frame> frames_; | 276 std::queue<content::SynchronousCompositor::Frame> frames_; |
| 282 uint32_t last_output_surface_id_; | 277 uint32_t last_output_surface_id_; |
| 283 std::map<cc::ResourceId, int> expected_return_count_; | 278 std::map<cc::ResourceId, int> expected_return_count_; |
| 284 }; | 279 }; |
| 285 | 280 |
| 286 RENDERING_TEST_F(SwitchOutputSurfaceIdTest); | 281 RENDERING_TEST_F(SwitchOutputSurfaceIdTest); |
| 287 | 282 |
| 288 } // namespace android_webview | 283 } // namespace android_webview |
| OLD | NEW |