| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "cc/quads/texture_draw_quad.h" | 21 #include "cc/quads/texture_draw_quad.h" |
| 22 #include "cc/resources/resource_provider.h" | 22 #include "cc/resources/resource_provider.h" |
| 23 #include "cc/test/fake_impl_task_runner_provider.h" | 23 #include "cc/test/fake_impl_task_runner_provider.h" |
| 24 #include "cc/test/fake_layer_tree_host_impl.h" | 24 #include "cc/test/fake_layer_tree_host_impl.h" |
| 25 #include "cc/test/fake_output_surface.h" | 25 #include "cc/test/fake_output_surface.h" |
| 26 #include "cc/test/fake_output_surface_client.h" | 26 #include "cc/test/fake_output_surface_client.h" |
| 27 #include "cc/test/fake_renderer_client.h" | 27 #include "cc/test/fake_renderer_client.h" |
| 28 #include "cc/test/fake_resource_provider.h" | 28 #include "cc/test/fake_resource_provider.h" |
| 29 #include "cc/test/pixel_test.h" | 29 #include "cc/test/pixel_test.h" |
| 30 #include "cc/test/render_pass_test_utils.h" | 30 #include "cc/test/render_pass_test_utils.h" |
| 31 #include "cc/test/test_gles2_interface.h" |
| 31 #include "cc/test/test_shared_bitmap_manager.h" | 32 #include "cc/test/test_shared_bitmap_manager.h" |
| 32 #include "cc/test/test_web_graphics_context_3d.h" | 33 #include "cc/test/test_web_graphics_context_3d.h" |
| 33 #include "gpu/GLES2/gl2extchromium.h" | 34 #include "gpu/GLES2/gl2extchromium.h" |
| 34 #include "gpu/command_buffer/client/context_support.h" | 35 #include "gpu/command_buffer/client/context_support.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include "third_party/skia/include/core/SkImageFilter.h" | 38 #include "third_party/skia/include/core/SkImageFilter.h" |
| 38 #include "third_party/skia/include/core/SkMatrix.h" | 39 #include "third_party/skia/include/core/SkMatrix.h" |
| 39 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" | 40 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" |
| 40 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | 41 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" |
| (...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 first_render_pass); | 1017 first_render_pass); |
| 1017 | 1018 |
| 1018 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); | 1019 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); |
| 1019 DrawFrame(&renderer, viewport_rect); | 1020 DrawFrame(&renderer, viewport_rect); |
| 1020 | 1021 |
| 1021 // In multiple render passes all but the root pass should clear the | 1022 // In multiple render passes all but the root pass should clear the |
| 1022 // framebuffer. | 1023 // framebuffer. |
| 1023 Mock::VerifyAndClearExpectations(&mock_context); | 1024 Mock::VerifyAndClearExpectations(&mock_context); |
| 1024 } | 1025 } |
| 1025 | 1026 |
| 1026 class ScissorTestOnClearCheckingContext : public TestWebGraphicsContext3D { | 1027 class ScissorTestOnClearCheckingGLES2Interface : public TestGLES2Interface { |
| 1027 public: | 1028 public: |
| 1028 ScissorTestOnClearCheckingContext() : scissor_enabled_(false) {} | 1029 ScissorTestOnClearCheckingGLES2Interface() = default; |
| 1029 | 1030 |
| 1030 void clear(GLbitfield) override { EXPECT_FALSE(scissor_enabled_); } | 1031 void Clear(GLbitfield) override { EXPECT_FALSE(scissor_enabled_); } |
| 1031 | 1032 |
| 1032 void enable(GLenum cap) override { | 1033 void Enable(GLenum cap) override { |
| 1033 if (cap == GL_SCISSOR_TEST) | 1034 if (cap == GL_SCISSOR_TEST) |
| 1034 scissor_enabled_ = true; | 1035 scissor_enabled_ = true; |
| 1035 } | 1036 } |
| 1036 | 1037 |
| 1037 void disable(GLenum cap) override { | 1038 void Disable(GLenum cap) override { |
| 1038 if (cap == GL_SCISSOR_TEST) | 1039 if (cap == GL_SCISSOR_TEST) |
| 1039 scissor_enabled_ = false; | 1040 scissor_enabled_ = false; |
| 1040 } | 1041 } |
| 1041 | 1042 |
| 1042 private: | 1043 private: |
| 1043 bool scissor_enabled_; | 1044 bool scissor_enabled_ = false; |
| 1044 }; | 1045 }; |
| 1045 | 1046 |
| 1046 TEST_F(GLRendererTest, ScissorTestWhenClearing) { | 1047 TEST_F(GLRendererTest, ScissorTestWhenClearing) { |
| 1047 std::unique_ptr<ScissorTestOnClearCheckingContext> context_owned( | 1048 auto gl_owned = base::MakeUnique<ScissorTestOnClearCheckingGLES2Interface>(); |
| 1048 new ScissorTestOnClearCheckingContext); | |
| 1049 | 1049 |
| 1050 FakeOutputSurfaceClient output_surface_client; | 1050 FakeOutputSurfaceClient output_surface_client; |
| 1051 std::unique_ptr<OutputSurface> output_surface( | 1051 std::unique_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 1052 FakeOutputSurface::Create3d(std::move(context_owned))); | 1052 TestContextProvider::Create(std::move(gl_owned)))); |
| 1053 CHECK(output_surface->BindToClient(&output_surface_client)); | 1053 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1054 | 1054 |
| 1055 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( | 1055 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 1056 new TestSharedBitmapManager()); | 1056 new TestSharedBitmapManager()); |
| 1057 std::unique_ptr<ResourceProvider> resource_provider = | 1057 std::unique_ptr<ResourceProvider> resource_provider = |
| 1058 FakeResourceProvider::Create(output_surface.get(), | 1058 FakeResourceProvider::Create(output_surface.get(), |
| 1059 shared_bitmap_manager.get()); | 1059 shared_bitmap_manager.get()); |
| 1060 | 1060 |
| 1061 RendererSettings settings; | 1061 RendererSettings settings; |
| 1062 FakeRendererClient renderer_client; | 1062 FakeRendererClient renderer_client; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1088 gfx::Transform()); | 1088 gfx::Transform()); |
| 1089 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); | 1089 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); |
| 1090 | 1090 |
| 1091 AddRenderPassQuad(root_pass, child_pass); | 1091 AddRenderPassQuad(root_pass, child_pass); |
| 1092 AddRenderPassQuad(child_pass, grand_child_pass); | 1092 AddRenderPassQuad(child_pass, grand_child_pass); |
| 1093 | 1093 |
| 1094 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); | 1094 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); |
| 1095 DrawFrame(&renderer, viewport_rect); | 1095 DrawFrame(&renderer, viewport_rect); |
| 1096 } | 1096 } |
| 1097 | 1097 |
| 1098 class DiscardCheckingContext : public TestWebGraphicsContext3D { | 1098 class DiscardCheckingGLES2Interface : public TestGLES2Interface { |
| 1099 public: | 1099 public: |
| 1100 DiscardCheckingContext() : discarded_(0) { | 1100 DiscardCheckingGLES2Interface() = default; |
| 1101 set_have_post_sub_buffer(true); | 1101 |
| 1102 set_have_discard_framebuffer(true); | 1102 void InitializeTestContext(TestWebGraphicsContext3D* context) override { |
| 1103 context->set_have_post_sub_buffer(true); |
| 1104 context->set_have_discard_framebuffer(true); |
| 1103 } | 1105 } |
| 1104 | 1106 |
| 1105 void discardFramebufferEXT(GLenum target, | 1107 void DiscardFramebufferEXT(GLenum target, |
| 1106 GLsizei numAttachments, | 1108 GLsizei numAttachments, |
| 1107 const GLenum* attachments) override { | 1109 const GLenum* attachments) override { |
| 1108 ++discarded_; | 1110 ++discarded_; |
| 1109 } | 1111 } |
| 1110 | 1112 |
| 1111 int discarded() const { return discarded_; } | 1113 int discarded() const { return discarded_; } |
| 1112 void reset() { discarded_ = 0; } | 1114 void reset_discarded() { discarded_ = 0; } |
| 1113 | 1115 |
| 1114 private: | 1116 private: |
| 1115 int discarded_; | 1117 int discarded_ = 0; |
| 1116 }; | 1118 }; |
| 1117 | 1119 |
| 1118 class NonReshapableOutputSurface : public FakeOutputSurface { | 1120 class NonReshapableOutputSurface : public FakeOutputSurface { |
| 1119 public: | 1121 public: |
| 1120 explicit NonReshapableOutputSurface( | 1122 explicit NonReshapableOutputSurface(std::unique_ptr<TestGLES2Interface> gl) |
| 1121 std::unique_ptr<TestWebGraphicsContext3D> context3d) | 1123 : FakeOutputSurface(TestContextProvider::Create(std::move(gl)), |
| 1122 : FakeOutputSurface(TestContextProvider::Create(std::move(context3d)), | |
| 1123 nullptr, | 1124 nullptr, |
| 1124 false) { | 1125 false) { |
| 1125 surface_size_ = gfx::Size(500, 500); | 1126 surface_size_ = gfx::Size(500, 500); |
| 1126 } | 1127 } |
| 1127 void Reshape(const gfx::Size& size, | 1128 void Reshape(const gfx::Size& size, |
| 1128 float scale_factor, | 1129 float scale_factor, |
| 1129 const gfx::ColorSpace& color_space, | 1130 const gfx::ColorSpace& color_space, |
| 1130 bool has_alpha) override {} | 1131 bool has_alpha) override {} |
| 1131 void set_fixed_size(const gfx::Size& size) { surface_size_ = size; } | 1132 void set_fixed_size(const gfx::Size& size) { surface_size_ = size; } |
| 1132 }; | 1133 }; |
| 1133 | 1134 |
| 1134 TEST_F(GLRendererTest, NoDiscardOnPartialUpdates) { | 1135 TEST_F(GLRendererTest, NoDiscardOnPartialUpdates) { |
| 1135 std::unique_ptr<DiscardCheckingContext> context_owned( | 1136 auto gl_owned = base::MakeUnique<DiscardCheckingGLES2Interface>(); |
| 1136 new DiscardCheckingContext); | 1137 auto* gl = gl_owned.get(); |
| 1137 DiscardCheckingContext* context = context_owned.get(); | |
| 1138 | 1138 |
| 1139 FakeOutputSurfaceClient output_surface_client; | 1139 FakeOutputSurfaceClient output_surface_client; |
| 1140 std::unique_ptr<NonReshapableOutputSurface> output_surface( | 1140 std::unique_ptr<NonReshapableOutputSurface> output_surface( |
| 1141 new NonReshapableOutputSurface(std::move(context_owned))); | 1141 new NonReshapableOutputSurface(std::move(gl_owned))); |
| 1142 CHECK(output_surface->BindToClient(&output_surface_client)); | 1142 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1143 output_surface->set_fixed_size(gfx::Size(100, 100)); | 1143 output_surface->set_fixed_size(gfx::Size(100, 100)); |
| 1144 | 1144 |
| 1145 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( | 1145 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 1146 new TestSharedBitmapManager()); | 1146 new TestSharedBitmapManager()); |
| 1147 std::unique_ptr<ResourceProvider> resource_provider = | 1147 std::unique_ptr<ResourceProvider> resource_provider = |
| 1148 FakeResourceProvider::Create(output_surface.get(), | 1148 FakeResourceProvider::Create(output_surface.get(), |
| 1149 shared_bitmap_manager.get()); | 1149 shared_bitmap_manager.get()); |
| 1150 | 1150 |
| 1151 RendererSettings settings; | 1151 RendererSettings settings; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1164 // Partial frame, should not discard. | 1164 // Partial frame, should not discard. |
| 1165 RenderPassId root_pass_id(1, 0); | 1165 RenderPassId root_pass_id(1, 0); |
| 1166 RenderPass* root_pass = | 1166 RenderPass* root_pass = |
| 1167 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, | 1167 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, |
| 1168 viewport_rect, gfx::Transform()); | 1168 viewport_rect, gfx::Transform()); |
| 1169 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); | 1169 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); |
| 1170 root_pass->damage_rect = gfx::Rect(2, 2, 3, 3); | 1170 root_pass->damage_rect = gfx::Rect(2, 2, 3, 3); |
| 1171 | 1171 |
| 1172 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); | 1172 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); |
| 1173 DrawFrame(&renderer, viewport_rect, clip_rect); | 1173 DrawFrame(&renderer, viewport_rect, clip_rect); |
| 1174 EXPECT_EQ(0, context->discarded()); | 1174 EXPECT_EQ(0, gl->discarded()); |
| 1175 context->reset(); | 1175 gl->reset_discarded(); |
| 1176 } | 1176 } |
| 1177 { | 1177 { |
| 1178 // Full frame, should discard. | 1178 // Full frame, should discard. |
| 1179 RenderPassId root_pass_id(1, 0); | 1179 RenderPassId root_pass_id(1, 0); |
| 1180 RenderPass* root_pass = | 1180 RenderPass* root_pass = |
| 1181 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, | 1181 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, |
| 1182 viewport_rect, gfx::Transform()); | 1182 viewport_rect, gfx::Transform()); |
| 1183 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); | 1183 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); |
| 1184 root_pass->damage_rect = root_pass->output_rect; | 1184 root_pass->damage_rect = root_pass->output_rect; |
| 1185 | 1185 |
| 1186 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); | 1186 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); |
| 1187 DrawFrame(&renderer, viewport_rect, clip_rect); | 1187 DrawFrame(&renderer, viewport_rect, clip_rect); |
| 1188 EXPECT_EQ(1, context->discarded()); | 1188 EXPECT_EQ(1, gl->discarded()); |
| 1189 context->reset(); | 1189 gl->reset_discarded(); |
| 1190 } | 1190 } |
| 1191 { | 1191 { |
| 1192 // Full frame, external scissor is set, should not discard. | 1192 // Full frame, external scissor is set, should not discard. |
| 1193 output_surface->set_has_external_stencil_test(true); | 1193 output_surface->set_has_external_stencil_test(true); |
| 1194 RenderPassId root_pass_id(1, 0); | 1194 RenderPassId root_pass_id(1, 0); |
| 1195 RenderPass* root_pass = | 1195 RenderPass* root_pass = |
| 1196 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, | 1196 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, |
| 1197 viewport_rect, gfx::Transform()); | 1197 viewport_rect, gfx::Transform()); |
| 1198 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); | 1198 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); |
| 1199 root_pass->damage_rect = root_pass->output_rect; | 1199 root_pass->damage_rect = root_pass->output_rect; |
| 1200 root_pass->has_transparent_background = false; | 1200 root_pass->has_transparent_background = false; |
| 1201 | 1201 |
| 1202 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); | 1202 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); |
| 1203 DrawFrame(&renderer, viewport_rect, clip_rect); | 1203 DrawFrame(&renderer, viewport_rect, clip_rect); |
| 1204 EXPECT_EQ(0, context->discarded()); | 1204 EXPECT_EQ(0, gl->discarded()); |
| 1205 context->reset(); | 1205 gl->reset_discarded(); |
| 1206 output_surface->set_has_external_stencil_test(false); | 1206 output_surface->set_has_external_stencil_test(false); |
| 1207 } | 1207 } |
| 1208 { | 1208 { |
| 1209 // Full frame, clipped, should not discard. | 1209 // Full frame, clipped, should not discard. |
| 1210 clip_rect = gfx::Rect(10, 10, 10, 10); | 1210 clip_rect = gfx::Rect(10, 10, 10, 10); |
| 1211 RenderPassId root_pass_id(1, 0); | 1211 RenderPassId root_pass_id(1, 0); |
| 1212 RenderPass* root_pass = | 1212 RenderPass* root_pass = |
| 1213 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, | 1213 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, |
| 1214 viewport_rect, gfx::Transform()); | 1214 viewport_rect, gfx::Transform()); |
| 1215 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); | 1215 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); |
| 1216 root_pass->damage_rect = root_pass->output_rect; | 1216 root_pass->damage_rect = root_pass->output_rect; |
| 1217 | 1217 |
| 1218 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); | 1218 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); |
| 1219 DrawFrame(&renderer, viewport_rect, clip_rect); | 1219 DrawFrame(&renderer, viewport_rect, clip_rect); |
| 1220 EXPECT_EQ(0, context->discarded()); | 1220 EXPECT_EQ(0, gl->discarded()); |
| 1221 context->reset(); | 1221 gl->reset_discarded(); |
| 1222 } | 1222 } |
| 1223 { | 1223 { |
| 1224 // Full frame, doesn't cover the surface, should not discard. | 1224 // Full frame, doesn't cover the surface, should not discard. |
| 1225 viewport_rect = gfx::Rect(10, 10, 10, 10); | 1225 viewport_rect = gfx::Rect(10, 10, 10, 10); |
| 1226 RenderPassId root_pass_id(1, 0); | 1226 RenderPassId root_pass_id(1, 0); |
| 1227 RenderPass* root_pass = | 1227 RenderPass* root_pass = |
| 1228 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, | 1228 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, |
| 1229 viewport_rect, gfx::Transform()); | 1229 viewport_rect, gfx::Transform()); |
| 1230 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); | 1230 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); |
| 1231 root_pass->damage_rect = root_pass->output_rect; | 1231 root_pass->damage_rect = root_pass->output_rect; |
| 1232 | 1232 |
| 1233 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); | 1233 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); |
| 1234 DrawFrame(&renderer, viewport_rect, clip_rect); | 1234 DrawFrame(&renderer, viewport_rect, clip_rect); |
| 1235 EXPECT_EQ(0, context->discarded()); | 1235 EXPECT_EQ(0, gl->discarded()); |
| 1236 context->reset(); | 1236 gl->reset_discarded(); |
| 1237 } | 1237 } |
| 1238 { | 1238 { |
| 1239 // Full frame, doesn't cover the surface (no offset), should not discard. | 1239 // Full frame, doesn't cover the surface (no offset), should not discard. |
| 1240 clip_rect = gfx::Rect(100, 100); | 1240 clip_rect = gfx::Rect(100, 100); |
| 1241 viewport_rect = gfx::Rect(50, 50); | 1241 viewport_rect = gfx::Rect(50, 50); |
| 1242 RenderPassId root_pass_id(1, 0); | 1242 RenderPassId root_pass_id(1, 0); |
| 1243 RenderPass* root_pass = | 1243 RenderPass* root_pass = |
| 1244 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, | 1244 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, |
| 1245 viewport_rect, gfx::Transform()); | 1245 viewport_rect, gfx::Transform()); |
| 1246 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); | 1246 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); |
| 1247 root_pass->damage_rect = root_pass->output_rect; | 1247 root_pass->damage_rect = root_pass->output_rect; |
| 1248 | 1248 |
| 1249 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); | 1249 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); |
| 1250 DrawFrame(&renderer, viewport_rect, clip_rect); | 1250 DrawFrame(&renderer, viewport_rect, clip_rect); |
| 1251 EXPECT_EQ(0, context->discarded()); | 1251 EXPECT_EQ(0, gl->discarded()); |
| 1252 context->reset(); | 1252 gl->reset_discarded(); |
| 1253 } | 1253 } |
| 1254 } | 1254 } |
| 1255 | 1255 |
| 1256 class FlippedScissorAndViewportContext : public TestWebGraphicsContext3D { | 1256 class FlippedScissorAndViewportGLES2Interface : public TestGLES2Interface { |
| 1257 public: | 1257 public: |
| 1258 MOCK_METHOD4(viewport, void(GLint x, GLint y, GLsizei width, GLsizei height)); | 1258 MOCK_METHOD4(Viewport, void(GLint x, GLint y, GLsizei width, GLsizei height)); |
| 1259 MOCK_METHOD4(scissor, void(GLint x, GLint y, GLsizei width, GLsizei height)); | 1259 MOCK_METHOD4(Scissor, void(GLint x, GLint y, GLsizei width, GLsizei height)); |
| 1260 }; | 1260 }; |
| 1261 | 1261 |
| 1262 TEST_F(GLRendererTest, ScissorAndViewportWithinNonreshapableSurface) { | 1262 TEST_F(GLRendererTest, ScissorAndViewportWithinNonreshapableSurface) { |
| 1263 // In Android WebView, the OutputSurface is unable to respect reshape() calls | 1263 // In Android WebView, the OutputSurface is unable to respect reshape() calls |
| 1264 // and maintains a fixed size. This test verifies that glViewport and | 1264 // and maintains a fixed size. This test verifies that glViewport and |
| 1265 // glScissor's Y coordinate is flipped correctly in this environment, and that | 1265 // glScissor's Y coordinate is flipped correctly in this environment, and that |
| 1266 // the glViewport can be at a nonzero origin within the surface. | 1266 // the glViewport can be at a nonzero origin within the surface. |
| 1267 std::unique_ptr<FlippedScissorAndViewportContext> context_owned( | 1267 auto gl_owned = base::MakeUnique<FlippedScissorAndViewportGLES2Interface>(); |
| 1268 new FlippedScissorAndViewportContext); | |
| 1269 | 1268 |
| 1270 // We expect exactly one call to viewport on this context and exactly two | 1269 // We expect exactly one call to viewport on this context and exactly two |
| 1271 // to scissor (one to scissor the clear, one to scissor the quad draw). | 1270 // to scissor (one to scissor the clear, one to scissor the quad draw). |
| 1272 EXPECT_CALL(*context_owned, viewport(10, 390, 100, 100)); | 1271 EXPECT_CALL(*gl_owned, Viewport(10, 390, 100, 100)); |
| 1273 EXPECT_CALL(*context_owned, scissor(10, 390, 100, 100)); | 1272 EXPECT_CALL(*gl_owned, Scissor(10, 390, 100, 100)); |
| 1274 EXPECT_CALL(*context_owned, scissor(30, 450, 20, 20)); | 1273 EXPECT_CALL(*gl_owned, Scissor(30, 450, 20, 20)); |
| 1275 | 1274 |
| 1276 FakeOutputSurfaceClient output_surface_client; | 1275 FakeOutputSurfaceClient output_surface_client; |
| 1277 std::unique_ptr<OutputSurface> output_surface( | 1276 std::unique_ptr<OutputSurface> output_surface( |
| 1278 new NonReshapableOutputSurface(std::move(context_owned))); | 1277 new NonReshapableOutputSurface(std::move(gl_owned))); |
| 1279 CHECK(output_surface->BindToClient(&output_surface_client)); | 1278 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1280 | 1279 |
| 1281 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( | 1280 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 1282 new TestSharedBitmapManager()); | 1281 new TestSharedBitmapManager()); |
| 1283 std::unique_ptr<ResourceProvider> resource_provider = | 1282 std::unique_ptr<ResourceProvider> resource_provider = |
| 1284 FakeResourceProvider::Create(output_surface.get(), | 1283 FakeResourceProvider::Create(output_surface.get(), |
| 1285 shared_bitmap_manager.get()); | 1284 shared_bitmap_manager.get()); |
| 1286 | 1285 |
| 1287 RendererSettings settings; | 1286 RendererSettings settings; |
| 1288 FakeRendererClient renderer_client; | 1287 FakeRendererClient renderer_client; |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 Strategy* strategy_; | 1835 Strategy* strategy_; |
| 1837 }; | 1836 }; |
| 1838 | 1837 |
| 1839 void MailboxReleased(const gpu::SyncToken& sync_token, | 1838 void MailboxReleased(const gpu::SyncToken& sync_token, |
| 1840 bool lost_resource, | 1839 bool lost_resource, |
| 1841 BlockingTaskRunner* main_thread_task_runner) {} | 1840 BlockingTaskRunner* main_thread_task_runner) {} |
| 1842 | 1841 |
| 1843 void IgnoreCopyResult(std::unique_ptr<CopyOutputResult> result) {} | 1842 void IgnoreCopyResult(std::unique_ptr<CopyOutputResult> result) {} |
| 1844 | 1843 |
| 1845 TEST_F(GLRendererTest, DontOverlayWithCopyRequests) { | 1844 TEST_F(GLRendererTest, DontOverlayWithCopyRequests) { |
| 1846 std::unique_ptr<DiscardCheckingContext> context_owned( | |
| 1847 new DiscardCheckingContext); | |
| 1848 FakeOutputSurfaceClient output_surface_client; | 1845 FakeOutputSurfaceClient output_surface_client; |
| 1849 std::unique_ptr<FakeOutputSurface> output_surface( | 1846 std::unique_ptr<FakeOutputSurface> output_surface( |
| 1850 FakeOutputSurface::Create3d(std::move(context_owned))); | 1847 FakeOutputSurface::Create3d()); |
| 1851 CHECK(output_surface->BindToClient(&output_surface_client)); | 1848 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1852 | 1849 |
| 1853 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( | 1850 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager( |
| 1854 new TestSharedBitmapManager()); | 1851 new TestSharedBitmapManager()); |
| 1855 std::unique_ptr<ResourceProvider> resource_provider = | 1852 std::unique_ptr<ResourceProvider> resource_provider = |
| 1856 FakeResourceProvider::Create(output_surface.get(), | 1853 FakeResourceProvider::Create(output_surface.get(), |
| 1857 shared_bitmap_manager.get()); | 1854 shared_bitmap_manager.get()); |
| 1858 std::unique_ptr<TextureMailboxDeleter> mailbox_deleter( | 1855 std::unique_ptr<TextureMailboxDeleter> mailbox_deleter( |
| 1859 new TextureMailboxDeleter(base::ThreadTaskRunnerHandle::Get())); | 1856 new TextureMailboxDeleter(base::ThreadTaskRunnerHandle::Get())); |
| 1860 | 1857 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2061 // Verify that overlay_quad actually gets turned into an overlay, and even | 2058 // Verify that overlay_quad actually gets turned into an overlay, and even |
| 2062 // though it's not drawn, that its sync point is waited on. | 2059 // though it's not drawn, that its sync point is waited on. |
| 2063 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))).Times(1); | 2060 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))).Times(1); |
| 2064 EXPECT_CALL(overlay_scheduler, | 2061 EXPECT_CALL(overlay_scheduler, |
| 2065 Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, _, viewport_rect, | 2062 Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, _, viewport_rect, |
| 2066 BoundingRect(uv_top_left, uv_bottom_right))).Times(1); | 2063 BoundingRect(uv_top_left, uv_bottom_right))).Times(1); |
| 2067 | 2064 |
| 2068 DrawFrame(&renderer, viewport_rect); | 2065 DrawFrame(&renderer, viewport_rect); |
| 2069 } | 2066 } |
| 2070 | 2067 |
| 2068 class PartialSwapMockGLES2Interface : public TestGLES2Interface { |
| 2069 public: |
| 2070 void InitializeTestContext(TestWebGraphicsContext3D* context) override { |
| 2071 context->set_have_post_sub_buffer(true); |
| 2072 } |
| 2073 |
| 2074 MOCK_METHOD1(Enable, void(GLenum cap)); |
| 2075 MOCK_METHOD1(Disable, void(GLenum cap)); |
| 2076 MOCK_METHOD4(Scissor, void(GLint x, GLint y, GLsizei width, GLsizei height)); |
| 2077 }; |
| 2078 |
| 2079 class GLRendererPartialSwapTest : public GLRendererTest { |
| 2080 protected: |
| 2081 void RunTest(bool partial_swap) { |
| 2082 auto gl_owned = base::MakeUnique<PartialSwapMockGLES2Interface>(); |
| 2083 auto* gl = gl_owned.get(); |
| 2084 |
| 2085 FakeOutputSurfaceClient output_surface_client; |
| 2086 std::unique_ptr<FakeOutputSurface> output_surface( |
| 2087 FakeOutputSurface::Create3d(std::move(gl_owned))); |
| 2088 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2089 |
| 2090 std::unique_ptr<ResourceProvider> resource_provider = |
| 2091 FakeResourceProvider::Create(output_surface.get(), nullptr); |
| 2092 |
| 2093 RendererSettings settings; |
| 2094 settings.partial_swap_enabled = partial_swap; |
| 2095 FakeRendererClient renderer_client; |
| 2096 FakeRendererGL renderer(&renderer_client, &settings, output_surface.get(), |
| 2097 resource_provider.get()); |
| 2098 EXPECT_EQ(partial_swap, renderer.Capabilities().using_partial_swap); |
| 2099 |
| 2100 gfx::Rect viewport_rect(100, 100); |
| 2101 gfx::Rect clip_rect(100, 100); |
| 2102 |
| 2103 { |
| 2104 RenderPassId root_pass_id(1, 0); |
| 2105 RenderPass* root_pass = |
| 2106 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, |
| 2107 viewport_rect, gfx::Transform()); |
| 2108 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); |
| 2109 |
| 2110 testing::Sequence seq; |
| 2111 // A bunch of initialization that happens. |
| 2112 EXPECT_CALL(*gl, Disable(GL_DEPTH_TEST)).InSequence(seq); |
| 2113 EXPECT_CALL(*gl, Disable(GL_CULL_FACE)).InSequence(seq); |
| 2114 EXPECT_CALL(*gl, Disable(GL_STENCIL_TEST)).InSequence(seq); |
| 2115 EXPECT_CALL(*gl, Enable(GL_BLEND)).InSequence(seq); |
| 2116 EXPECT_CALL(*gl, Disable(GL_SCISSOR_TEST)).InSequence(seq); |
| 2117 |
| 2118 // Partial frame, we should use a scissor to swap only that part when |
| 2119 // partial swap is enabled. |
| 2120 root_pass->damage_rect = gfx::Rect(2, 2, 3, 3); |
| 2121 |
| 2122 if (partial_swap) { |
| 2123 EXPECT_CALL(*gl, Enable(GL_SCISSOR_TEST)).InSequence(seq); |
| 2124 // The scissor is flipped, so subtract the y coord and height from the |
| 2125 // bottom of the GL viewport. |
| 2126 EXPECT_CALL(*gl, Scissor(2, viewport_rect.bottom() - 3 - 2, 3, 3)) |
| 2127 .InSequence(seq); |
| 2128 } |
| 2129 |
| 2130 // The quad doesn't need blending. |
| 2131 EXPECT_CALL(*gl, Disable(GL_BLEND)).InSequence(seq); |
| 2132 |
| 2133 // Blending is disabled at the end of the frame. |
| 2134 EXPECT_CALL(*gl, Disable(GL_BLEND)).InSequence(seq); |
| 2135 |
| 2136 renderer.DecideRenderPassAllocationsForFrame( |
| 2137 render_passes_in_draw_order_); |
| 2138 DrawFrame(&renderer, viewport_rect, clip_rect); |
| 2139 } |
| 2140 } |
| 2141 }; |
| 2142 |
| 2143 TEST_F(GLRendererPartialSwapTest, PartialSwap) { |
| 2144 RunTest(true); |
| 2145 } |
| 2146 |
| 2147 TEST_F(GLRendererPartialSwapTest, NoPartialSwap) { |
| 2148 RunTest(false); |
| 2149 } |
| 2150 |
| 2071 } // namespace | 2151 } // namespace |
| 2072 } // namespace cc | 2152 } // namespace cc |
| OLD | NEW |