Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / gpu / command_buffer / service / framebuffer_manager_unittest.cc
blobe1af82d1059be87d63561312c2dfe4bf30be90d2
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
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/error_state_mock.h"
6 #include "gpu/command_buffer/service/framebuffer_manager.h"
7 #include "gpu/command_buffer/service/feature_info.h"
8 #include "gpu/command_buffer/service/gpu_service_test.h"
9 #include "gpu/command_buffer/service/renderbuffer_manager.h"
10 #include "gpu/command_buffer/service/test_helper.h"
11 #include "gpu/command_buffer/service/texture_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gl/gl_mock.h"
15 using ::testing::_;
16 using ::testing::Return;
18 namespace gpu {
19 namespace gles2 {
20 namespace {
22 const GLint kMaxTextureSize = 64;
23 const GLint kMaxCubemapSize = 64;
24 const GLint kMaxRectangleTextureSize = 64;
25 const GLint kMax3DTextureSize = 256;
26 const GLint kMaxRenderbufferSize = 64;
27 const GLint kMaxSamples = 4;
28 const uint32 kMaxDrawBuffers = 16;
29 const uint32 kMaxColorAttachments = 16;
30 const bool kUseDefaultTextures = false;
32 } // namespace
34 class FramebufferManagerTest : public GpuServiceTest {
35 public:
36 FramebufferManagerTest()
37 : manager_(1, 1),
38 feature_info_(new FeatureInfo()) {
39 texture_manager_.reset(new TextureManager(NULL,
40 feature_info_.get(),
41 kMaxTextureSize,
42 kMaxCubemapSize,
43 kMaxRectangleTextureSize,
44 kMax3DTextureSize,
45 kUseDefaultTextures));
46 renderbuffer_manager_.reset(new RenderbufferManager(NULL,
47 kMaxRenderbufferSize,
48 kMaxSamples,
49 feature_info_.get()));
51 ~FramebufferManagerTest() override {
52 manager_.Destroy(false);
53 texture_manager_->Destroy(false);
54 renderbuffer_manager_->Destroy(false);
57 protected:
59 FramebufferManager manager_;
60 scoped_refptr<FeatureInfo> feature_info_;
61 scoped_ptr<TextureManager> texture_manager_;
62 scoped_ptr<RenderbufferManager> renderbuffer_manager_;
65 TEST_F(FramebufferManagerTest, Basic) {
66 const GLuint kClient1Id = 1;
67 const GLuint kService1Id = 11;
68 const GLuint kClient2Id = 2;
69 // Check we can create framebuffer.
70 manager_.CreateFramebuffer(kClient1Id, kService1Id);
71 // Check framebuffer got created.
72 Framebuffer* framebuffer1 = manager_.GetFramebuffer(kClient1Id);
73 ASSERT_TRUE(framebuffer1 != NULL);
74 EXPECT_FALSE(framebuffer1->IsDeleted());
75 EXPECT_EQ(kService1Id, framebuffer1->service_id());
76 GLuint client_id = 0;
77 EXPECT_TRUE(manager_.GetClientId(framebuffer1->service_id(), &client_id));
78 EXPECT_EQ(kClient1Id, client_id);
79 // Check we get nothing for a non-existent framebuffer.
80 EXPECT_TRUE(manager_.GetFramebuffer(kClient2Id) == NULL);
81 // Check trying to a remove non-existent framebuffers does not crash.
82 manager_.RemoveFramebuffer(kClient2Id);
83 // Check framebuffer gets deleted when last reference is released.
84 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, ::testing::Pointee(kService1Id)))
85 .Times(1)
86 .RetiresOnSaturation();
87 // Check we can't get the framebuffer after we remove it.
88 manager_.RemoveFramebuffer(kClient1Id);
89 EXPECT_TRUE(manager_.GetFramebuffer(kClient1Id) == NULL);
92 TEST_F(FramebufferManagerTest, Destroy) {
93 const GLuint kClient1Id = 1;
94 const GLuint kService1Id = 11;
95 // Check we can create framebuffer.
96 manager_.CreateFramebuffer(kClient1Id, kService1Id);
97 // Check framebuffer got created.
98 Framebuffer* framebuffer1 = manager_.GetFramebuffer(kClient1Id);
99 ASSERT_TRUE(framebuffer1 != NULL);
100 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, ::testing::Pointee(kService1Id)))
101 .Times(1)
102 .RetiresOnSaturation();
103 manager_.Destroy(true);
104 // Check the resources were released.
105 framebuffer1 = manager_.GetFramebuffer(kClient1Id);
106 ASSERT_TRUE(framebuffer1 == NULL);
109 class FramebufferInfoTest : public GpuServiceTest {
110 public:
111 static const GLuint kClient1Id = 1;
112 static const GLuint kService1Id = 11;
114 FramebufferInfoTest()
115 : manager_(kMaxDrawBuffers, kMaxColorAttachments),
116 feature_info_(new FeatureInfo()) {
117 texture_manager_.reset(new TextureManager(NULL,
118 feature_info_.get(),
119 kMaxTextureSize,
120 kMaxCubemapSize,
121 kMaxRectangleTextureSize,
122 kMax3DTextureSize,
123 kUseDefaultTextures));
124 renderbuffer_manager_.reset(new RenderbufferManager(NULL,
125 kMaxRenderbufferSize,
126 kMaxSamples,
127 feature_info_.get()));
129 ~FramebufferInfoTest() override {
130 manager_.Destroy(false);
131 texture_manager_->Destroy(false);
132 renderbuffer_manager_->Destroy(false);
135 protected:
136 void SetUp() override {
137 InitializeContext("2.0", "GL_EXT_framebuffer_object");
140 void InitializeContext(const char* gl_version, const char* extensions) {
141 GpuServiceTest::SetUpWithGLVersion(gl_version, extensions);
142 TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion(gl_.get(),
143 extensions, "", gl_version);
144 feature_info_->Initialize();
145 manager_.CreateFramebuffer(kClient1Id, kService1Id);
146 error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>());
147 framebuffer_ = manager_.GetFramebuffer(kClient1Id);
148 ASSERT_TRUE(framebuffer_ != NULL);
151 FramebufferManager manager_;
152 Framebuffer* framebuffer_;
153 scoped_refptr<FeatureInfo> feature_info_;
154 scoped_ptr<TextureManager> texture_manager_;
155 scoped_ptr<RenderbufferManager> renderbuffer_manager_;
156 scoped_ptr<MockErrorState> error_state_;
159 // GCC requires these declarations, but MSVC requires they not be present
160 #ifndef COMPILER_MSVC
161 const GLuint FramebufferInfoTest::kClient1Id;
162 const GLuint FramebufferInfoTest::kService1Id;
163 #endif
165 TEST_F(FramebufferInfoTest, Basic) {
166 EXPECT_EQ(kService1Id, framebuffer_->service_id());
167 EXPECT_FALSE(framebuffer_->IsDeleted());
168 EXPECT_TRUE(NULL == framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0));
169 EXPECT_TRUE(NULL == framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT));
170 EXPECT_TRUE(NULL == framebuffer_->GetAttachment(GL_STENCIL_ATTACHMENT));
171 EXPECT_TRUE(
172 NULL == framebuffer_->GetAttachment(GL_DEPTH_STENCIL_ATTACHMENT));
173 EXPECT_FALSE(framebuffer_->HasDepthAttachment());
174 EXPECT_FALSE(framebuffer_->HasStencilAttachment());
175 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT),
176 framebuffer_->IsPossiblyComplete());
177 EXPECT_TRUE(framebuffer_->IsCleared());
178 EXPECT_EQ(static_cast<GLenum>(0), framebuffer_->GetColorAttachmentFormat());
179 EXPECT_FALSE(manager_.IsComplete(framebuffer_));
182 TEST_F(FramebufferInfoTest, AttachRenderbuffer) {
183 const GLuint kRenderbufferClient1Id = 33;
184 const GLuint kRenderbufferService1Id = 333;
185 const GLuint kRenderbufferClient2Id = 34;
186 const GLuint kRenderbufferService2Id = 334;
187 const GLuint kRenderbufferClient3Id = 35;
188 const GLuint kRenderbufferService3Id = 335;
189 const GLuint kRenderbufferClient4Id = 36;
190 const GLuint kRenderbufferService4Id = 336;
191 const GLsizei kWidth1 = 16;
192 const GLsizei kHeight1 = 32;
193 const GLenum kFormat1 = GL_RGBA4;
194 const GLenum kBadFormat1 = GL_DEPTH_COMPONENT16;
195 const GLsizei kSamples1 = 0;
196 const GLsizei kWidth2 = 16;
197 const GLsizei kHeight2 = 32;
198 const GLenum kFormat2 = GL_DEPTH_COMPONENT16;
199 const GLsizei kSamples2 = 0;
200 const GLsizei kWidth3 = 16;
201 const GLsizei kHeight3 = 32;
202 const GLenum kFormat3 = GL_STENCIL_INDEX8;
203 const GLsizei kSamples3 = 0;
204 const GLsizei kWidth4 = 16;
205 const GLsizei kHeight4 = 32;
206 const GLenum kFormat4 = GL_STENCIL_INDEX8;
207 const GLsizei kSamples4 = 0;
209 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
210 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
211 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
212 EXPECT_FALSE(
213 framebuffer_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT));
215 renderbuffer_manager_->CreateRenderbuffer(
216 kRenderbufferClient1Id, kRenderbufferService1Id);
217 Renderbuffer* renderbuffer1 =
218 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient1Id);
219 ASSERT_TRUE(renderbuffer1 != NULL);
221 // check adding one attachment
222 framebuffer_->AttachRenderbuffer(GL_COLOR_ATTACHMENT0, renderbuffer1);
223 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
224 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
225 EXPECT_EQ(static_cast<GLenum>(GL_RGBA4),
226 framebuffer_->GetColorAttachmentFormat());
227 EXPECT_FALSE(framebuffer_->HasDepthAttachment());
228 EXPECT_FALSE(framebuffer_->HasStencilAttachment());
229 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
230 framebuffer_->IsPossiblyComplete());
231 EXPECT_TRUE(framebuffer_->IsCleared());
233 // Try a format that's not good for COLOR_ATTACHMENT0.
234 renderbuffer_manager_->SetInfo(
235 renderbuffer1, kSamples1, kBadFormat1, kWidth1, kHeight1);
236 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
237 framebuffer_->IsPossiblyComplete());
239 // Try a good format.
240 renderbuffer_manager_->SetInfo(
241 renderbuffer1, kSamples1, kFormat1, kWidth1, kHeight1);
242 EXPECT_EQ(static_cast<GLenum>(kFormat1),
243 framebuffer_->GetColorAttachmentFormat());
244 EXPECT_FALSE(framebuffer_->HasDepthAttachment());
245 EXPECT_FALSE(framebuffer_->HasStencilAttachment());
246 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
247 framebuffer_->IsPossiblyComplete());
248 EXPECT_FALSE(framebuffer_->IsCleared());
250 // check adding another
251 renderbuffer_manager_->CreateRenderbuffer(
252 kRenderbufferClient2Id, kRenderbufferService2Id);
253 Renderbuffer* renderbuffer2 =
254 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient2Id);
255 ASSERT_TRUE(renderbuffer2 != NULL);
256 framebuffer_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, renderbuffer2);
257 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
258 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
259 EXPECT_EQ(static_cast<GLenum>(kFormat1),
260 framebuffer_->GetColorAttachmentFormat());
261 EXPECT_TRUE(framebuffer_->HasDepthAttachment());
262 EXPECT_FALSE(framebuffer_->HasStencilAttachment());
263 // The attachment has a size of 0,0 so depending on the order of the map
264 // of attachments it could either get INCOMPLETE_ATTACHMENT because it's 0,0
265 // or INCOMPLETE_DIMENSIONS because it's not the same size as the other
266 // attachment.
267 GLenum status = framebuffer_->IsPossiblyComplete();
268 EXPECT_TRUE(
269 status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT ||
270 status == GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT);
271 EXPECT_FALSE(framebuffer_->IsCleared());
273 renderbuffer_manager_->SetInfo(
274 renderbuffer2, kSamples2, kFormat2, kWidth2, kHeight2);
275 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
276 framebuffer_->IsPossiblyComplete());
277 EXPECT_FALSE(framebuffer_->IsCleared());
278 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
280 // check marking them as cleared.
281 manager_.MarkAttachmentsAsCleared(
282 framebuffer_, renderbuffer_manager_.get(), texture_manager_.get());
283 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
284 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
285 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
286 framebuffer_->IsPossiblyComplete());
287 EXPECT_TRUE(framebuffer_->IsCleared());
289 // Check adding one that is already cleared.
290 renderbuffer_manager_->CreateRenderbuffer(
291 kRenderbufferClient3Id, kRenderbufferService3Id);
292 Renderbuffer* renderbuffer3 =
293 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient3Id);
294 ASSERT_TRUE(renderbuffer3 != NULL);
295 renderbuffer_manager_->SetInfo(
296 renderbuffer3, kSamples3, kFormat3, kWidth3, kHeight3);
297 renderbuffer_manager_->SetCleared(renderbuffer3, true);
299 framebuffer_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, renderbuffer3);
300 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
301 EXPECT_EQ(static_cast<GLenum>(kFormat1),
302 framebuffer_->GetColorAttachmentFormat());
303 EXPECT_TRUE(framebuffer_->HasDepthAttachment());
304 EXPECT_TRUE(framebuffer_->HasStencilAttachment());
305 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
306 framebuffer_->IsPossiblyComplete());
307 EXPECT_TRUE(framebuffer_->IsCleared());
309 // Check marking the renderbuffer as unclared.
310 renderbuffer_manager_->SetInfo(
311 renderbuffer1, kSamples1, kFormat1, kWidth1, kHeight1);
312 EXPECT_EQ(static_cast<GLenum>(kFormat1),
313 framebuffer_->GetColorAttachmentFormat());
314 EXPECT_TRUE(framebuffer_->HasDepthAttachment());
315 EXPECT_TRUE(framebuffer_->HasStencilAttachment());
316 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
317 framebuffer_->IsPossiblyComplete());
318 EXPECT_FALSE(framebuffer_->IsCleared());
320 const Framebuffer::Attachment* attachment =
321 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0);
322 ASSERT_TRUE(attachment != NULL);
323 EXPECT_EQ(kWidth1, attachment->width());
324 EXPECT_EQ(kHeight1, attachment->height());
325 EXPECT_EQ(kSamples1, attachment->samples());
326 EXPECT_EQ(kFormat1, attachment->internal_format());
327 EXPECT_FALSE(attachment->cleared());
329 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
331 // Clear it.
332 manager_.MarkAttachmentsAsCleared(
333 framebuffer_, renderbuffer_manager_.get(), texture_manager_.get());
334 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
335 EXPECT_TRUE(framebuffer_->IsCleared());
337 // Check replacing an attachment
338 renderbuffer_manager_->CreateRenderbuffer(
339 kRenderbufferClient4Id, kRenderbufferService4Id);
340 Renderbuffer* renderbuffer4 =
341 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient4Id);
342 ASSERT_TRUE(renderbuffer4 != NULL);
343 renderbuffer_manager_->SetInfo(
344 renderbuffer4, kSamples4, kFormat4, kWidth4, kHeight4);
346 framebuffer_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, renderbuffer4);
347 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
348 EXPECT_FALSE(framebuffer_->IsCleared());
350 attachment = framebuffer_->GetAttachment(GL_STENCIL_ATTACHMENT);
351 ASSERT_TRUE(attachment != NULL);
352 EXPECT_EQ(kWidth4, attachment->width());
353 EXPECT_EQ(kHeight4, attachment->height());
354 EXPECT_EQ(kSamples4, attachment->samples());
355 EXPECT_EQ(kFormat4, attachment->internal_format());
356 EXPECT_FALSE(attachment->cleared());
357 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
358 framebuffer_->IsPossiblyComplete());
360 // Check changing an attachment.
361 renderbuffer_manager_->SetInfo(
362 renderbuffer4, kSamples4, kFormat4, kWidth4 + 1, kHeight4);
364 attachment = framebuffer_->GetAttachment(GL_STENCIL_ATTACHMENT);
365 ASSERT_TRUE(attachment != NULL);
366 EXPECT_EQ(kWidth4 + 1, attachment->width());
367 EXPECT_EQ(kHeight4, attachment->height());
368 EXPECT_EQ(kSamples4, attachment->samples());
369 EXPECT_EQ(kFormat4, attachment->internal_format());
370 EXPECT_FALSE(attachment->cleared());
371 EXPECT_FALSE(framebuffer_->IsCleared());
372 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT),
373 framebuffer_->IsPossiblyComplete());
375 // Check removing it.
376 framebuffer_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, NULL);
377 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
378 EXPECT_EQ(static_cast<GLenum>(kFormat1),
379 framebuffer_->GetColorAttachmentFormat());
380 EXPECT_TRUE(framebuffer_->HasDepthAttachment());
381 EXPECT_FALSE(framebuffer_->HasStencilAttachment());
383 EXPECT_TRUE(framebuffer_->IsCleared());
384 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
385 framebuffer_->IsPossiblyComplete());
387 // Remove depth, Set color to 0 size.
388 framebuffer_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, NULL);
389 renderbuffer_manager_->SetInfo(renderbuffer1, kSamples1, kFormat1, 0, 0);
390 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
391 framebuffer_->IsPossiblyComplete());
393 // Remove color.
394 framebuffer_->AttachRenderbuffer(GL_COLOR_ATTACHMENT0, NULL);
395 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT),
396 framebuffer_->IsPossiblyComplete());
399 TEST_F(FramebufferInfoTest, AttachTexture) {
400 const GLuint kTextureClient1Id = 33;
401 const GLuint kTextureService1Id = 333;
402 const GLuint kTextureClient2Id = 34;
403 const GLuint kTextureService2Id = 334;
404 const GLint kDepth = 1;
405 const GLint kBorder = 0;
406 const GLenum kType = GL_UNSIGNED_BYTE;
407 const GLsizei kWidth1 = 16;
408 const GLsizei kHeight1 = 32;
409 const GLint kLevel1 = 0;
410 const GLenum kFormat1 = GL_RGBA;
411 const GLenum kBadFormat1 = GL_DEPTH_COMPONENT16;
412 const GLenum kTarget1 = GL_TEXTURE_2D;
413 const GLsizei kSamples1 = 0;
414 const GLsizei kWidth2 = 16;
415 const GLsizei kHeight2 = 32;
416 const GLint kLevel2 = 0;
417 const GLenum kFormat2 = GL_RGB;
418 const GLenum kTarget2 = GL_TEXTURE_2D;
419 const GLsizei kSamples2 = 0;
420 const GLsizei kWidth3 = 75;
421 const GLsizei kHeight3 = 123;
422 const GLint kLevel3 = 0;
423 const GLenum kFormat3 = GL_RGB565;
424 const GLsizei kSamples3 = 0;
425 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
426 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
427 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
428 EXPECT_FALSE(
429 framebuffer_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT));
430 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT),
431 framebuffer_->IsPossiblyComplete());
433 texture_manager_->CreateTexture(kTextureClient1Id, kTextureService1Id);
434 scoped_refptr<TextureRef> texture1(
435 texture_manager_->GetTexture(kTextureClient1Id));
436 ASSERT_TRUE(texture1.get() != NULL);
438 // check adding one attachment
439 framebuffer_->AttachTexture(
440 GL_COLOR_ATTACHMENT0, texture1.get(), kTarget1, kLevel1, kSamples1);
441 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
442 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
443 framebuffer_->IsPossiblyComplete());
444 EXPECT_TRUE(framebuffer_->IsCleared());
445 EXPECT_EQ(static_cast<GLenum>(0), framebuffer_->GetColorAttachmentFormat());
447 // Try format that doesn't work with COLOR_ATTACHMENT0
448 texture_manager_->SetTarget(texture1.get(), GL_TEXTURE_2D);
449 texture_manager_->SetLevelInfo(texture1.get(),
450 GL_TEXTURE_2D,
451 kLevel1,
452 kBadFormat1,
453 kWidth1,
454 kHeight1,
455 kDepth,
456 kBorder,
457 kBadFormat1,
458 kType,
459 true);
460 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
461 framebuffer_->IsPossiblyComplete());
463 // Try a good format.
464 texture_manager_->SetLevelInfo(texture1.get(),
465 GL_TEXTURE_2D,
466 kLevel1,
467 kFormat1,
468 kWidth1,
469 kHeight1,
470 kDepth,
471 kBorder,
472 kFormat1,
473 kType,
474 false);
475 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
476 framebuffer_->IsPossiblyComplete());
477 EXPECT_FALSE(framebuffer_->IsCleared());
478 texture_manager_->SetLevelInfo(texture1.get(),
479 GL_TEXTURE_2D,
480 kLevel1,
481 kFormat1,
482 kWidth1,
483 kHeight1,
484 kDepth,
485 kBorder,
486 kFormat1,
487 kType,
488 true);
489 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
490 framebuffer_->IsPossiblyComplete());
491 EXPECT_TRUE(framebuffer_->IsCleared());
492 EXPECT_EQ(static_cast<GLenum>(kFormat1),
493 framebuffer_->GetColorAttachmentFormat());
495 const Framebuffer::Attachment* attachment =
496 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0);
497 ASSERT_TRUE(attachment != NULL);
498 EXPECT_EQ(kWidth1, attachment->width());
499 EXPECT_EQ(kHeight1, attachment->height());
500 EXPECT_EQ(kSamples1, attachment->samples());
501 EXPECT_EQ(kFormat1, attachment->internal_format());
502 EXPECT_TRUE(attachment->cleared());
504 // Check replacing an attachment
505 texture_manager_->CreateTexture(kTextureClient2Id, kTextureService2Id);
506 scoped_refptr<TextureRef> texture2(
507 texture_manager_->GetTexture(kTextureClient2Id));
508 ASSERT_TRUE(texture2.get() != NULL);
509 texture_manager_->SetTarget(texture2.get(), GL_TEXTURE_2D);
510 texture_manager_->SetLevelInfo(texture2.get(),
511 GL_TEXTURE_2D,
512 kLevel2,
513 kFormat2,
514 kWidth2,
515 kHeight2,
516 kDepth,
517 kBorder,
518 kFormat2,
519 kType,
520 true);
522 framebuffer_->AttachTexture(
523 GL_COLOR_ATTACHMENT0, texture2.get(), kTarget2, kLevel2, kSamples2);
524 EXPECT_EQ(static_cast<GLenum>(kFormat2),
525 framebuffer_->GetColorAttachmentFormat());
526 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
527 framebuffer_->IsPossiblyComplete());
528 EXPECT_TRUE(framebuffer_->IsCleared());
530 attachment = framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0);
531 ASSERT_TRUE(attachment != NULL);
532 EXPECT_EQ(kWidth2, attachment->width());
533 EXPECT_EQ(kHeight2, attachment->height());
534 EXPECT_EQ(kSamples2, attachment->samples());
535 EXPECT_EQ(kFormat2, attachment->internal_format());
536 EXPECT_TRUE(attachment->cleared());
538 // Check changing attachment
539 texture_manager_->SetLevelInfo(texture2.get(),
540 GL_TEXTURE_2D,
541 kLevel3,
542 kFormat3,
543 kWidth3,
544 kHeight3,
545 kDepth,
546 kBorder,
547 kFormat3,
548 kType,
549 false);
550 attachment = framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0);
551 ASSERT_TRUE(attachment != NULL);
552 EXPECT_EQ(kWidth3, attachment->width());
553 EXPECT_EQ(kHeight3, attachment->height());
554 EXPECT_EQ(kSamples3, attachment->samples());
555 EXPECT_EQ(kFormat3, attachment->internal_format());
556 EXPECT_FALSE(attachment->cleared());
557 EXPECT_EQ(static_cast<GLenum>(kFormat3),
558 framebuffer_->GetColorAttachmentFormat());
559 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
560 framebuffer_->IsPossiblyComplete());
561 EXPECT_FALSE(framebuffer_->IsCleared());
563 // Set to size 0
564 texture_manager_->SetLevelInfo(texture2.get(),
565 GL_TEXTURE_2D,
566 kLevel3,
567 kFormat3,
570 kDepth,
571 kBorder,
572 kFormat3,
573 kType,
574 false);
575 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),
576 framebuffer_->IsPossiblyComplete());
578 // Check removing it.
579 framebuffer_->AttachTexture(GL_COLOR_ATTACHMENT0, NULL, 0, 0, 0);
580 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL);
581 EXPECT_EQ(static_cast<GLenum>(0), framebuffer_->GetColorAttachmentFormat());
583 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT),
584 framebuffer_->IsPossiblyComplete());
585 EXPECT_TRUE(framebuffer_->IsCleared());
588 TEST_F(FramebufferInfoTest, DrawBuffers) {
589 const GLuint kTextureClientId[] = { 33, 34 };
590 const GLuint kTextureServiceId[] = { 333, 334 };
592 for (GLenum i = GL_COLOR_ATTACHMENT0;
593 i < GL_COLOR_ATTACHMENT0 + kMaxColorAttachments; ++i) {
594 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(i));
596 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments());
598 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT0),
599 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER0_ARB));
600 for (GLenum i = GL_DRAW_BUFFER1_ARB;
601 i < GL_DRAW_BUFFER0_ARB + kMaxDrawBuffers; ++i) {
602 EXPECT_EQ(static_cast<GLenum>(GL_NONE),
603 framebuffer_->GetDrawBuffer(i));
606 for (size_t ii = 0; ii < arraysize(kTextureClientId); ++ii) {
607 texture_manager_->CreateTexture(
608 kTextureClientId[ii], kTextureServiceId[ii]);
609 scoped_refptr<TextureRef> texture(
610 texture_manager_->GetTexture(kTextureClientId[ii]));
611 ASSERT_TRUE(texture.get() != NULL);
613 framebuffer_->AttachTexture(
614 GL_COLOR_ATTACHMENT0 + ii, texture.get(), GL_TEXTURE_2D, 0, 0);
615 EXPECT_FALSE(
616 framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0 + ii));
618 const Framebuffer::Attachment* attachment =
619 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0 + ii);
620 ASSERT_TRUE(attachment != NULL);
621 EXPECT_TRUE(attachment->cleared());
623 EXPECT_TRUE(framebuffer_->IsCleared());
624 EXPECT_FALSE(framebuffer_->HasUnclearedColorAttachments());
626 // Set a texture as uncleared.
627 scoped_refptr<TextureRef> texture1(
628 texture_manager_->GetTexture(kTextureClientId[1]));
629 texture_manager_->SetTarget(texture1.get(), GL_TEXTURE_2D);
630 texture_manager_->SetLevelInfo(
631 texture1.get(), GL_TEXTURE_2D, 0, GL_RGBA, 4, 4,
632 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, false);
634 const Framebuffer::Attachment* attachment1 =
635 framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT1);
636 ASSERT_TRUE(attachment1 != NULL);
637 EXPECT_FALSE(attachment1->cleared());
638 EXPECT_FALSE(framebuffer_->IsCleared());
639 EXPECT_TRUE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT1));
640 EXPECT_TRUE(framebuffer_->HasUnclearedColorAttachments());
642 GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
643 framebuffer_->SetDrawBuffers(2, buffers);
644 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT0),
645 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER0_ARB));
646 EXPECT_EQ(static_cast<GLenum>(GL_COLOR_ATTACHMENT1),
647 framebuffer_->GetDrawBuffer(GL_DRAW_BUFFER1_ARB));
648 for (GLenum i = GL_DRAW_BUFFER2_ARB;
649 i < GL_DRAW_BUFFER0_ARB + kMaxDrawBuffers; ++i) {
650 EXPECT_EQ(static_cast<GLenum>(GL_NONE),
651 framebuffer_->GetDrawBuffer(i));
654 // Nothing happens.
655 framebuffer_->PrepareDrawBuffersForClear();
656 framebuffer_->RestoreDrawBuffersAfterClear();
658 // Now we disable a draw buffer 1.
659 buffers[1] = GL_NONE;
660 framebuffer_->SetDrawBuffers(2, buffers);
661 // We will enable the disabled draw buffer for clear(), and disable it
662 // after the clear.
663 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
664 .Times(1)
665 .RetiresOnSaturation();
666 framebuffer_->PrepareDrawBuffersForClear();
667 EXPECT_CALL(*gl_, DrawBuffersARB(kMaxDrawBuffers, _))
668 .Times(1)
669 .RetiresOnSaturation();
670 framebuffer_->RestoreDrawBuffersAfterClear();
672 // Now remove draw buffer 1's attachment.
673 framebuffer_->AttachTexture(GL_COLOR_ATTACHMENT1, NULL, 0, 0, 0);
674 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT1) == NULL);
676 // Nothing happens.
677 framebuffer_->PrepareDrawBuffersForClear();
678 framebuffer_->RestoreDrawBuffersAfterClear();
681 class FramebufferInfoFloatTest : public FramebufferInfoTest {
682 public:
683 FramebufferInfoFloatTest()
684 : FramebufferInfoTest() {
686 ~FramebufferInfoFloatTest() override {}
688 protected:
689 void SetUp() override {
690 InitializeContext("OpenGL ES 3.0",
691 "GL_OES_texture_float GL_EXT_color_buffer_float");
695 TEST_F(FramebufferInfoFloatTest, AttachFloatTexture) {
696 const GLuint kTextureClientId = 33;
697 const GLuint kTextureServiceId = 333;
698 const GLint kDepth = 1;
699 const GLint kBorder = 0;
700 const GLenum kType = GL_FLOAT;
701 const GLsizei kWidth = 16;
702 const GLsizei kHeight = 32;
703 const GLint kLevel = 0;
704 const GLenum kFormat = GL_RGBA;
705 const GLenum kInternalFormat = GL_RGBA32F;
706 const GLenum kTarget = GL_TEXTURE_2D;
707 const GLsizei kSamples = 0;
708 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0));
709 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT));
710 EXPECT_FALSE(framebuffer_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT));
712 texture_manager_->CreateTexture(kTextureClientId, kTextureServiceId);
713 scoped_refptr<TextureRef> texture(
714 texture_manager_->GetTexture(kTextureClientId));
715 ASSERT_TRUE(texture.get() != NULL);
717 framebuffer_->AttachTexture(
718 GL_COLOR_ATTACHMENT0, texture.get(), kTarget, kLevel, kSamples);
719 EXPECT_EQ(static_cast<GLenum>(0), framebuffer_->GetColorAttachmentFormat());
721 texture_manager_->SetTarget(texture.get(), GL_TEXTURE_2D);
722 texture_manager_->SetLevelInfo(texture.get(),
723 GL_TEXTURE_2D,
724 kLevel,
725 kInternalFormat,
726 kWidth,
727 kHeight,
728 kDepth,
729 kBorder,
730 kFormat,
731 kType,
732 false);
733 // Texture with a sized float internalformat is allowed as an attachment
734 // since float color attachment extension is present.
735 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
736 framebuffer_->IsPossiblyComplete());
739 TEST_F(FramebufferInfoTest, UnbindRenderbuffer) {
740 const GLuint kRenderbufferClient1Id = 33;
741 const GLuint kRenderbufferService1Id = 333;
742 const GLuint kRenderbufferClient2Id = 34;
743 const GLuint kRenderbufferService2Id = 334;
745 renderbuffer_manager_->CreateRenderbuffer(
746 kRenderbufferClient1Id, kRenderbufferService1Id);
747 Renderbuffer* renderbuffer1 =
748 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient1Id);
749 ASSERT_TRUE(renderbuffer1 != NULL);
750 renderbuffer_manager_->CreateRenderbuffer(
751 kRenderbufferClient2Id, kRenderbufferService2Id);
752 Renderbuffer* renderbuffer2 =
753 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient2Id);
754 ASSERT_TRUE(renderbuffer2 != NULL);
756 // Attach to 2 attachment points.
757 framebuffer_->AttachRenderbuffer(GL_COLOR_ATTACHMENT0, renderbuffer1);
758 framebuffer_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, renderbuffer1);
759 // Check they were attached.
760 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) != NULL);
761 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) != NULL);
762 // Unbind unattached renderbuffer.
763 framebuffer_->UnbindRenderbuffer(GL_RENDERBUFFER, renderbuffer2);
764 // Should be no-op.
765 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) != NULL);
766 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) != NULL);
767 // Unbind renderbuffer.
768 framebuffer_->UnbindRenderbuffer(GL_RENDERBUFFER, renderbuffer1);
769 // Check they were detached
770 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL);
771 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) == NULL);
774 TEST_F(FramebufferInfoTest, UnbindTexture) {
775 const GLuint kTextureClient1Id = 33;
776 const GLuint kTextureService1Id = 333;
777 const GLuint kTextureClient2Id = 34;
778 const GLuint kTextureService2Id = 334;
779 const GLenum kTarget1 = GL_TEXTURE_2D;
780 const GLint kLevel1 = 0;
781 const GLint kSamples1 = 0;
783 texture_manager_->CreateTexture(kTextureClient1Id, kTextureService1Id);
784 scoped_refptr<TextureRef> texture1(
785 texture_manager_->GetTexture(kTextureClient1Id));
786 ASSERT_TRUE(texture1.get() != NULL);
787 texture_manager_->CreateTexture(kTextureClient2Id, kTextureService2Id);
788 scoped_refptr<TextureRef> texture2(
789 texture_manager_->GetTexture(kTextureClient2Id));
790 ASSERT_TRUE(texture2.get() != NULL);
792 // Attach to 2 attachment points.
793 framebuffer_->AttachTexture(
794 GL_COLOR_ATTACHMENT0, texture1.get(), kTarget1, kLevel1, kSamples1);
795 framebuffer_->AttachTexture(
796 GL_DEPTH_ATTACHMENT, texture1.get(), kTarget1, kLevel1, kSamples1);
797 // Check they were attached.
798 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) != NULL);
799 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) != NULL);
800 // Unbind unattached texture.
801 framebuffer_->UnbindTexture(kTarget1, texture2.get());
802 // Should be no-op.
803 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) != NULL);
804 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) != NULL);
805 // Unbind texture.
806 framebuffer_->UnbindTexture(kTarget1, texture1.get());
807 // Check they were detached
808 EXPECT_TRUE(framebuffer_->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL);
809 EXPECT_TRUE(framebuffer_->GetAttachment(GL_DEPTH_ATTACHMENT) == NULL);
812 TEST_F(FramebufferInfoTest, IsCompleteMarkAsComplete) {
813 const GLuint kRenderbufferClient1Id = 33;
814 const GLuint kRenderbufferService1Id = 333;
815 const GLuint kTextureClient2Id = 34;
816 const GLuint kTextureService2Id = 334;
817 const GLenum kTarget1 = GL_TEXTURE_2D;
818 const GLint kLevel1 = 0;
819 const GLint kSamples1 = 0;
821 renderbuffer_manager_->CreateRenderbuffer(
822 kRenderbufferClient1Id, kRenderbufferService1Id);
823 Renderbuffer* renderbuffer1 =
824 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient1Id);
825 ASSERT_TRUE(renderbuffer1 != NULL);
826 texture_manager_->CreateTexture(kTextureClient2Id, kTextureService2Id);
827 scoped_refptr<TextureRef> texture2(
828 texture_manager_->GetTexture(kTextureClient2Id));
829 ASSERT_TRUE(texture2.get() != NULL);
831 // Check MarkAsComlete marks as complete.
832 manager_.MarkAsComplete(framebuffer_);
833 EXPECT_TRUE(manager_.IsComplete(framebuffer_));
835 // Check at attaching marks as not complete.
836 framebuffer_->AttachTexture(
837 GL_COLOR_ATTACHMENT0, texture2.get(), kTarget1, kLevel1, kSamples1);
838 EXPECT_FALSE(manager_.IsComplete(framebuffer_));
839 manager_.MarkAsComplete(framebuffer_);
840 EXPECT_TRUE(manager_.IsComplete(framebuffer_));
841 framebuffer_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, renderbuffer1);
842 EXPECT_FALSE(manager_.IsComplete(framebuffer_));
844 // Check MarkAttachmentsAsCleared marks as complete.
845 manager_.MarkAttachmentsAsCleared(
846 framebuffer_, renderbuffer_manager_.get(), texture_manager_.get());
847 EXPECT_TRUE(manager_.IsComplete(framebuffer_));
849 // Check Unbind marks as not complete.
850 framebuffer_->UnbindRenderbuffer(GL_RENDERBUFFER, renderbuffer1);
851 EXPECT_FALSE(manager_.IsComplete(framebuffer_));
852 manager_.MarkAsComplete(framebuffer_);
853 EXPECT_TRUE(manager_.IsComplete(framebuffer_));
854 framebuffer_->UnbindTexture(kTarget1, texture2.get());
855 EXPECT_FALSE(manager_.IsComplete(framebuffer_));
858 TEST_F(FramebufferInfoTest, GetStatus) {
859 const GLuint kRenderbufferClient1Id = 33;
860 const GLuint kRenderbufferService1Id = 333;
861 const GLuint kTextureClient2Id = 34;
862 const GLuint kTextureService2Id = 334;
863 const GLenum kTarget1 = GL_TEXTURE_2D;
864 const GLint kLevel1 = 0;
865 const GLint kSamples1 = 0;
867 renderbuffer_manager_->CreateRenderbuffer(
868 kRenderbufferClient1Id, kRenderbufferService1Id);
869 Renderbuffer* renderbuffer1 =
870 renderbuffer_manager_->GetRenderbuffer(kRenderbufferClient1Id);
871 ASSERT_TRUE(renderbuffer1 != NULL);
872 texture_manager_->CreateTexture(kTextureClient2Id, kTextureService2Id);
873 scoped_refptr<TextureRef> texture2(
874 texture_manager_->GetTexture(kTextureClient2Id));
875 ASSERT_TRUE(texture2.get() != NULL);
876 texture_manager_->SetTarget(texture2.get(), GL_TEXTURE_2D);
878 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
879 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
880 .RetiresOnSaturation();
881 framebuffer_->GetStatus(texture_manager_.get(), GL_FRAMEBUFFER);
883 // Check a second call for the same type does not call anything
884 if (!framebuffer_->AllowFramebufferComboCompleteMapForTesting()) {
885 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
886 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
887 .RetiresOnSaturation();
889 framebuffer_->GetStatus(texture_manager_.get(), GL_FRAMEBUFFER);
891 // Check changing the attachments calls CheckFramebufferStatus.
892 framebuffer_->AttachTexture(
893 GL_COLOR_ATTACHMENT0, texture2.get(), kTarget1, kLevel1, kSamples1);
894 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
895 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)).RetiresOnSaturation();
896 framebuffer_->GetStatus(texture_manager_.get(), GL_FRAMEBUFFER);
898 // Check a second call for the same type does not call anything.
899 if (!framebuffer_->AllowFramebufferComboCompleteMapForTesting()) {
900 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
901 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
902 .RetiresOnSaturation();
904 framebuffer_->GetStatus(texture_manager_.get(), GL_FRAMEBUFFER);
906 // Check a second call with a different target calls CheckFramebufferStatus.
907 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER))
908 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
909 .RetiresOnSaturation();
910 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
912 // Check a second call for the same type does not call anything.
913 if (!framebuffer_->AllowFramebufferComboCompleteMapForTesting()) {
914 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER))
915 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
916 .RetiresOnSaturation();
918 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
920 // Check adding another attachment calls CheckFramebufferStatus.
921 framebuffer_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, renderbuffer1);
922 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER))
923 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
924 .RetiresOnSaturation();
925 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
927 // Check a second call for the same type does not call anything.
928 if (!framebuffer_->AllowFramebufferComboCompleteMapForTesting()) {
929 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER))
930 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
931 .RetiresOnSaturation();
933 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
935 // Check changing the format calls CheckFramebuffferStatus.
936 TestHelper::SetTexParameteriWithExpectations(gl_.get(),
937 error_state_.get(),
938 texture_manager_.get(),
939 texture2.get(),
940 GL_TEXTURE_WRAP_S,
941 GL_CLAMP_TO_EDGE,
942 GL_NO_ERROR);
944 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER))
945 .WillOnce(Return(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT))
946 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
947 .RetiresOnSaturation();
948 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
950 // Check since it did not return FRAMEBUFFER_COMPLETE that it calls
951 // CheckFramebufferStatus
952 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
954 // Check putting it back does not call CheckFramebufferStatus.
955 if (!framebuffer_->AllowFramebufferComboCompleteMapForTesting()) {
956 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER))
957 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
958 .RetiresOnSaturation();
960 TestHelper::SetTexParameteriWithExpectations(gl_.get(),
961 error_state_.get(),
962 texture_manager_.get(),
963 texture2.get(),
964 GL_TEXTURE_WRAP_S,
965 GL_REPEAT,
966 GL_NO_ERROR);
967 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
969 // Check Unbinding does not call CheckFramebufferStatus
970 framebuffer_->UnbindRenderbuffer(GL_RENDERBUFFER, renderbuffer1);
971 if (!framebuffer_->AllowFramebufferComboCompleteMapForTesting()) {
972 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER))
973 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
974 .RetiresOnSaturation();
976 framebuffer_->GetStatus(texture_manager_.get(), GL_READ_FRAMEBUFFER);
979 } // namespace gles2
980 } // namespace gpu