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

Side by Side Diff: cc/gl_renderer_unittest.cc

Issue 11348371: cc: Move WebCompositorOutputSurface and related classes into cc/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: forlanding6 Created 8 years 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
« no previous file with comments | « cc/delegated_renderer_layer_impl_unittest.cc ('k') | cc/heads_up_display_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gl_renderer.h" 5 #include "cc/gl_renderer.h"
6 6
7 #include "cc/draw_quad.h" 7 #include "cc/draw_quad.h"
8 #include "cc/prioritized_resource_manager.h" 8 #include "cc/prioritized_resource_manager.h"
9 #include "cc/resource_provider.h" 9 #include "cc/resource_provider.h"
10 #include "cc/test/fake_impl_proxy.h" 10 #include "cc/test/fake_impl_proxy.h"
11 #include "cc/test/fake_layer_tree_host_impl.h" 11 #include "cc/test/fake_layer_tree_host_impl.h"
12 #include "cc/test/fake_web_compositor_output_surface.h" 12 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/fake_web_graphics_context_3d.h" 13 #include "cc/test/fake_web_graphics_context_3d.h"
14 #include "cc/test/render_pass_test_common.h" 14 #include "cc/test/render_pass_test_common.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/khronos/GLES2/gl2.h" 17 #include "third_party/khronos/GLES2/gl2.h"
18 #include "ui/gfx/transform.h" 18 #include "ui/gfx/transform.h"
19 19
20 using namespace WebKit; 20 using namespace WebKit;
21 using namespace WebKitTests; 21 using namespace WebKitTests;
22 22
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 using GLRenderer::drawQuad; 116 using GLRenderer::drawQuad;
117 using GLRenderer::beginDrawingFrame; 117 using GLRenderer::beginDrawingFrame;
118 using GLRenderer::finishDrawingQuadList; 118 using GLRenderer::finishDrawingQuadList;
119 }; 119 };
120 120
121 class GLRendererTest : public testing::Test { 121 class GLRendererTest : public testing::Test {
122 protected: 122 protected:
123 GLRendererTest() 123 GLRendererTest()
124 : m_suggestHaveBackbufferYes(1, true) 124 : m_suggestHaveBackbufferYes(1, true)
125 , m_suggestHaveBackbufferNo(1, false) 125 , m_suggestHaveBackbufferNo(1, false)
126 , m_context(FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::We bGraphicsContext3D>(new FrameCountingMemoryAllocationSettingContext()))) 126 , m_context(FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsCo ntext3D>(new FrameCountingMemoryAllocationSettingContext())))
127 , m_resourceProvider(ResourceProvider::create(m_context.get())) 127 , m_resourceProvider(ResourceProvider::create(m_context.get()))
128 , m_renderer(&m_mockClient, m_resourceProvider.get()) 128 , m_renderer(&m_mockClient, m_resourceProvider.get())
129 { 129 {
130 } 130 }
131 131
132 virtual void SetUp() 132 virtual void SetUp()
133 { 133 {
134 m_renderer.initialize(); 134 m_renderer.initialize();
135 } 135 }
136 136
137 void swapBuffers() 137 void swapBuffers()
138 { 138 {
139 m_renderer.swapBuffers(); 139 m_renderer.swapBuffers();
140 } 140 }
141 141
142 FrameCountingMemoryAllocationSettingContext* context() { return static_cast< FrameCountingMemoryAllocationSettingContext*>(m_context->context3D()); } 142 FrameCountingMemoryAllocationSettingContext* context() { return static_cast< FrameCountingMemoryAllocationSettingContext*>(m_context->Context3D()); }
143 143
144 WebGraphicsMemoryAllocation m_suggestHaveBackbufferYes; 144 WebGraphicsMemoryAllocation m_suggestHaveBackbufferYes;
145 WebGraphicsMemoryAllocation m_suggestHaveBackbufferNo; 145 WebGraphicsMemoryAllocation m_suggestHaveBackbufferNo;
146 146
147 scoped_ptr<OutputSurface> m_context; 147 scoped_ptr<OutputSurface> m_context;
148 FakeRendererClient m_mockClient; 148 FakeRendererClient m_mockClient;
149 scoped_ptr<ResourceProvider> m_resourceProvider; 149 scoped_ptr<ResourceProvider> m_resourceProvider;
150 FakeRendererGL m_renderer; 150 FakeRendererGL m_renderer;
151 }; 151 };
152 152
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 virtual WGC3Dint getUniformLocation(WebGLId program, const WGC3Dchar* name) { ADD_FAILURE(); return 0; } 298 virtual WGC3Dint getUniformLocation(WebGLId program, const WGC3Dchar* name) { ADD_FAILURE(); return 0; }
299 virtual void getVertexAttribfv(WGC3Duint index, WGC3Denum pname, WGC3Dfloat* value) { ADD_FAILURE(); } 299 virtual void getVertexAttribfv(WGC3Duint index, WGC3Denum pname, WGC3Dfloat* value) { ADD_FAILURE(); }
300 virtual void getVertexAttribiv(WGC3Duint index, WGC3Denum pname, WGC3Dint* v alue) { ADD_FAILURE(); } 300 virtual void getVertexAttribiv(WGC3Duint index, WGC3Denum pname, WGC3Dint* v alue) { ADD_FAILURE(); }
301 virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index, WGC3Denum pname ) { ADD_FAILURE(); return 0; } 301 virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index, WGC3Denum pname ) { ADD_FAILURE(); return 0; }
302 }; 302 };
303 303
304 // This test isn't using the same fixture as GLRendererTest, and you can't mix T EST() and TEST_F() with the same name, hence LRC2. 304 // This test isn't using the same fixture as GLRendererTest, and you can't mix T EST() and TEST_F() with the same name, hence LRC2.
305 TEST(GLRendererTest2, initializationDoesNotMakeSynchronousCalls) 305 TEST(GLRendererTest2, initializationDoesNotMakeSynchronousCalls)
306 { 306 {
307 FakeRendererClient mockClient; 307 FakeRendererClient mockClient;
308 scoped_ptr<OutputSurface> context(FakeWebCompositorOutputSurface::create(sco ped_ptr<WebKit::WebGraphicsContext3D>(new ForbidSynchronousCallContext))); 308 scoped_ptr<OutputSurface> context(FakeOutputSurface::Create3d(scoped_ptr<Web Kit::WebGraphicsContext3D>(new ForbidSynchronousCallContext)));
309 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get())); 309 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
310 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 310 FakeRendererGL renderer(&mockClient, resourceProvider.get());
311 311
312 EXPECT_TRUE(renderer.initialize()); 312 EXPECT_TRUE(renderer.initialize());
313 } 313 }
314 314
315 class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D { 315 class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D {
316 public: 316 public:
317 LoseContextOnFirstGetContext() 317 LoseContextOnFirstGetContext()
318 : m_contextLost(false) 318 : m_contextLost(false)
(...skipping 22 matching lines...) Expand all
341 return m_contextLost ? 1 : 0; 341 return m_contextLost ? 1 : 0;
342 } 342 }
343 343
344 private: 344 private:
345 bool m_contextLost; 345 bool m_contextLost;
346 }; 346 };
347 347
348 TEST(GLRendererTest2, initializationWithQuicklyLostContextDoesNotAssert) 348 TEST(GLRendererTest2, initializationWithQuicklyLostContextDoesNotAssert)
349 { 349 {
350 FakeRendererClient mockClient; 350 FakeRendererClient mockClient;
351 scoped_ptr<OutputSurface> context(FakeWebCompositorOutputSurface::create(sco ped_ptr<WebKit::WebGraphicsContext3D>(new LoseContextOnFirstGetContext))); 351 scoped_ptr<OutputSurface> context(FakeOutputSurface::Create3d(scoped_ptr<Web Kit::WebGraphicsContext3D>(new LoseContextOnFirstGetContext)));
352 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get())); 352 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
353 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 353 FakeRendererGL renderer(&mockClient, resourceProvider.get());
354 354
355 renderer.initialize(); 355 renderer.initialize();
356 } 356 }
357 357
358 class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphic sContext3D { 358 class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphic sContext3D {
359 public: 359 public:
360 ContextThatDoesNotSupportMemoryManagmentExtensions() { } 360 ContextThatDoesNotSupportMemoryManagmentExtensions() { }
361 361
362 // WebGraphicsContext3D methods. 362 // WebGraphicsContext3D methods.
363 363
364 // This method would normally do a glSwapBuffers under the hood. 364 // This method would normally do a glSwapBuffers under the hood.
365 virtual void prepareTexture() { } 365 virtual void prepareTexture() { }
366 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll ocationChangedCallbackCHROMIUM* callback) { } 366 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll ocationChangedCallbackCHROMIUM* callback) { }
367 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); } 367 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); }
368 }; 368 };
369 369
370 TEST(GLRendererTest2, initializationWithoutGpuMemoryManagerExtensionSupportShoul dDefaultToNonZeroAllocation) 370 TEST(GLRendererTest2, initializationWithoutGpuMemoryManagerExtensionSupportShoul dDefaultToNonZeroAllocation)
371 { 371 {
372 FakeRendererClient mockClient; 372 FakeRendererClient mockClient;
373 scoped_ptr<OutputSurface> outputSurface(FakeWebCompositorOutputSurface::crea te(scoped_ptr<WebKit::WebGraphicsContext3D>(new ContextThatDoesNotSupportMemoryM anagmentExtensions))); 373 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p tr<WebKit::WebGraphicsContext3D>(new ContextThatDoesNotSupportMemoryManagmentExt ensions)));
374 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get())); 374 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get()));
375 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 375 FakeRendererGL renderer(&mockClient, resourceProvider.get());
376 376
377 renderer.initialize(); 377 renderer.initialize();
378 378
379 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul); 379 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul);
380 } 380 }
381 381
382 class ClearCountingContext : public FakeWebGraphicsContext3D { 382 class ClearCountingContext : public FakeWebGraphicsContext3D {
383 public: 383 public:
384 ClearCountingContext() : m_clear(0) { } 384 ClearCountingContext() : m_clear(0) { }
385 385
386 virtual void clear(WGC3Dbitfield) 386 virtual void clear(WGC3Dbitfield)
387 { 387 {
388 m_clear++; 388 m_clear++;
389 } 389 }
390 390
391 int clearCount() const { return m_clear; } 391 int clearCount() const { return m_clear; }
392 392
393 private: 393 private:
394 int m_clear; 394 int m_clear;
395 }; 395 };
396 396
397 TEST(GLRendererTest2, opaqueBackground) 397 TEST(GLRendererTest2, opaqueBackground)
398 { 398 {
399 FakeRendererClient mockClient; 399 FakeRendererClient mockClient;
400 scoped_ptr<OutputSurface> outputSurface(FakeWebCompositorOutputSurface::crea te(scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); 400 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p tr<WebKit::WebGraphicsContext3D>(new ClearCountingContext)));
401 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur face->context3D()); 401 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur face->Context3D());
402 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get())); 402 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get()));
403 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 403 FakeRendererGL renderer(&mockClient, resourceProvider.get());
404 404
405 mockClient.rootRenderPass()->has_transparent_background = false; 405 mockClient.rootRenderPass()->has_transparent_background = false;
406 406
407 EXPECT_TRUE(renderer.initialize()); 407 EXPECT_TRUE(renderer.initialize());
408 408
409 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa sses()); 409 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa sses());
410 410
411 // On DEBUG builds, render passes with opaque background clear to blue to 411 // On DEBUG builds, render passes with opaque background clear to blue to
412 // easily see regions that were not drawn on the screen. 412 // easily see regions that were not drawn on the screen.
413 #ifdef NDEBUG 413 #ifdef NDEBUG
414 EXPECT_EQ(0, context->clearCount()); 414 EXPECT_EQ(0, context->clearCount());
415 #else 415 #else
416 EXPECT_EQ(1, context->clearCount()); 416 EXPECT_EQ(1, context->clearCount());
417 #endif 417 #endif
418 } 418 }
419 419
420 TEST(GLRendererTest2, transparentBackground) 420 TEST(GLRendererTest2, transparentBackground)
421 { 421 {
422 FakeRendererClient mockClient; 422 FakeRendererClient mockClient;
423 scoped_ptr<OutputSurface> outputSurface(FakeWebCompositorOutputSurface::crea te(scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); 423 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p tr<WebKit::WebGraphicsContext3D>(new ClearCountingContext)));
424 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur face->context3D()); 424 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur face->Context3D());
425 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get())); 425 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get()));
426 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 426 FakeRendererGL renderer(&mockClient, resourceProvider.get());
427 427
428 mockClient.rootRenderPass()->has_transparent_background = true; 428 mockClient.rootRenderPass()->has_transparent_background = true;
429 429
430 EXPECT_TRUE(renderer.initialize()); 430 EXPECT_TRUE(renderer.initialize());
431 431
432 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa sses()); 432 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa sses());
433 433
434 EXPECT_EQ(1, context->clearCount()); 434 EXPECT_EQ(1, context->clearCount());
(...skipping 29 matching lines...) Expand all
464 // Methods added for test. 464 // Methods added for test.
465 void setLastCallWasSetVisibilityPointer(bool* lastCallWasSetVisibility) { m_ lastCallWasSetVisibility = lastCallWasSetVisibility; } 465 void setLastCallWasSetVisibilityPointer(bool* lastCallWasSetVisibility) { m_ lastCallWasSetVisibility = lastCallWasSetVisibility; }
466 466
467 private: 467 private:
468 bool* m_lastCallWasSetVisibility; 468 bool* m_lastCallWasSetVisibility;
469 }; 469 };
470 470
471 TEST(GLRendererTest2, visibilityChangeIsLastCall) 471 TEST(GLRendererTest2, visibilityChangeIsLastCall)
472 { 472 {
473 FakeRendererClient mockClient; 473 FakeRendererClient mockClient;
474 scoped_ptr<OutputSurface> outputSurface(FakeWebCompositorOutputSurface::crea te(scoped_ptr<WebKit::WebGraphicsContext3D>(new VisibilityChangeIsLastCallTracki ngContext))); 474 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p tr<WebKit::WebGraphicsContext3D>(new VisibilityChangeIsLastCallTrackingContext)) );
475 VisibilityChangeIsLastCallTrackingContext* context = static_cast<VisibilityC hangeIsLastCallTrackingContext*>(outputSurface->context3D()); 475 VisibilityChangeIsLastCallTrackingContext* context = static_cast<VisibilityC hangeIsLastCallTrackingContext*>(outputSurface->Context3D());
476 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get())); 476 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get()));
477 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 477 FakeRendererGL renderer(&mockClient, resourceProvider.get());
478 478
479 EXPECT_TRUE(renderer.initialize()); 479 EXPECT_TRUE(renderer.initialize());
480 480
481 bool lastCallWasSetVisiblity = false; 481 bool lastCallWasSetVisiblity = false;
482 // Ensure that the call to setVisibilityCHROMIUM is the last call issue to t he GPU 482 // Ensure that the call to setVisibilityCHROMIUM is the last call issue to t he GPU
483 // process, after glFlush is called, and after the RendererClient's enforceM anagedMemoryPolicy 483 // process, after glFlush is called, and after the RendererClient's enforceM anagedMemoryPolicy
484 // is called. Plumb this tracking between both the RenderClient and the Cont ext by giving 484 // is called. Plumb this tracking between both the RenderClient and the Cont ext by giving
485 // them both a pointer to a variable on the stack. 485 // them both a pointer to a variable on the stack.
(...skipping 30 matching lines...) Expand all
516 516
517 WGC3Denum activeTexture() const { return m_activeTexture; } 517 WGC3Denum activeTexture() const { return m_activeTexture; }
518 518
519 private: 519 private:
520 WGC3Denum m_activeTexture; 520 WGC3Denum m_activeTexture;
521 }; 521 };
522 522
523 TEST(GLRendererTest2, activeTextureState) 523 TEST(GLRendererTest2, activeTextureState)
524 { 524 {
525 FakeRendererClient fakeClient; 525 FakeRendererClient fakeClient;
526 scoped_ptr<OutputSurface> outputSurface(FakeWebCompositorOutputSurface::crea te(scoped_ptr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))); 526 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p tr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext)));
527 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte xt*>(outputSurface->context3D()); 527 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte xt*>(outputSurface->Context3D());
528 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get())); 528 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get()));
529 FakeRendererGL renderer(&fakeClient, resourceProvider.get()); 529 FakeRendererGL renderer(&fakeClient, resourceProvider.get());
530 530
531 // During initialization we are allowed to set any texture parameters. 531 // During initialization we are allowed to set any texture parameters.
532 EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber()); 532 EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber());
533 EXPECT_TRUE(renderer.initialize()); 533 EXPECT_TRUE(renderer.initialize());
534 534
535 cc::RenderPass::Id id(1, 1); 535 cc::RenderPass::Id id(1, 1);
536 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); 536 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create();
537 pass->SetNew(id, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 100, 100), gfx:: Transform()); 537 pass->SetNew(id, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 100, 100), gfx:: Transform());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 it != pass->quad_list.backToFrontEnd(); ++it) { 573 it != pass->quad_list.backToFrontEnd(); ++it) {
574 renderer.drawQuad(drawingFrame, *it); 574 renderer.drawQuad(drawingFrame, *it);
575 } 575 }
576 renderer.finishDrawingQuadList(); 576 renderer.finishDrawingQuadList();
577 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); 577 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0);
578 Mock::VerifyAndClearExpectations(context); 578 Mock::VerifyAndClearExpectations(context);
579 } 579 }
580 580
581 } // namespace 581 } // namespace
582 } // namespace cc 582 } // namespace cc
OLDNEW
« no previous file with comments | « cc/delegated_renderer_layer_impl_unittest.cc ('k') | cc/heads_up_display_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698