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
3 // found in the LICENSE file.
5 #include "android_webview/browser/browser_view_renderer.h"
6 #include "android_webview/browser/child_frame.h"
7 #include "android_webview/browser/test/rendering_test.h"
9 namespace android_webview
{
11 class SmokeTest
: public RenderingTest
{
12 void StartTest() override
{
13 browser_view_renderer_
->SetContinuousInvalidate(true);
16 void WillOnDraw() override
{
17 browser_view_renderer_
->SetContinuousInvalidate(false);
20 void DidDrawOnRT(SharedRendererState
* functor
) override
{
25 RENDERING_TEST_F(SmokeTest
);
27 class ClearViewTest
: public RenderingTest
{
29 ClearViewTest() : on_draw_count_(0u) {}
31 void StartTest() override
{
32 browser_view_renderer_
->SetContinuousInvalidate(true);
33 browser_view_renderer_
->ClearView();
36 void WillOnDraw() override
{
38 if (on_draw_count_
== 2u) {
39 browser_view_renderer_
->SetContinuousInvalidate(false);
43 void DidOnDraw(bool success
) override
{
44 if (on_draw_count_
== 1u) {
45 // First OnDraw should be skipped due to ClearView.
46 EXPECT_FALSE(success
);
47 browser_view_renderer_
->DidUpdateContent(); // Unset ClearView.
49 // Following OnDraws should succeed.
54 void DidDrawOnRT(SharedRendererState
* functor
) override
{
58 size_t on_draw_count_
;
61 RENDERING_TEST_F(ClearViewTest
);
63 class TestAnimateInAndOutOfScreen
: public RenderingTest
{
65 TestAnimateInAndOutOfScreen()
66 : on_draw_count_(0u), draw_gl_count_on_rt_(0u) {}
68 void StartTest() override
{
69 new_constraints_
= ParentCompositorDrawConstraints(
70 false, gfx::Transform(), gfx::Rect(window_
->surface_size()));
71 new_constraints_
.transform
.Scale(2.0, 2.0);
72 browser_view_renderer_
->SetContinuousInvalidate(true);
75 void WillOnDraw() override
{
76 browser_view_renderer_
->SetContinuousInvalidate(false);
77 // Step 0: A single onDraw on screen. The parent draw constraints
78 // of the BVR will updated to be the initial constraints.
79 // Step 1: A single onDrraw off screen. The parent draw constraints of the
80 // BVR will be updated to the new constraints.
81 // Step 2: This onDraw is to introduce the DrawGL that animates the
82 // webview onto the screen on render thread. End the test when the parent
83 // draw constraints of BVR is updated to initial constraints.
84 if (on_draw_count_
== 1u || on_draw_count_
== 2u)
85 browser_view_renderer_
->PrepareToDraw(gfx::Vector2d(), gfx::Rect());
88 void DidOnDraw(bool success
) override
{
93 bool WillDrawOnRT(SharedRendererState
* functor
,
94 AwDrawGLInfo
* draw_info
) override
{
95 if (draw_gl_count_on_rt_
== 1u) {
96 draw_gl_count_on_rt_
++;
97 ui_proxy_
->PostTask(FROM_HERE
, base::Bind(&RenderingTest::PostInvalidate
,
98 base::Unretained(this)));
102 draw_info
->width
= window_
->surface_size().width();
103 draw_info
->height
= window_
->surface_size().height();
104 draw_info
->is_layer
= false;
106 gfx::Transform transform
;
107 if (draw_gl_count_on_rt_
== 0u)
108 transform
= new_constraints_
.transform
;
110 transform
.matrix().asColMajorf(draw_info
->transform
);
114 void DidDrawOnRT(SharedRendererState
* functor
) override
{
115 draw_gl_count_on_rt_
++;
118 bool DrawConstraintsEquals(
119 const ParentCompositorDrawConstraints
& constraints1
,
120 const ParentCompositorDrawConstraints
& constraints2
) {
121 if (constraints1
.is_layer
!= constraints2
.is_layer
||
122 constraints1
.transform
!= constraints2
.transform
)
125 return !constraints1
.is_layer
||
126 constraints1
.surface_rect
== constraints2
.surface_rect
;
129 void ParentDrawConstraintsUpdated(
130 const ParentCompositorDrawConstraints
& constraints
) override
{
131 switch (on_draw_count_
) {
133 EXPECT_TRUE(DrawConstraintsEquals(constraints
, new_constraints_
));
136 EXPECT_TRUE(DrawConstraintsEquals(constraints
, initial_constraints_
));
139 // There will be a following 4th onDraw. But the hardware renderer won't
140 // post back the draw constraints in DrawGL because the constraints
148 size_t on_draw_count_
;
149 size_t draw_gl_count_on_rt_
;
150 ParentCompositorDrawConstraints initial_constraints_
;
151 ParentCompositorDrawConstraints new_constraints_
;
154 RENDERING_TEST_F(TestAnimateInAndOutOfScreen
);
156 } // namespace android_webview