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

Side by Side Diff: gpu/command_buffer/service/framebuffer_manager_unittest.cc

Issue 315283002: Framebuffer clear() needs to consider the situation some draw buffers are disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "gpu/command_buffer/service/error_state_mock.h" 5 #include "gpu/command_buffer/service/error_state_mock.h"
6 #include "gpu/command_buffer/service/framebuffer_manager.h" 6 #include "gpu/command_buffer/service/framebuffer_manager.h"
7 #include "gpu/command_buffer/service/feature_info.h" 7 #include "gpu/command_buffer/service/feature_info.h"
8 #include "gpu/command_buffer/service/renderbuffer_manager.h" 8 #include "gpu/command_buffer/service/renderbuffer_manager.h"
9 #include "gpu/command_buffer/service/test_helper.h" 9 #include "gpu/command_buffer/service/test_helper.h"
10 #include "gpu/command_buffer/service/texture_manager.h" 10 #include "gpu/command_buffer/service/texture_manager.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gl/gl_mock.h" 12 #include "ui/gl/gl_mock.h"
13 13
14 using ::testing::_;
14 using ::testing::Return; 15 using ::testing::Return;
15 16
16 namespace gpu { 17 namespace gpu {
17 namespace gles2 { 18 namespace gles2 {
18 namespace { 19 namespace {
19 20
20 const GLint kMaxTextureSize = 64; 21 const GLint kMaxTextureSize = 64;
21 const GLint kMaxCubemapSize = 64; 22 const GLint kMaxCubemapSize = 64;
22 const GLint kMaxRenderbufferSize = 64; 23 const GLint kMaxRenderbufferSize = 64;
23 const GLint kMaxSamples = 4; 24 const GLint kMaxSamples = 4;
25 const uint32 kMaxDrawBuffers = 16;
26 const uint32 kMaxColorAttachments = 16;
24 const bool kDepth24Supported = false; 27 const bool kDepth24Supported = false;
25 const bool kUseDefaultTextures = false; 28 const bool kUseDefaultTextures = false;
26 29
27 } // namespace 30 } // namespace
28 31
29 class FramebufferManagerTest : public testing::Test { 32 class FramebufferManagerTest : public testing::Test {
30 public: 33 public:
31 FramebufferManagerTest() 34 FramebufferManagerTest()
32 : manager_(1, 1), 35 : manager_(1, 1),
33 texture_manager_(NULL, 36 texture_manager_(NULL,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 framebuffer1 = manager_.GetFramebuffer(kClient1Id); 109 framebuffer1 = manager_.GetFramebuffer(kClient1Id);
107 ASSERT_TRUE(framebuffer1 == NULL); 110 ASSERT_TRUE(framebuffer1 == NULL);
108 } 111 }
109 112
110 class FramebufferInfoTest : public testing::Test { 113 class FramebufferInfoTest : public testing::Test {
111 public: 114 public:
112 static const GLuint kClient1Id = 1; 115 static const GLuint kClient1Id = 1;
113 static const GLuint kService1Id = 11; 116 static const GLuint kService1Id = 11;
114 117
115 FramebufferInfoTest() 118 FramebufferInfoTest()
116 : manager_(1, 1), 119 : manager_(kMaxDrawBuffers, kMaxColorAttachments),
117 feature_info_(new FeatureInfo()), 120 feature_info_(new FeatureInfo()),
118 renderbuffer_manager_(NULL, kMaxRenderbufferSize, kMaxSamples, 121 renderbuffer_manager_(NULL, kMaxRenderbufferSize, kMaxSamples,
119 kDepth24Supported) { 122 kDepth24Supported) {
120 texture_manager_.reset(new TextureManager(NULL, 123 texture_manager_.reset(new TextureManager(NULL,
121 feature_info_.get(), 124 feature_info_.get(),
122 kMaxTextureSize, 125 kMaxTextureSize,
123 kMaxCubemapSize, 126 kMaxCubemapSize,
124 kUseDefaultTextures)); 127 kUseDefaultTextures));
125 } 128 }
126 virtual ~FramebufferInfoTest() { 129 virtual ~FramebufferInfoTest() {
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 // Check removing it. 586 // Check removing it.
584 framebuffer_->AttachTexture(GL_COLOR_ATTACHMENT0, NULL, 0, 0, 0); 587 framebuffer_->AttachTexture(GL_COLOR_ATTACHMENT0, NULL, 0, 0, 0);
585 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL); 588 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL);
586 EXPECT_EQ(static_cast<GLenum>(0), framebuffer_->GetColorAttachmentFormat()); 589 EXPECT_EQ(static_cast<GLenum>(0), framebuffer_->GetColorAttachmentFormat());
587 590
588 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT), 591 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT),
589 framebuffer_->IsPossiblyComplete()); 592 framebuffer_->IsPossiblyComplete());
590 EXPECT_TRUE(framebuffer_->IsCleared()); 593 EXPECT_TRUE(framebuffer_->IsCleared());
591 } 594 }
592 595
596 TEST_F(FramebufferInfoTest, DrawBuffers) {
597 const GLuint kTextureClientId[] = { 33, 34 };
598 const GLuint kTextureServiceId[] = { 333, 334 };
599
600 for (GLenum i = GL_COLOR_ATTACHMENT0;
601 i < GL_COLOR_ATTACHMENT0 + kMaxColorAttachments; ++i) {
602 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(i));
603 }
604 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments());
605
606 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT0),
607 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER0_ARB));
608 for (GLenum i = GL_DRAW_BUFFER1_ARB;
609 i < GL_DRAW_BUFFER0_ARB + kMaxDrawBuffers; ++i) {
610 EXPECT_EQ(static_cast<GLenum>(GL_NONE),
611 framebuffer_->GetDrawBuffer(i));
612 }
613
614 for (size_t ii = 0; ii < arraysize(kTextureClientId); ++ii) {
615 texture_manager_->CreateTexture(
616 kTextureClientId[ii], kTextureServiceId[ii]);
617 scoped_refptr<TextureRef> texture(
618 texture_manager_->GetTexture(kTextureClientId[ii]));
619 ASSERT_TRUE(texture.get() != NULL);
620
621 framebuffer_->AttachTexture(
622 GL_COLOR_ATTACHMENT0 + ii, texture.get(), GL_TEXTURE_2D, 0, 0);
623 EXPECT_FALSE(
624 framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0 + ii));
625
626 const Framebuffer::Attachment* attachment =
627 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0 + ii);
628 ASSERT_TRUE(attachment != NULL);
629 EXPECT_TRUE(attachment->cleared());
630 }
631 EXPECT_TRUE(framebuffer_->IsCleared());
632 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments());
633
634 // Set a texture as uncleared.
635 scoped_refptr<TextureRef> texture1(
636 texture_manager_->GetTexture(kTextureClientId[1]));
637 texture_manager_->SetTarget(texture1.get(), GL_TEXTURE_2D);
638 texture_manager_->SetLevelInfo(
639 texture1.get(), GL_TEXTURE_2D, 0, GL_RGBA, 4, 4,
640 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, false);
641
642 const Framebuffer::Attachment* attachment1 =
643 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT1);
644 ASSERT_TRUE(attachment1 != NULL);
645 EXPECT_FALSE(attachment1->cleared());
646 EXPECT_FALSE(framebuffer_->IsCleared());
647 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT1));
648 EXPECT_TRUE(framebuffer_->HasUnclearedColorAttachments());
649
650 GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
651 framebuffer_->SetDrawBuffers(2, buffers);
652 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT0),
653 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER0_ARB));
654 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT1),
655 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER1_ARB));
656 for (GLenum i = GL_DRAW_BUFFER2_ARB;
657 i < GL_DRAW_BUFFER0_ARB + kMaxDrawBuffers; ++i) {
658 EXPECT_EQ(static_cast<GLenum>(GL_NONE),
659 framebuffer_->GetDrawBuffer(i));
660 }
661
662 // Nothing happens.
663 framebuffer_->PrepareDrawBuffersForClear();
664 framebuffer_->RestoreDrawBuffersAfterClear();
665
666 // Now we disable a draw buffer 1.
667 buffers[1] = GL_NONE;
668 framebuffer_->SetDrawBuffers(2, buffers);
669 // We will enable the disabled draw buffer for clear(), and disable it
670 // after the clear.
671 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
672 .Times(1)
673 .RetiresOnSaturation();
674 framebuffer_->PrepareDrawBuffersForClear();
675 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
676 .Times(1)
677 .RetiresOnSaturation();
678 framebuffer_->RestoreDrawBuffersAfterClear();
679
680 // Now remove draw buffer 1's attachment.
681 framebuffer_->AttachTexture(GL_COLOR_ATTACHMENT1, NULL, 0, 0, 0);
682 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT1) == NULL);
683
684 // Nothing happens.
685 framebuffer_->PrepareDrawBuffersForClear();
686 framebuffer_->RestoreDrawBuffersAfterClear();
687 }
688
593 class FramebufferInfoFloatTest : public FramebufferInfoTest { 689 class FramebufferInfoFloatTest : public FramebufferInfoTest {
594 public: 690 public:
595 FramebufferInfoFloatTest() 691 FramebufferInfoFloatTest()
596 : FramebufferInfoTest() { 692 : FramebufferInfoTest() {
597 } 693 }
598 virtual ~FramebufferInfoFloatTest() { 694 virtual ~FramebufferInfoFloatTest() {
599 } 695 }
600 696
601 protected: 697 protected:
602 virtual void SetUp() { 698 virtual void SetUp() {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)) 982 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
887 .RetiresOnSaturation(); 983 .RetiresOnSaturation();
888 } 984 }
889 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER); 985 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
890 } 986 }
891 987
892 } // namespace gles2 988 } // namespace gles2
893 } // namespace gpu 989 } // namespace gpu
894 990
895 991
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/framebuffer_manager.cc ('k') | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698