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

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: mynits 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
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_web_compositor_output_surface.h" 10 #include "cc/test/fake_output_surface.h"
11 #include "cc/test/fake_web_graphics_context_3d.h" 11 #include "cc/test/fake_web_graphics_context_3d.h"
12 #include "cc/test/render_pass_test_common.h" 12 #include "cc/test/render_pass_test_common.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/khronos/GLES2/gl2.h" 15 #include "third_party/khronos/GLES2/gl2.h"
16 #include "ui/gfx/transform.h" 16 #include "ui/gfx/transform.h"
17 17
18 using namespace WebKit; 18 using namespace WebKit;
19 using namespace WebKitTests; 19 using namespace WebKitTests;
20 20
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 using GLRenderer::drawQuad; 106 using GLRenderer::drawQuad;
107 using GLRenderer::beginDrawingFrame; 107 using GLRenderer::beginDrawingFrame;
108 using GLRenderer::finishDrawingQuadList; 108 using GLRenderer::finishDrawingQuadList;
109 }; 109 };
110 110
111 class GLRendererTest : public testing::Test { 111 class GLRendererTest : public testing::Test {
112 protected: 112 protected:
113 GLRendererTest() 113 GLRendererTest()
114 : m_suggestHaveBackbufferYes(1, true) 114 : m_suggestHaveBackbufferYes(1, true)
115 , m_suggestHaveBackbufferNo(1, false) 115 , m_suggestHaveBackbufferNo(1, false)
116 , m_context(FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::We bGraphicsContext3D>(new FrameCountingMemoryAllocationSettingContext()))) 116 , m_context(FakeOutputSurface::Create(scoped_ptr<WebKit::WebGraphicsCont ext3D>(new FrameCountingMemoryAllocationSettingContext())))
117 , m_resourceProvider(ResourceProvider::create(m_context.get())) 117 , m_resourceProvider(ResourceProvider::create(m_context.get()))
118 , m_renderer(&m_mockClient, m_resourceProvider.get()) 118 , m_renderer(&m_mockClient, m_resourceProvider.get())
119 { 119 {
120 } 120 }
121 121
122 virtual void SetUp() 122 virtual void SetUp()
123 { 123 {
124 m_renderer.initialize(); 124 m_renderer.initialize();
125 } 125 }
126 126
127 void swapBuffers() 127 void swapBuffers()
128 { 128 {
129 m_renderer.swapBuffers(); 129 m_renderer.swapBuffers();
130 } 130 }
131 131
132 FrameCountingMemoryAllocationSettingContext* context() { return static_cast< FrameCountingMemoryAllocationSettingContext*>(m_context->context3D()); } 132 FrameCountingMemoryAllocationSettingContext* context() { return static_cast< FrameCountingMemoryAllocationSettingContext*>(m_context->Context3D()); }
133 133
134 WebGraphicsMemoryAllocation m_suggestHaveBackbufferYes; 134 WebGraphicsMemoryAllocation m_suggestHaveBackbufferYes;
135 WebGraphicsMemoryAllocation m_suggestHaveBackbufferNo; 135 WebGraphicsMemoryAllocation m_suggestHaveBackbufferNo;
136 136
137 scoped_ptr<GraphicsContext> m_context; 137 scoped_ptr<GraphicsContext> m_context;
138 FakeRendererClient m_mockClient; 138 FakeRendererClient m_mockClient;
139 scoped_ptr<ResourceProvider> m_resourceProvider; 139 scoped_ptr<ResourceProvider> m_resourceProvider;
140 FakeRendererGL m_renderer; 140 FakeRendererGL m_renderer;
141 }; 141 };
142 142
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 virtual WGC3Dint getUniformLocation(WebGLId program, const WGC3Dchar* name) { ADD_FAILURE(); return 0; } 288 virtual WGC3Dint getUniformLocation(WebGLId program, const WGC3Dchar* name) { ADD_FAILURE(); return 0; }
289 virtual void getVertexAttribfv(WGC3Duint index, WGC3Denum pname, WGC3Dfloat* value) { ADD_FAILURE(); } 289 virtual void getVertexAttribfv(WGC3Duint index, WGC3Denum pname, WGC3Dfloat* value) { ADD_FAILURE(); }
290 virtual void getVertexAttribiv(WGC3Duint index, WGC3Denum pname, WGC3Dint* v alue) { ADD_FAILURE(); } 290 virtual void getVertexAttribiv(WGC3Duint index, WGC3Denum pname, WGC3Dint* v alue) { ADD_FAILURE(); }
291 virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index, WGC3Denum pname ) { ADD_FAILURE(); return 0; } 291 virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index, WGC3Denum pname ) { ADD_FAILURE(); return 0; }
292 }; 292 };
293 293
294 // 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. 294 // 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.
295 TEST(GLRendererTest2, initializationDoesNotMakeSynchronousCalls) 295 TEST(GLRendererTest2, initializationDoesNotMakeSynchronousCalls)
296 { 296 {
297 FakeRendererClient mockClient; 297 FakeRendererClient mockClient;
298 scoped_ptr<GraphicsContext> context(FakeWebCompositorOutputSurface::create(s coped_ptr<WebKit::WebGraphicsContext3D>(new ForbidSynchronousCallContext))); 298 scoped_ptr<GraphicsContext> context(FakeOutputSurface::Create(scoped_ptr<Web Kit::WebGraphicsContext3D>(new ForbidSynchronousCallContext)));
299 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get())); 299 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
300 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 300 FakeRendererGL renderer(&mockClient, resourceProvider.get());
301 301
302 EXPECT_TRUE(renderer.initialize()); 302 EXPECT_TRUE(renderer.initialize());
303 } 303 }
304 304
305 class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D { 305 class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D {
306 public: 306 public:
307 LoseContextOnFirstGetContext() 307 LoseContextOnFirstGetContext()
308 : m_contextLost(false) 308 : m_contextLost(false)
(...skipping 22 matching lines...) Expand all
331 return m_contextLost ? 1 : 0; 331 return m_contextLost ? 1 : 0;
332 } 332 }
333 333
334 private: 334 private:
335 bool m_contextLost; 335 bool m_contextLost;
336 }; 336 };
337 337
338 TEST(GLRendererTest2, initializationWithQuicklyLostContextDoesNotAssert) 338 TEST(GLRendererTest2, initializationWithQuicklyLostContextDoesNotAssert)
339 { 339 {
340 FakeRendererClient mockClient; 340 FakeRendererClient mockClient;
341 scoped_ptr<GraphicsContext> context(FakeWebCompositorOutputSurface::create(s coped_ptr<WebKit::WebGraphicsContext3D>(new LoseContextOnFirstGetContext))); 341 scoped_ptr<GraphicsContext> context(FakeOutputSurface::Create(scoped_ptr<Web Kit::WebGraphicsContext3D>(new LoseContextOnFirstGetContext)));
342 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get())); 342 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
343 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 343 FakeRendererGL renderer(&mockClient, resourceProvider.get());
344 344
345 renderer.initialize(); 345 renderer.initialize();
346 } 346 }
347 347
348 class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphic sContext3D { 348 class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphic sContext3D {
349 public: 349 public:
350 ContextThatDoesNotSupportMemoryManagmentExtensions() { } 350 ContextThatDoesNotSupportMemoryManagmentExtensions() { }
351 351
352 // WebGraphicsContext3D methods. 352 // WebGraphicsContext3D methods.
353 353
354 // This method would normally do a glSwapBuffers under the hood. 354 // This method would normally do a glSwapBuffers under the hood.
355 virtual void prepareTexture() { } 355 virtual void prepareTexture() { }
356 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll ocationChangedCallbackCHROMIUM* callback) { } 356 virtual void setMemoryAllocationChangedCallbackCHROMIUM(WebGraphicsMemoryAll ocationChangedCallbackCHROMIUM* callback) { }
357 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); } 357 virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); }
358 }; 358 };
359 359
360 TEST(GLRendererTest2, initializationWithoutGpuMemoryManagerExtensionSupportShoul dDefaultToNonZeroAllocation) 360 TEST(GLRendererTest2, initializationWithoutGpuMemoryManagerExtensionSupportShoul dDefaultToNonZeroAllocation)
361 { 361 {
362 FakeRendererClient mockClient; 362 FakeRendererClient mockClient;
363 scoped_ptr<GraphicsContext> context(FakeWebCompositorOutputSurface::create(s coped_ptr<WebKit::WebGraphicsContext3D>(new ContextThatDoesNotSupportMemoryManag mentExtensions))); 363 scoped_ptr<GraphicsContext> context(FakeOutputSurface::Create(scoped_ptr<Web Kit::WebGraphicsContext3D>(new ContextThatDoesNotSupportMemoryManagmentExtension s)));
364 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get())); 364 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(conte xt.get()));
365 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 365 FakeRendererGL renderer(&mockClient, resourceProvider.get());
366 366
367 renderer.initialize(); 367 renderer.initialize();
368 368
369 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul); 369 EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul);
370 } 370 }
371 371
372 class ClearCountingContext : public FakeWebGraphicsContext3D { 372 class ClearCountingContext : public FakeWebGraphicsContext3D {
373 public: 373 public:
374 ClearCountingContext() : m_clear(0) { } 374 ClearCountingContext() : m_clear(0) { }
375 375
376 virtual void clear(WGC3Dbitfield) 376 virtual void clear(WGC3Dbitfield)
377 { 377 {
378 m_clear++; 378 m_clear++;
379 } 379 }
380 380
381 int clearCount() const { return m_clear; } 381 int clearCount() const { return m_clear; }
382 382
383 private: 383 private:
384 int m_clear; 384 int m_clear;
385 }; 385 };
386 386
387 TEST(GLRendererTest2, opaqueBackground) 387 TEST(GLRendererTest2, opaqueBackground)
388 { 388 {
389 FakeRendererClient mockClient; 389 FakeRendererClient mockClient;
390 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); 390 scoped_ptr<GraphicsContext> outputSurface(FakeOutputSurface::Create(scoped_p tr<WebKit::WebGraphicsContext3D>(new ClearCountingContext)));
391 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur face->context3D()); 391 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur face->Context3D());
392 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get())); 392 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get()));
393 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 393 FakeRendererGL renderer(&mockClient, resourceProvider.get());
394 394
395 mockClient.rootRenderPass()->has_transparent_background = false; 395 mockClient.rootRenderPass()->has_transparent_background = false;
396 396
397 EXPECT_TRUE(renderer.initialize()); 397 EXPECT_TRUE(renderer.initialize());
398 398
399 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa sses()); 399 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa sses());
400 400
401 // On DEBUG builds, render passes with opaque background clear to blue to 401 // On DEBUG builds, render passes with opaque background clear to blue to
402 // easily see regions that were not drawn on the screen. 402 // easily see regions that were not drawn on the screen.
403 #ifdef NDEBUG 403 #ifdef NDEBUG
404 EXPECT_EQ(0, context->clearCount()); 404 EXPECT_EQ(0, context->clearCount());
405 #else 405 #else
406 EXPECT_EQ(1, context->clearCount()); 406 EXPECT_EQ(1, context->clearCount());
407 #endif 407 #endif
408 } 408 }
409 409
410 TEST(GLRendererTest2, transparentBackground) 410 TEST(GLRendererTest2, transparentBackground)
411 { 411 {
412 FakeRendererClient mockClient; 412 FakeRendererClient mockClient;
413 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); 413 scoped_ptr<GraphicsContext> outputSurface(FakeOutputSurface::Create(scoped_p tr<WebKit::WebGraphicsContext3D>(new ClearCountingContext)));
414 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur face->context3D()); 414 ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSur face->Context3D());
415 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get())); 415 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get()));
416 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 416 FakeRendererGL renderer(&mockClient, resourceProvider.get());
417 417
418 mockClient.rootRenderPass()->has_transparent_background = true; 418 mockClient.rootRenderPass()->has_transparent_background = true;
419 419
420 EXPECT_TRUE(renderer.initialize()); 420 EXPECT_TRUE(renderer.initialize());
421 421
422 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa sses()); 422 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa sses());
423 423
424 EXPECT_EQ(1, context->clearCount()); 424 EXPECT_EQ(1, context->clearCount());
(...skipping 29 matching lines...) Expand all
454 // Methods added for test. 454 // Methods added for test.
455 void setLastCallWasSetVisibilityPointer(bool* lastCallWasSetVisibility) { m_ lastCallWasSetVisibility = lastCallWasSetVisibility; } 455 void setLastCallWasSetVisibilityPointer(bool* lastCallWasSetVisibility) { m_ lastCallWasSetVisibility = lastCallWasSetVisibility; }
456 456
457 private: 457 private:
458 bool* m_lastCallWasSetVisibility; 458 bool* m_lastCallWasSetVisibility;
459 }; 459 };
460 460
461 TEST(GLRendererTest2, visibilityChangeIsLastCall) 461 TEST(GLRendererTest2, visibilityChangeIsLastCall)
462 { 462 {
463 FakeRendererClient mockClient; 463 FakeRendererClient mockClient;
464 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new VisibilityChangeIsLastCallTrac kingContext))); 464 scoped_ptr<GraphicsContext> outputSurface(FakeOutputSurface::Create(scoped_p tr<WebKit::WebGraphicsContext3D>(new VisibilityChangeIsLastCallTrackingContext)) );
465 VisibilityChangeIsLastCallTrackingContext* context = static_cast<VisibilityC hangeIsLastCallTrackingContext*>(outputSurface->context3D()); 465 VisibilityChangeIsLastCallTrackingContext* context = static_cast<VisibilityC hangeIsLastCallTrackingContext*>(outputSurface->Context3D());
466 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get())); 466 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get()));
467 FakeRendererGL renderer(&mockClient, resourceProvider.get()); 467 FakeRendererGL renderer(&mockClient, resourceProvider.get());
468 468
469 EXPECT_TRUE(renderer.initialize()); 469 EXPECT_TRUE(renderer.initialize());
470 470
471 bool lastCallWasSetVisiblity = false; 471 bool lastCallWasSetVisiblity = false;
472 // Ensure that the call to setVisibilityCHROMIUM is the last call issue to t he GPU 472 // Ensure that the call to setVisibilityCHROMIUM is the last call issue to t he GPU
473 // process, after glFlush is called, and after the RendererClient's enforceM anagedMemoryPolicy 473 // process, after glFlush is called, and after the RendererClient's enforceM anagedMemoryPolicy
474 // is called. Plumb this tracking between both the RenderClient and the Cont ext by giving 474 // is called. Plumb this tracking between both the RenderClient and the Cont ext by giving
475 // them both a pointer to a variable on the stack. 475 // them both a pointer to a variable on the stack.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 WGC3Denum activeTexture() const { return m_activeTexture; } 516 WGC3Denum activeTexture() const { return m_activeTexture; }
517 517
518 private: 518 private:
519 bool m_inDraw; 519 bool m_inDraw;
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<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))) ; 526 scoped_ptr<GraphicsContext> outputSurface(FakeOutputSurface::Create(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 EXPECT_TRUE(renderer.initialize()); 531 EXPECT_TRUE(renderer.initialize());
532 532
533 cc::RenderPass::Id id(1, 1); 533 cc::RenderPass::Id id(1, 1);
534 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); 534 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create();
535 pass->SetNew(id, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 100, 100), gfx:: Transform()); 535 pass->SetNew(id, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 100, 100), gfx:: Transform());
536 pass->AppendOneOfEveryQuadType(resourceProvider.get()); 536 pass->AppendOneOfEveryQuadType(resourceProvider.get());
537 537
538 context->setInDraw(); 538 context->setInDraw();
539 539
540 cc::DirectRenderer::DrawingFrame drawingFrame; 540 cc::DirectRenderer::DrawingFrame drawingFrame;
541 renderer.beginDrawingFrame(drawingFrame); 541 renderer.beginDrawingFrame(drawingFrame);
542 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); 542 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0);
543 543
544 for (cc::QuadList::backToFrontIterator it = pass->quad_list.backToFrontBegin (); 544 for (cc::QuadList::backToFrontIterator it = pass->quad_list.backToFrontBegin ();
545 it != pass->quad_list.backToFrontEnd(); ++it) { 545 it != pass->quad_list.backToFrontEnd(); ++it) {
546 renderer.drawQuad(drawingFrame, *it); 546 renderer.drawQuad(drawingFrame, *it);
547 } 547 }
548 renderer.finishDrawingQuadList(); 548 renderer.finishDrawingQuadList();
549 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); 549 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0);
550 } 550 }
551 551
552 } // namespace 552 } // namespace
553 } // namespace cc 553 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698