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

Side by Side Diff: cc/gl_renderer_unittest.cc

Issue 11358181: Use nearest neighbor filtering for non-translated quads (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Associate resources with min/mag filters and use NEAREST for tile quads when feasible. Created 8 years, 1 month 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_web_compositor_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 <public/WebTransformationMatrix.h> 16 #include <public/WebTransformationMatrix.h>
17 17
18 using namespace WebKit; 18 using namespace WebKit;
19 using namespace WebKitTests; 19 using namespace WebKitTests;
20 20
21 using testing::_;
22 using testing::AnyNumber;
23 using testing::InSequence;
24 using testing::Mock;
25
21 namespace cc { 26 namespace cc {
22 namespace { 27 namespace {
23 28
24 class FrameCountingMemoryAllocationSettingContext : public FakeWebGraphicsContex t3D { 29 class FrameCountingMemoryAllocationSettingContext : public FakeWebGraphicsContex t3D {
25 public: 30 public:
26 FrameCountingMemoryAllocationSettingContext() : m_frame(0) { } 31 FrameCountingMemoryAllocationSettingContext() : m_frame(0) { }
27 32
28 // WebGraphicsContext3D methods. 33 // WebGraphicsContext3D methods.
29 34
30 // This method would normally do a glSwapBuffers under the hood. 35 // This method would normally do a glSwapBuffers under the hood.
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // is called. Plumb this tracking between both the RenderClient and the Cont ext by giving 478 // is called. Plumb this tracking between both the RenderClient and the Cont ext by giving
474 // them both a pointer to a variable on the stack. 479 // them both a pointer to a variable on the stack.
475 context->setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); 480 context->setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity);
476 mockClient.setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity); 481 mockClient.setLastCallWasSetVisibilityPointer(&lastCallWasSetVisiblity);
477 renderer.setVisible(true); 482 renderer.setVisible(true);
478 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa sses()); 483 renderer.drawFrame(mockClient.renderPassesInDrawOrder(), mockClient.renderPa sses());
479 renderer.setVisible(false); 484 renderer.setVisible(false);
480 EXPECT_TRUE(lastCallWasSetVisiblity); 485 EXPECT_TRUE(lastCallWasSetVisiblity);
481 } 486 }
482 487
483
484 class TextureStateTrackingContext : public FakeWebGraphicsContext3D { 488 class TextureStateTrackingContext : public FakeWebGraphicsContext3D {
485 public: 489 public:
486 TextureStateTrackingContext() 490 TextureStateTrackingContext()
487 : m_activeTexture(GL_INVALID_ENUM) 491 : m_activeTexture(GL_INVALID_ENUM)
488 , m_inDraw(false)
489 { 492 {
490 } 493 }
491 494
492 virtual WebString getString(WGC3Denum name) 495 virtual WebString getString(WGC3Denum name)
493 { 496 {
494 if (name == GL_EXTENSIONS) 497 if (name == GL_EXTENSIONS)
495 return WebString("GL_OES_EGL_image_external"); 498 return WebString("GL_OES_EGL_image_external");
496 return WebString(); 499 return WebString();
497 } 500 }
498 501
499 // We shouldn't set any texture parameters during the draw sequence, althoug h 502 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint param));
500 // we might when creating the quads. 503 MOCK_METHOD4(drawElements, void(WGC3Denum mode, WGC3Dsizei count, WGC3Denum type, WGC3Dintptr offset));
501 void setInDraw() { m_inDraw = true; }
502
503 virtual void texParameteri(WGC3Denum target, WGC3Denum pname, WGC3Dint param )
504 {
505 if (m_inDraw)
506 ADD_FAILURE();
507 }
508 504
509 virtual void activeTexture(WGC3Denum texture) 505 virtual void activeTexture(WGC3Denum texture)
510 { 506 {
511 EXPECT_NE(texture, m_activeTexture); 507 EXPECT_NE(texture, m_activeTexture);
512 m_activeTexture = texture; 508 m_activeTexture = texture;
513 } 509 }
514 510
515 WGC3Denum activeTexture() const { return m_activeTexture; } 511 WGC3Denum activeTexture() const { return m_activeTexture; }
516 512
517 private: 513 private:
518 bool m_inDraw;
519 WGC3Denum m_activeTexture; 514 WGC3Denum m_activeTexture;
520 }; 515 };
521 516
522 TEST(GLRendererTest2, activeTextureState) 517 TEST(GLRendererTest2, activeTextureState)
523 { 518 {
524 FakeRendererClient fakeClient; 519 FakeRendererClient fakeClient;
525 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))) ; 520 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))) ;
526 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte xt*>(outputSurface->context3D()); 521 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte xt*>(outputSurface->context3D());
527 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get())); 522 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get()));
528 FakeRendererGL renderer(&fakeClient, resourceProvider.get()); 523 FakeRendererGL renderer(&fakeClient, resourceProvider.get());
529 524
525 // During initialization we are allowed to set any texture parameters.
526 EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber());
530 EXPECT_TRUE(renderer.initialize()); 527 EXPECT_TRUE(renderer.initialize());
531 528
532 cc::RenderPass::Id id(1, 1); 529 cc::RenderPass::Id id(1, 1);
533 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); 530 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create();
534 pass->SetNew(id, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 100, 100), WebTr ansformationMatrix()); 531 pass->SetNew(id, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 100, 100), WebTr ansformationMatrix());
535 pass->AppendOneOfEveryQuadType(resourceProvider.get()); 532 pass->AppendOneOfEveryQuadType(resourceProvider.get());
536 533
537 context->setInDraw(); 534 // Set up expected texture filter state transitions that match the quads
535 // created in AppendOneOfEveryQuadType().
536 Mock::VerifyAndClearExpectations(context);
537 {
538 InSequence sequence;
539
540 // yuv_quad is drawn with the default filter.
541 EXPECT_CALL(*context, drawElements(_, _, _, _));
542
543 // tile_quad is drawn with GL_NEAREST because it is not transformed or
544 // scaled.
545 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_NEAREST));
546 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_NEAREST));
547 EXPECT_CALL(*context, drawElements(_, _, _, _));
548
549 // transformed_tile_quad uses GL_LINEAR.
550 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR));
551 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR));
552 EXPECT_CALL(*context, drawElements(_, _, _, _));
553
554 // scaled_tile_quad also uses GL_LINEAR.
555 EXPECT_CALL(*context, drawElements(_, _, _, _));
556
557 // The remaining quads also use GL_LINEAR because nearest neighbor
558 // filtering is currently only used with tile quads.
559 EXPECT_CALL(*context, drawElements(_, _, _, _)).Times(6);
560 }
538 561
539 cc::DirectRenderer::DrawingFrame drawingFrame; 562 cc::DirectRenderer::DrawingFrame drawingFrame;
540 renderer.beginDrawingFrame(drawingFrame); 563 renderer.beginDrawingFrame(drawingFrame);
541 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); 564 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0);
542 565
543 for (cc::QuadList::backToFrontIterator it = pass->quad_list.backToFrontBegin (); 566 for (cc::QuadList::backToFrontIterator it = pass->quad_list.backToFrontBegin ();
544 it != pass->quad_list.backToFrontEnd(); ++it) { 567 it != pass->quad_list.backToFrontEnd(); ++it) {
545 renderer.drawQuad(drawingFrame, *it); 568 renderer.drawQuad(drawingFrame, *it);
546 } 569 }
547 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); 570 EXPECT_EQ(context->activeTexture(), GL_TEXTURE0);
571 Mock::VerifyAndClearExpectations(context);
548 } 572 }
549 573
550 } // namespace 574 } // namespace
551 } // namespace cc 575 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698