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

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 20185002: ContextProvider in OutputSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: contextprovider: fix android output surface impls Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "cc/animation/timing_function.h" 11 #include "cc/animation/timing_function.h"
12 #include "cc/debug/frame_rate_counter.h" 12 #include "cc/debug/frame_rate_counter.h"
13 #include "cc/debug/test_web_graphics_context_3d.h"
13 #include "cc/layers/content_layer.h" 14 #include "cc/layers/content_layer.h"
14 #include "cc/layers/content_layer_client.h" 15 #include "cc/layers/content_layer_client.h"
15 #include "cc/layers/io_surface_layer.h" 16 #include "cc/layers/io_surface_layer.h"
16 #include "cc/layers/layer_impl.h" 17 #include "cc/layers/layer_impl.h"
17 #include "cc/layers/picture_layer.h" 18 #include "cc/layers/picture_layer.h"
18 #include "cc/layers/scrollbar_layer.h" 19 #include "cc/layers/scrollbar_layer.h"
19 #include "cc/layers/solid_color_layer.h" 20 #include "cc/layers/solid_color_layer.h"
20 #include "cc/layers/video_layer.h" 21 #include "cc/layers/video_layer.h"
21 #include "cc/output/begin_frame_args.h" 22 #include "cc/output/begin_frame_args.h"
22 #include "cc/output/copy_output_request.h" 23 #include "cc/output/copy_output_request.h"
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 1140
1140 virtual void BeginTest() OVERRIDE { 1141 virtual void BeginTest() OVERRIDE {
1141 drew_frame_ = -1; 1142 drew_frame_ = -1;
1142 PostSetNeedsCommitToMainThread(); 1143 PostSetNeedsCommitToMainThread();
1143 } 1144 }
1144 1145
1145 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1146 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1146 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates); 1147 ASSERT_EQ(0u, layer_tree_host()->settings().max_partial_texture_updates);
1147 1148
1148 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 1149 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
1149 impl->output_surface()->context3d()); 1150 impl->output_surface()->context_provider()->Context3d());
1150 1151
1151 switch (impl->active_tree()->source_frame_number()) { 1152 switch (impl->active_tree()->source_frame_number()) {
1152 case 0: 1153 case 0:
1153 // Number of textures should be one for each layer 1154 // Number of textures should be one for each layer
1154 ASSERT_EQ(2u, context->NumTextures()); 1155 ASSERT_EQ(2u, context->NumTextures());
1155 // Number of textures used for commit should be one for each layer. 1156 // Number of textures used for commit should be one for each layer.
1156 EXPECT_EQ(2u, context->NumUsedTextures()); 1157 EXPECT_EQ(2u, context->NumUsedTextures());
1157 // Verify that used texture is correct. 1158 // Verify that used texture is correct.
1158 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); 1159 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0)));
1159 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); 1160 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1)));
(...skipping 22 matching lines...) Expand all
1182 EndTest(); 1183 EndTest();
1183 break; 1184 break;
1184 default: 1185 default:
1185 NOTREACHED(); 1186 NOTREACHED();
1186 break; 1187 break;
1187 } 1188 }
1188 } 1189 }
1189 1190
1190 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1191 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1191 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 1192 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
1192 impl->output_surface()->context3d()); 1193 impl->output_surface()->context_provider()->Context3d());
1193 1194
1194 if (drew_frame_ == impl->active_tree()->source_frame_number()) { 1195 if (drew_frame_ == impl->active_tree()->source_frame_number()) {
1195 EXPECT_EQ(0u, context->NumUsedTextures()) << "For frame " << drew_frame_; 1196 EXPECT_EQ(0u, context->NumUsedTextures()) << "For frame " << drew_frame_;
1196 return; 1197 return;
1197 } 1198 }
1198 drew_frame_ = impl->active_tree()->source_frame_number(); 1199 drew_frame_ = impl->active_tree()->source_frame_number();
1199 1200
1200 // We draw/ship one texture each frame for each layer. 1201 // We draw/ship one texture each frame for each layer.
1201 EXPECT_EQ(2u, context->NumUsedTextures()); 1202 EXPECT_EQ(2u, context->NumUsedTextures());
1202 context->ResetUsedTextures(); 1203 context->ResetUsedTextures();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 default: 1288 default:
1288 NOTREACHED() << layer_tree_host()->source_frame_number(); 1289 NOTREACHED() << layer_tree_host()->source_frame_number();
1289 break; 1290 break;
1290 } 1291 }
1291 } 1292 }
1292 1293
1293 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1294 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1294 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates); 1295 ASSERT_EQ(1u, layer_tree_host()->settings().max_partial_texture_updates);
1295 1296
1296 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 1297 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
1297 impl->output_surface()->context3d()); 1298 impl->output_surface()->context_provider()->Context3d());
1298 1299
1299 switch (impl->active_tree()->source_frame_number()) { 1300 switch (impl->active_tree()->source_frame_number()) {
1300 case 0: 1301 case 0:
1301 // Number of textures should be one for each layer. 1302 // Number of textures should be one for each layer.
1302 ASSERT_EQ(2u, context->NumTextures()); 1303 ASSERT_EQ(2u, context->NumTextures());
1303 // Number of textures used for commit should be one for each layer. 1304 // Number of textures used for commit should be one for each layer.
1304 EXPECT_EQ(2u, context->NumUsedTextures()); 1305 EXPECT_EQ(2u, context->NumUsedTextures());
1305 // Verify that used textures are correct. 1306 // Verify that used textures are correct.
1306 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0))); 1307 EXPECT_TRUE(context->UsedTexture(context->TextureAt(0)));
1307 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1))); 1308 EXPECT_TRUE(context->UsedTexture(context->TextureAt(1)));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 default: 1353 default:
1353 NOTREACHED(); 1354 NOTREACHED();
1354 break; 1355 break;
1355 } 1356 }
1356 } 1357 }
1357 1358
1358 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { 1359 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
1359 EXPECT_LT(impl->active_tree()->source_frame_number(), 5); 1360 EXPECT_LT(impl->active_tree()->source_frame_number(), 5);
1360 1361
1361 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 1362 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
1362 impl->output_surface()->context3d()); 1363 impl->output_surface()->context_provider()->Context3d());
1363 1364
1364 // Number of textures used for drawing should one per layer except for 1365 // Number of textures used for drawing should one per layer except for
1365 // frame 3 where the viewport only contains one layer. 1366 // frame 3 where the viewport only contains one layer.
1366 if (impl->active_tree()->source_frame_number() == 3) { 1367 if (impl->active_tree()->source_frame_number() == 3) {
1367 EXPECT_EQ(1u, context->NumUsedTextures()); 1368 EXPECT_EQ(1u, context->NumUsedTextures());
1368 } else { 1369 } else {
1369 EXPECT_EQ(2u, context->NumUsedTextures()) << 1370 EXPECT_EQ(2u, context->NumUsedTextures()) <<
1370 "For frame " << impl->active_tree()->source_frame_number(); 1371 "For frame " << impl->active_tree()->source_frame_number();
1371 } 1372 }
1372 1373
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
2310 } 2311 }
2311 } 2312 }
2312 2313
2313 private: 2314 private:
2314 SetBoundsClient client_; 2315 SetBoundsClient client_;
2315 int num_commits_; 2316 int num_commits_;
2316 }; 2317 };
2317 2318
2318 SINGLE_THREAD_TEST_F(LayerTreeHostTestChangeLayerPropertiesInPaintContents); 2319 SINGLE_THREAD_TEST_F(LayerTreeHostTestChangeLayerPropertiesInPaintContents);
2319 2320
2320 class MockIOSurfaceWebGraphicsContext3D : public FakeWebGraphicsContext3D { 2321 class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D {
2321 public: 2322 public:
2322 MockIOSurfaceWebGraphicsContext3D()
2323 : FakeWebGraphicsContext3D() {}
2324
2325 virtual WebKit::WebGLId createTexture() OVERRIDE { 2323 virtual WebKit::WebGLId createTexture() OVERRIDE {
2326 return 1; 2324 return 1;
2327 } 2325 }
2328 2326
2329 virtual WebKit::WebString getString(WebKit::WGC3Denum name) OVERRIDE {
2330 if (name == GL_EXTENSIONS) {
2331 return WebKit::WebString(
2332 "GL_CHROMIUM_iosurface GL_ARB_texture_rectangle");
2333 }
2334 return WebKit::WebString();
2335 }
2336
2337 MOCK_METHOD1(activeTexture, void(WebKit::WGC3Denum texture)); 2327 MOCK_METHOD1(activeTexture, void(WebKit::WGC3Denum texture));
2338 MOCK_METHOD2(bindTexture, void(WebKit::WGC3Denum target, 2328 MOCK_METHOD2(bindTexture, void(WebKit::WGC3Denum target,
2339 WebKit::WebGLId texture_id)); 2329 WebKit::WebGLId texture_id));
2340 MOCK_METHOD3(texParameteri, void(WebKit::WGC3Denum target, 2330 MOCK_METHOD3(texParameteri, void(WebKit::WGC3Denum target,
2341 WebKit::WGC3Denum pname, 2331 WebKit::WGC3Denum pname,
2342 WebKit::WGC3Dint param)); 2332 WebKit::WGC3Dint param));
2343 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(WebKit::WGC3Denum target, 2333 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(WebKit::WGC3Denum target,
2344 WebKit::WGC3Dint width, 2334 WebKit::WGC3Dint width,
2345 WebKit::WGC3Dint height, 2335 WebKit::WGC3Dint height,
2346 WebKit::WGC3Duint ioSurfaceId, 2336 WebKit::WGC3Duint ioSurfaceId,
2347 WebKit::WGC3Duint plane)); 2337 WebKit::WGC3Duint plane));
2348 MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, 2338 MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode,
2349 WebKit::WGC3Dsizei count, 2339 WebKit::WGC3Dsizei count,
2350 WebKit::WGC3Denum type, 2340 WebKit::WGC3Denum type,
2351 WebKit::WGC3Dintptr offset)); 2341 WebKit::WGC3Dintptr offset));
2342 MOCK_METHOD1(deleteTexture, void(WebKit::WGC3Denum texture));
2352 }; 2343 };
2353 2344
2354 2345
2355 class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest { 2346 class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest {
2356 protected: 2347 protected:
2357 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 2348 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
2358 OVERRIDE { 2349 OVERRIDE {
2359 scoped_ptr<MockIOSurfaceWebGraphicsContext3D> context( 2350 scoped_ptr<MockIOSurfaceWebGraphicsContext3D> mock_context_owned(
2360 new MockIOSurfaceWebGraphicsContext3D); 2351 new MockIOSurfaceWebGraphicsContext3D);
2361 mock_context_ = context.get(); 2352 mock_context_ = mock_context_owned.get();
2362 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d( 2353
2363 context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); 2354 mock_context_->set_have_extension_io_surface(true);
2355
2356 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
2357 mock_context_owned.PassAs<TestWebGraphicsContext3D>()));
2364 return output_surface.Pass(); 2358 return output_surface.Pass();
2365 } 2359 }
2366 2360
2367 virtual void SetupTree() OVERRIDE { 2361 virtual void SetupTree() OVERRIDE {
2368 LayerTreeHostTest::SetupTree(); 2362 LayerTreeHostTest::SetupTree();
2369 2363
2370 layer_tree_host()->root_layer()->SetIsDrawable(false); 2364 layer_tree_host()->root_layer()->SetIsDrawable(false);
2371 2365
2372 io_surface_id_ = 9; 2366 io_surface_id_ = 9;
2373 io_surface_size_ = gfx::Size(6, 7); 2367 io_surface_size_ = gfx::Size(6, 7);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) 2426 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1))
2433 .Times(1); 2427 .Times(1);
2434 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _)) 2428 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _))
2435 .Times(AtLeast(1)); 2429 .Times(AtLeast(1));
2436 2430
2437 return result; 2431 return result;
2438 } 2432 }
2439 2433
2440 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 2434 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
2441 Mock::VerifyAndClearExpectations(&mock_context_); 2435 Mock::VerifyAndClearExpectations(&mock_context_);
2436
2437 EXPECT_CALL(*mock_context_, deleteTexture(1)).Times(1);
2442 EndTest(); 2438 EndTest();
2443 } 2439 }
2444 2440
2445 virtual void AfterTest() OVERRIDE {} 2441 virtual void AfterTest() OVERRIDE {}
2446 2442
2447 int io_surface_id_; 2443 int io_surface_id_;
2448 MockIOSurfaceWebGraphicsContext3D* mock_context_; 2444 MockIOSurfaceWebGraphicsContext3D* mock_context_;
2449 gfx::Size io_surface_size_; 2445 gfx::Size io_surface_size_;
2450 }; 2446 };
2451 2447
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 gfx::Size(bitmap->width(), bitmap->height()).ToString()); 2531 gfx::Size(bitmap->width(), bitmap->height()).ToString());
2536 callbacks_.push_back(result->size()); 2532 callbacks_.push_back(result->size());
2537 } 2533 }
2538 2534
2539 virtual void AfterTest() OVERRIDE { 2535 virtual void AfterTest() OVERRIDE {
2540 EXPECT_EQ(4u, callbacks_.size()); 2536 EXPECT_EQ(4u, callbacks_.size());
2541 } 2537 }
2542 2538
2543 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) 2539 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback)
2544 OVERRIDE { 2540 OVERRIDE {
2545 if (use_gl_renderer_) 2541 scoped_ptr<FakeOutputSurface> output_surface;
2546 return FakeOutputSurface::Create3d().PassAs<OutputSurface>(); 2542 if (use_gl_renderer_) {
2547 return FakeOutputSurface::CreateSoftware( 2543 output_surface = FakeOutputSurface::Create3d().Pass();
2548 make_scoped_ptr(new SoftwareOutputDevice)).PassAs<OutputSurface>(); 2544 } else {
2545 output_surface = FakeOutputSurface::CreateSoftware(
2546 make_scoped_ptr(new SoftwareOutputDevice)).Pass();
2547 }
2548 return output_surface.PassAs<OutputSurface>();
2549 } 2549 }
2550 2550
2551 bool use_gl_renderer_; 2551 bool use_gl_renderer_;
2552 std::vector<gfx::Size> callbacks_; 2552 std::vector<gfx::Size> callbacks_;
2553 FakeContentLayerClient client_; 2553 FakeContentLayerClient client_;
2554 scoped_refptr<FakeContentLayer> root; 2554 scoped_refptr<FakeContentLayer> root;
2555 scoped_refptr<FakeContentLayer> child; 2555 scoped_refptr<FakeContentLayer> child;
2556 }; 2556 };
2557 2557
2558 // Readback can't be done with a delegating renderer. 2558 // Readback can't be done with a delegating renderer.
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
3123 base::Unretained(host_impl))); 3123 base::Unretained(host_impl)));
3124 } else if (did_initialize_gl_ && did_release_gl_) { 3124 } else if (did_initialize_gl_ && did_release_gl_) {
3125 EXPECT_LE(3u, layer_impl->append_quads_count()); 3125 EXPECT_LE(3u, layer_impl->append_quads_count());
3126 EndTest(); 3126 EndTest();
3127 } 3127 }
3128 } 3128 }
3129 3129
3130 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) { 3130 void DeferredInitializeAndRedraw(LayerTreeHostImpl* host_impl) {
3131 EXPECT_FALSE(did_initialize_gl_); 3131 EXPECT_FALSE(did_initialize_gl_);
3132 // SetAndInitializeContext3D calls SetNeedsCommit. 3132 // SetAndInitializeContext3D calls SetNeedsCommit.
3133 EXPECT_TRUE(static_cast<FakeOutputSurface*>(host_impl->output_surface()) 3133 FakeOutputSurface* fake_output_surface =
3134 ->SetAndInitializeContext3D( 3134 static_cast<FakeOutputSurface*>(host_impl->output_surface());
3135 scoped_ptr<WebKit::WebGraphicsContext3D>( 3135 scoped_refptr<TestContextProvider> context_provider =
3136 TestWebGraphicsContext3D::Create()))); 3136 TestContextProvider::Create(); // Not bound to thread.
3137 EXPECT_TRUE(fake_output_surface->InitializeAndSetContext3d(
3138 context_provider, NULL));
3137 did_initialize_gl_ = true; 3139 did_initialize_gl_ = true;
3138 } 3140 }
3139 3141
3140 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) { 3142 void ReleaseGLAndRedraw(LayerTreeHostImpl* host_impl) {
3141 EXPECT_TRUE(did_initialize_gl_); 3143 EXPECT_TRUE(did_initialize_gl_);
3142 EXPECT_FALSE(did_release_gl_); 3144 EXPECT_FALSE(did_release_gl_);
3143 // ReleaseGL calls SetNeedsCommit. 3145 // ReleaseGL calls SetNeedsCommit.
3144 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL(); 3146 static_cast<FakeOutputSurface*>(host_impl->output_surface())->ReleaseGL();
3145 did_release_gl_ = true; 3147 did_release_gl_ = true;
3146 } 3148 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3194 break; 3196 break;
3195 case 5: 3197 case 5:
3196 ClearResources(); 3198 ClearResources();
3197 EndTest(); 3199 EndTest();
3198 break; 3200 break;
3199 } 3201 }
3200 } 3202 }
3201 3203
3202 void PerformTest(LayerTreeHostImpl* impl) { 3204 void PerformTest(LayerTreeHostImpl* impl) {
3203 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( 3205 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(
3204 impl->output_surface()->context3d()); 3206 impl->output_surface()->context_provider()->Context3d());
3205 3207
3206 int frame = num_commits_; 3208 int frame = num_commits_;
3207 switch (frame) { 3209 switch (frame) {
3208 case 1: 3210 case 1:
3209 ASSERT_EQ(0u, context->NumTextures()); 3211 ASSERT_EQ(0u, context->NumTextures());
3210 break; 3212 break;
3211 case 2: 3213 case 2:
3212 // Created two textures. 3214 // Created two textures.
3213 ASSERT_EQ(2u, context->NumTextures()); 3215 ASSERT_EQ(2u, context->NumTextures());
3214 break; 3216 break;
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
4291 int num_will_begin_frames_; 4293 int num_will_begin_frames_;
4292 int num_impl_commits_; 4294 int num_impl_commits_;
4293 }; 4295 };
4294 4296
4295 // Commits can only be aborted when using the thread proxy. 4297 // Commits can only be aborted when using the thread proxy.
4296 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures); 4298 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures);
4297 4299
4298 } // namespace 4300 } // namespace
4299 4301
4300 } // namespace cc 4302 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698