| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 namespace blink { | 50 namespace blink { |
| 51 | 51 |
| 52 class DrawingBufferTest : public Test { | 52 class DrawingBufferTest : public Test { |
| 53 protected: | 53 protected: |
| 54 void SetUp() override { | 54 void SetUp() override { |
| 55 IntSize initialSize(InitialWidth, InitialHeight); | 55 IntSize initialSize(InitialWidth, InitialHeight); |
| 56 std::unique_ptr<GLES2InterfaceForTests> gl = | 56 std::unique_ptr<GLES2InterfaceForTests> gl = |
| 57 wrapUnique(new GLES2InterfaceForTests); | 57 wrapUnique(new GLES2InterfaceForTests); |
| 58 m_gl = gl.get(); | 58 m_gl = gl.get(); |
| 59 SetAndSaveRestoreState(false); |
| 59 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = | 60 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = |
| 60 wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 61 wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); |
| 61 m_drawingBuffer = DrawingBufferForTests::create( | 62 m_drawingBuffer = DrawingBufferForTests::create( |
| 62 std::move(provider), initialSize, DrawingBuffer::Preserve); | 63 std::move(provider), m_gl, initialSize, DrawingBuffer::Preserve); |
| 63 CHECK(m_drawingBuffer); | 64 CHECK(m_drawingBuffer); |
| 64 } | 65 } |
| 65 | 66 |
| 67 // Initialize GL state with unusual values, to verify that they are restored. |
| 68 // The |invert| parameter will reverse all boolean parameters, so that all |
| 69 // values are tested. |
| 70 void SetAndSaveRestoreState(bool invert) { |
| 71 GLboolean scissorEnabled = !invert; |
| 72 GLfloat clearColor[4] = {0.1, 0.2, 0.3, 0.4}; |
| 73 GLfloat clearDepth = 0.8; |
| 74 GLint clearStencil = 37; |
| 75 GLboolean colorMask[4] = {invert, !invert, !invert, invert}; |
| 76 GLboolean depthMask = invert; |
| 77 GLboolean stencilMask = invert; |
| 78 GLint packAlignment = 7; |
| 79 GLuint activeTexture2DBinding = 0xbeef1; |
| 80 GLuint renderbufferBinding = 0xbeef2; |
| 81 GLuint drawFramebufferBinding = 0xbeef3; |
| 82 GLuint readFramebufferBinding = 0xbeef4; |
| 83 GLuint pixelUnpackBufferBinding = 0xbeef5; |
| 84 |
| 85 if (scissorEnabled) |
| 86 m_gl->Enable(GL_SCISSOR_TEST); |
| 87 else |
| 88 m_gl->Disable(GL_SCISSOR_TEST); |
| 89 |
| 90 m_gl->ClearColor(clearColor[0], clearColor[1], clearColor[2], |
| 91 clearColor[3]); |
| 92 m_gl->ClearDepthf(clearDepth); |
| 93 m_gl->ClearStencil(clearStencil); |
| 94 m_gl->ColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]); |
| 95 m_gl->DepthMask(depthMask); |
| 96 m_gl->StencilMask(stencilMask); |
| 97 m_gl->PixelStorei(GL_PACK_ALIGNMENT, packAlignment); |
| 98 m_gl->BindTexture(GL_TEXTURE_2D, activeTexture2DBinding); |
| 99 m_gl->BindRenderbuffer(GL_RENDERBUFFER, renderbufferBinding); |
| 100 m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFramebufferBinding); |
| 101 m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER, readFramebufferBinding); |
| 102 m_gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, pixelUnpackBufferBinding); |
| 103 |
| 104 m_gl->SaveState(); |
| 105 } |
| 106 |
| 107 void VerifyStateWasRestored() { m_gl->VeriyStateHasNotChangedSinceSave(); } |
| 108 |
| 66 GLES2InterfaceForTests* m_gl; | 109 GLES2InterfaceForTests* m_gl; |
| 67 RefPtr<DrawingBufferForTests> m_drawingBuffer; | 110 RefPtr<DrawingBufferForTests> m_drawingBuffer; |
| 68 }; | 111 }; |
| 69 | 112 |
| 70 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) { | 113 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) { |
| 114 VerifyStateWasRestored(); |
| 71 cc::TextureMailbox textureMailbox; | 115 cc::TextureMailbox textureMailbox; |
| 72 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 116 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 73 | 117 |
| 74 IntSize initialSize(InitialWidth, InitialHeight); | 118 IntSize initialSize(InitialWidth, InitialHeight); |
| 75 IntSize alternateSize(InitialWidth, AlternateHeight); | 119 IntSize alternateSize(InitialWidth, AlternateHeight); |
| 76 | 120 |
| 77 // Produce one mailbox at size 100x100. | 121 // Produce one mailbox at size 100x100. |
| 78 m_drawingBuffer->markContentsChanged(); | 122 m_drawingBuffer->markContentsChanged(); |
| 79 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 123 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, |
| 80 &releaseCallback)); | 124 &releaseCallback)); |
| 125 VerifyStateWasRestored(); |
| 81 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 126 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); |
| 82 | 127 |
| 83 // Resize to 100x50. | 128 // Resize to 100x50. |
| 84 m_drawingBuffer->reset(alternateSize); | 129 m_drawingBuffer->resize(alternateSize); |
| 130 VerifyStateWasRestored(); |
| 85 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 131 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
| 132 VerifyStateWasRestored(); |
| 86 | 133 |
| 87 // Produce a mailbox at this size. | 134 // Produce a mailbox at this size. |
| 88 m_drawingBuffer->markContentsChanged(); | 135 m_drawingBuffer->markContentsChanged(); |
| 89 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 136 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, |
| 90 &releaseCallback)); | 137 &releaseCallback)); |
| 91 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); | 138 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); |
| 139 VerifyStateWasRestored(); |
| 92 | 140 |
| 93 // Reset to initial size. | 141 // Reset to initial size. |
| 94 m_drawingBuffer->reset(initialSize); | 142 m_drawingBuffer->resize(initialSize); |
| 143 VerifyStateWasRestored(); |
| 144 SetAndSaveRestoreState(true); |
| 95 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 145 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
| 146 VerifyStateWasRestored(); |
| 96 | 147 |
| 97 // Prepare another mailbox and verify that it's the correct size. | 148 // Prepare another mailbox and verify that it's the correct size. |
| 98 m_drawingBuffer->markContentsChanged(); | 149 m_drawingBuffer->markContentsChanged(); |
| 99 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 150 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, |
| 100 &releaseCallback)); | 151 &releaseCallback)); |
| 101 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 152 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); |
| 153 VerifyStateWasRestored(); |
| 102 | 154 |
| 103 // Prepare one final mailbox and verify that it's the correct size. | 155 // Prepare one final mailbox and verify that it's the correct size. |
| 104 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 156 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
| 105 m_drawingBuffer->markContentsChanged(); | 157 m_drawingBuffer->markContentsChanged(); |
| 106 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 158 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, |
| 107 &releaseCallback)); | 159 &releaseCallback)); |
| 160 VerifyStateWasRestored(); |
| 108 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 161 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); |
| 109 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 162 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
| 110 m_drawingBuffer->beginDestruction(); | 163 m_drawingBuffer->beginDestruction(); |
| 111 } | 164 } |
| 112 | 165 |
| 113 TEST_F(DrawingBufferTest, verifyDestructionCompleteAfterAllMailboxesReleased) { | 166 TEST_F(DrawingBufferTest, verifyDestructionCompleteAfterAllMailboxesReleased) { |
| 114 bool live = true; | 167 bool live = true; |
| 115 m_drawingBuffer->m_live = &live; | 168 m_drawingBuffer->m_live = &live; |
| 116 | 169 |
| 117 cc::TextureMailbox textureMailbox1; | 170 cc::TextureMailbox textureMailbox1; |
| 118 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 171 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; |
| 119 cc::TextureMailbox textureMailbox2; | 172 cc::TextureMailbox textureMailbox2; |
| 120 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 173 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; |
| 121 cc::TextureMailbox textureMailbox3; | 174 cc::TextureMailbox textureMailbox3; |
| 122 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 175 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; |
| 123 | 176 |
| 124 IntSize initialSize(InitialWidth, InitialHeight); | 177 IntSize initialSize(InitialWidth, InitialHeight); |
| 125 | 178 |
| 126 // Produce mailboxes. | 179 // Produce mailboxes. |
| 127 m_drawingBuffer->markContentsChanged(); | 180 m_drawingBuffer->markContentsChanged(); |
| 181 m_drawingBuffer->clearFramebuffers(GL_STENCIL_BUFFER_BIT); |
| 182 VerifyStateWasRestored(); |
| 128 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, | 183 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, |
| 129 &releaseCallback1)); | 184 &releaseCallback1)); |
| 130 m_drawingBuffer->markContentsChanged(); | 185 m_drawingBuffer->markContentsChanged(); |
| 186 m_drawingBuffer->clearFramebuffers(GL_DEPTH_BUFFER_BIT); |
| 187 VerifyStateWasRestored(); |
| 131 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, | 188 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, |
| 132 &releaseCallback2)); | 189 &releaseCallback2)); |
| 133 m_drawingBuffer->markContentsChanged(); | 190 m_drawingBuffer->markContentsChanged(); |
| 191 m_drawingBuffer->clearFramebuffers(GL_COLOR_BUFFER_BIT); |
| 192 VerifyStateWasRestored(); |
| 134 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, | 193 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, |
| 135 &releaseCallback3)); | 194 &releaseCallback3)); |
| 136 | 195 |
| 137 m_drawingBuffer->markContentsChanged(); | 196 m_drawingBuffer->markContentsChanged(); |
| 138 releaseCallback1->Run(gpu::SyncToken(), false /* lostResource */); | 197 releaseCallback1->Run(gpu::SyncToken(), false /* lostResource */); |
| 139 | 198 |
| 140 m_drawingBuffer->beginDestruction(); | 199 m_drawingBuffer->beginDestruction(); |
| 141 ASSERT_EQ(live, true); | 200 ASSERT_EQ(live, true); |
| 142 | 201 |
| 143 DrawingBufferForTests* rawPointer = m_drawingBuffer.get(); | 202 DrawingBufferForTests* rawPointer = m_drawingBuffer.get(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 160 cc::TextureMailbox textureMailbox1; | 219 cc::TextureMailbox textureMailbox1; |
| 161 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 220 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; |
| 162 cc::TextureMailbox textureMailbox2; | 221 cc::TextureMailbox textureMailbox2; |
| 163 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 222 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; |
| 164 cc::TextureMailbox textureMailbox3; | 223 cc::TextureMailbox textureMailbox3; |
| 165 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 224 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; |
| 166 | 225 |
| 167 m_drawingBuffer->markContentsChanged(); | 226 m_drawingBuffer->markContentsChanged(); |
| 168 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, | 227 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, |
| 169 &releaseCallback1)); | 228 &releaseCallback1)); |
| 229 VerifyStateWasRestored(); |
| 170 m_drawingBuffer->markContentsChanged(); | 230 m_drawingBuffer->markContentsChanged(); |
| 171 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, | 231 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, |
| 172 &releaseCallback2)); | 232 &releaseCallback2)); |
| 233 VerifyStateWasRestored(); |
| 173 m_drawingBuffer->markContentsChanged(); | 234 m_drawingBuffer->markContentsChanged(); |
| 174 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, | 235 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, |
| 175 &releaseCallback3)); | 236 &releaseCallback3)); |
| 237 VerifyStateWasRestored(); |
| 176 | 238 |
| 177 m_drawingBuffer->markContentsChanged(); | 239 m_drawingBuffer->markContentsChanged(); |
| 178 releaseCallback1->Run(gpu::SyncToken(), true /* lostResource */); | 240 releaseCallback1->Run(gpu::SyncToken(), true /* lostResource */); |
| 179 EXPECT_EQ(live, true); | 241 EXPECT_EQ(live, true); |
| 180 | 242 |
| 181 m_drawingBuffer->beginDestruction(); | 243 m_drawingBuffer->beginDestruction(); |
| 182 EXPECT_EQ(live, true); | 244 EXPECT_EQ(live, true); |
| 183 | 245 |
| 184 m_drawingBuffer->markContentsChanged(); | 246 m_drawingBuffer->markContentsChanged(); |
| 185 releaseCallback2->Run(gpu::SyncToken(), false /* lostResource */); | 247 releaseCallback2->Run(gpu::SyncToken(), false /* lostResource */); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); | 342 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); |
| 281 } | 343 } |
| 282 | 344 |
| 283 class DrawingBufferImageChromiumTest : public DrawingBufferTest { | 345 class DrawingBufferImageChromiumTest : public DrawingBufferTest { |
| 284 protected: | 346 protected: |
| 285 void SetUp() override { | 347 void SetUp() override { |
| 286 IntSize initialSize(InitialWidth, InitialHeight); | 348 IntSize initialSize(InitialWidth, InitialHeight); |
| 287 std::unique_ptr<GLES2InterfaceForTests> gl = | 349 std::unique_ptr<GLES2InterfaceForTests> gl = |
| 288 wrapUnique(new GLES2InterfaceForTests); | 350 wrapUnique(new GLES2InterfaceForTests); |
| 289 m_gl = gl.get(); | 351 m_gl = gl.get(); |
| 352 SetAndSaveRestoreState(true); |
| 290 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = | 353 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = |
| 291 wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 354 wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); |
| 292 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); | 355 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); |
| 293 m_imageId0 = m_gl->nextImageIdToBeCreated(); | 356 m_imageId0 = m_gl->nextImageIdToBeCreated(); |
| 294 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId0)).Times(1); | 357 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId0)).Times(1); |
| 295 m_drawingBuffer = DrawingBufferForTests::create( | 358 m_drawingBuffer = DrawingBufferForTests::create( |
| 296 std::move(provider), initialSize, DrawingBuffer::Preserve); | 359 std::move(provider), m_gl, initialSize, DrawingBuffer::Preserve); |
| 297 CHECK(m_drawingBuffer); | 360 CHECK(m_drawingBuffer); |
| 298 testing::Mock::VerifyAndClearExpectations(m_gl); | 361 testing::Mock::VerifyAndClearExpectations(m_gl); |
| 299 } | 362 } |
| 300 | 363 |
| 301 void TearDown() override { | 364 void TearDown() override { |
| 302 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false); | 365 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false); |
| 303 } | 366 } |
| 304 | 367 |
| 305 GLuint m_imageId0; | 368 GLuint m_imageId0; |
| 306 }; | 369 }; |
| 307 | 370 |
| 308 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) { | 371 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) { |
| 309 cc::TextureMailbox textureMailbox; | 372 cc::TextureMailbox textureMailbox; |
| 310 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 373 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 311 | 374 |
| 312 IntSize initialSize(InitialWidth, InitialHeight); | 375 IntSize initialSize(InitialWidth, InitialHeight); |
| 313 IntSize alternateSize(InitialWidth, AlternateHeight); | 376 IntSize alternateSize(InitialWidth, AlternateHeight); |
| 314 | 377 |
| 315 GLuint m_imageId1 = m_gl->nextImageIdToBeCreated(); | 378 GLuint m_imageId1 = m_gl->nextImageIdToBeCreated(); |
| 316 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId1)).Times(1); | 379 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId1)).Times(1); |
| 317 // Produce one mailbox at size 100x100. | 380 // Produce one mailbox at size 100x100. |
| 318 m_drawingBuffer->markContentsChanged(); | 381 m_drawingBuffer->markContentsChanged(); |
| 319 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 382 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, |
| 320 &releaseCallback)); | 383 &releaseCallback)); |
| 321 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 384 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); |
| 322 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); | 385 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); |
| 323 testing::Mock::VerifyAndClearExpectations(m_gl); | 386 testing::Mock::VerifyAndClearExpectations(m_gl); |
| 387 VerifyStateWasRestored(); |
| 324 | 388 |
| 325 GLuint m_imageId2 = m_gl->nextImageIdToBeCreated(); | 389 GLuint m_imageId2 = m_gl->nextImageIdToBeCreated(); |
| 326 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId2)).Times(1); | 390 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId2)).Times(1); |
| 327 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId0)).Times(1); | 391 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId0)).Times(1); |
| 328 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId0)).Times(1); | 392 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId0)).Times(1); |
| 329 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId1)).Times(1); | 393 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId1)).Times(1); |
| 330 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId1)).Times(1); | 394 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId1)).Times(1); |
| 331 // Resize to 100x50. | 395 // Resize to 100x50. |
| 332 m_drawingBuffer->reset(alternateSize); | 396 m_drawingBuffer->resize(alternateSize); |
| 397 VerifyStateWasRestored(); |
| 333 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 398 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
| 399 VerifyStateWasRestored(); |
| 334 testing::Mock::VerifyAndClearExpectations(m_gl); | 400 testing::Mock::VerifyAndClearExpectations(m_gl); |
| 335 | 401 |
| 336 GLuint m_imageId3 = m_gl->nextImageIdToBeCreated(); | 402 GLuint m_imageId3 = m_gl->nextImageIdToBeCreated(); |
| 337 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId3)).Times(1); | 403 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId3)).Times(1); |
| 338 // Produce a mailbox at this size. | 404 // Produce a mailbox at this size. |
| 339 m_drawingBuffer->markContentsChanged(); | 405 m_drawingBuffer->markContentsChanged(); |
| 340 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 406 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, |
| 341 &releaseCallback)); | 407 &releaseCallback)); |
| 342 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); | 408 EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); |
| 343 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); | 409 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); |
| 344 testing::Mock::VerifyAndClearExpectations(m_gl); | 410 testing::Mock::VerifyAndClearExpectations(m_gl); |
| 345 | 411 |
| 346 GLuint m_imageId4 = m_gl->nextImageIdToBeCreated(); | 412 GLuint m_imageId4 = m_gl->nextImageIdToBeCreated(); |
| 347 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId4)).Times(1); | 413 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId4)).Times(1); |
| 348 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId2)).Times(1); | 414 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId2)).Times(1); |
| 349 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId2)).Times(1); | 415 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId2)).Times(1); |
| 350 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId3)).Times(1); | 416 EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId3)).Times(1); |
| 351 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId3)).Times(1); | 417 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId3)).Times(1); |
| 352 // Reset to initial size. | 418 // Reset to initial size. |
| 353 m_drawingBuffer->reset(initialSize); | 419 m_drawingBuffer->resize(initialSize); |
| 420 VerifyStateWasRestored(); |
| 354 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 421 releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); |
| 422 VerifyStateWasRestored(); |
| 355 testing::Mock::VerifyAndClearExpectations(m_gl); | 423 testing::Mock::VerifyAndClearExpectations(m_gl); |
| 356 | 424 |
| 357 GLuint m_imageId5 = m_gl->nextImageIdToBeCreated(); | 425 GLuint m_imageId5 = m_gl->nextImageIdToBeCreated(); |
| 358 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId5)).Times(1); | 426 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId5)).Times(1); |
| 359 // Prepare another mailbox and verify that it's the correct size. | 427 // Prepare another mailbox and verify that it's the correct size. |
| 360 m_drawingBuffer->markContentsChanged(); | 428 m_drawingBuffer->markContentsChanged(); |
| 361 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 429 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, |
| 362 &releaseCallback)); | 430 &releaseCallback)); |
| 363 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 431 EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); |
| 364 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); | 432 EXPECT_TRUE(textureMailbox.is_overlay_candidate()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 391 | 459 |
| 392 // Request a mailbox. An image should already be created. Everything works | 460 // Request a mailbox. An image should already be created. Everything works |
| 393 // as expected. | 461 // as expected. |
| 394 EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); | 462 EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); |
| 395 IntSize initialSize(InitialWidth, InitialHeight); | 463 IntSize initialSize(InitialWidth, InitialHeight); |
| 396 m_drawingBuffer->markContentsChanged(); | 464 m_drawingBuffer->markContentsChanged(); |
| 397 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, | 465 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, |
| 398 &releaseCallback1)); | 466 &releaseCallback1)); |
| 399 EXPECT_TRUE(textureMailbox1.is_overlay_candidate()); | 467 EXPECT_TRUE(textureMailbox1.is_overlay_candidate()); |
| 400 testing::Mock::VerifyAndClearExpectations(m_gl); | 468 testing::Mock::VerifyAndClearExpectations(m_gl); |
| 469 VerifyStateWasRestored(); |
| 401 | 470 |
| 402 // Force image CHROMIUM creation failure. Request another mailbox. It should | 471 // Force image CHROMIUM creation failure. Request another mailbox. It should |
| 403 // still be provided, but this time with allowOverlay = false. | 472 // still be provided, but this time with allowOverlay = false. |
| 404 m_gl->setCreateImageChromiumFail(true); | 473 m_gl->setCreateImageChromiumFail(true); |
| 405 m_drawingBuffer->markContentsChanged(); | 474 m_drawingBuffer->markContentsChanged(); |
| 406 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, | 475 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, |
| 407 &releaseCallback2)); | 476 &releaseCallback2)); |
| 408 EXPECT_FALSE(textureMailbox2.is_overlay_candidate()); | 477 EXPECT_FALSE(textureMailbox2.is_overlay_candidate()); |
| 478 VerifyStateWasRestored(); |
| 409 | 479 |
| 410 // Check that if image CHROMIUM starts working again, mailboxes are | 480 // Check that if image CHROMIUM starts working again, mailboxes are |
| 411 // correctly created with allowOverlay = true. | 481 // correctly created with allowOverlay = true. |
| 412 EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); | 482 EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); |
| 413 m_gl->setCreateImageChromiumFail(false); | 483 m_gl->setCreateImageChromiumFail(false); |
| 414 m_drawingBuffer->markContentsChanged(); | 484 m_drawingBuffer->markContentsChanged(); |
| 415 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, | 485 EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, |
| 416 &releaseCallback3)); | 486 &releaseCallback3)); |
| 417 EXPECT_TRUE(textureMailbox3.is_overlay_candidate()); | 487 EXPECT_TRUE(textureMailbox3.is_overlay_candidate()); |
| 418 testing::Mock::VerifyAndClearExpectations(m_gl); | 488 testing::Mock::VerifyAndClearExpectations(m_gl); |
| 489 VerifyStateWasRestored(); |
| 419 | 490 |
| 420 releaseCallback1->Run(gpu::SyncToken(), false /* lostResource */); | 491 releaseCallback1->Run(gpu::SyncToken(), false /* lostResource */); |
| 421 releaseCallback2->Run(gpu::SyncToken(), false /* lostResource */); | 492 releaseCallback2->Run(gpu::SyncToken(), false /* lostResource */); |
| 422 releaseCallback3->Run(gpu::SyncToken(), false /* lostResource */); | 493 releaseCallback3->Run(gpu::SyncToken(), false /* lostResource */); |
| 423 | 494 |
| 424 EXPECT_CALL(*m_gl, DestroyImageMock(_)).Times(3); | 495 EXPECT_CALL(*m_gl, DestroyImageMock(_)).Times(3); |
| 425 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(_)).Times(3); | 496 EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(_)).Times(3); |
| 426 m_drawingBuffer->beginDestruction(); | 497 m_drawingBuffer->beginDestruction(); |
| 427 testing::Mock::VerifyAndClearExpectations(m_gl); | 498 testing::Mock::VerifyAndClearExpectations(m_gl); |
| 428 } | 499 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = | 596 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = |
| 526 wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 597 wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); |
| 527 DrawingBuffer::PreserveDrawingBuffer preserve = DrawingBuffer::Preserve; | 598 DrawingBuffer::PreserveDrawingBuffer preserve = DrawingBuffer::Preserve; |
| 528 | 599 |
| 529 bool premultipliedAlpha = false; | 600 bool premultipliedAlpha = false; |
| 530 bool wantAlphaChannel = true; | 601 bool wantAlphaChannel = true; |
| 531 bool wantDepthBuffer = cases[i].requestDepth; | 602 bool wantDepthBuffer = cases[i].requestDepth; |
| 532 bool wantStencilBuffer = cases[i].requestStencil; | 603 bool wantStencilBuffer = cases[i].requestStencil; |
| 533 bool wantAntialiasing = false; | 604 bool wantAntialiasing = false; |
| 534 RefPtr<DrawingBuffer> drawingBuffer = DrawingBuffer::create( | 605 RefPtr<DrawingBuffer> drawingBuffer = DrawingBuffer::create( |
| 535 std::move(provider), IntSize(10, 10), premultipliedAlpha, | 606 std::move(provider), nullptr, IntSize(10, 10), premultipliedAlpha, |
| 536 wantAlphaChannel, wantDepthBuffer, wantStencilBuffer, wantAntialiasing, | 607 wantAlphaChannel, wantDepthBuffer, wantStencilBuffer, wantAntialiasing, |
| 537 preserve, DrawingBuffer::WebGL1, DrawingBuffer::AllowChromiumImage); | 608 preserve, DrawingBuffer::WebGL1, DrawingBuffer::AllowChromiumImage); |
| 538 | 609 |
| 539 // When we request a depth or a stencil buffer, we will get both. | 610 // When we request a depth or a stencil buffer, we will get both. |
| 540 EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 611 EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, |
| 541 drawingBuffer->hasDepthBuffer()); | 612 drawingBuffer->hasDepthBuffer()); |
| 542 EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 613 EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, |
| 543 drawingBuffer->hasStencilBuffer()); | 614 drawingBuffer->hasStencilBuffer()); |
| 544 EXPECT_EQ(cases[i].expectedRenderBuffers, | 615 EXPECT_EQ(cases[i].expectedRenderBuffers, |
| 545 trackingGL->numAllocatedRenderBuffer()); | 616 trackingGL->numAllocatedRenderBuffer()); |
| 546 if (cases[i].requestDepth || cases[i].requestStencil) { | 617 if (cases[i].requestDepth || cases[i].requestStencil) { |
| 547 EXPECT_NE(0u, trackingGL->depthStencilAttachment()); | 618 EXPECT_NE(0u, trackingGL->depthStencilAttachment()); |
| 548 EXPECT_EQ(0u, trackingGL->depthAttachment()); | 619 EXPECT_EQ(0u, trackingGL->depthAttachment()); |
| 549 EXPECT_EQ(0u, trackingGL->stencilAttachment()); | 620 EXPECT_EQ(0u, trackingGL->stencilAttachment()); |
| 550 } else { | 621 } else { |
| 551 EXPECT_EQ(0u, trackingGL->depthStencilAttachment()); | 622 EXPECT_EQ(0u, trackingGL->depthStencilAttachment()); |
| 552 EXPECT_EQ(0u, trackingGL->depthAttachment()); | 623 EXPECT_EQ(0u, trackingGL->depthAttachment()); |
| 553 EXPECT_EQ(0u, trackingGL->stencilAttachment()); | 624 EXPECT_EQ(0u, trackingGL->stencilAttachment()); |
| 554 } | 625 } |
| 555 | 626 |
| 556 drawingBuffer->reset(IntSize(10, 20)); | 627 drawingBuffer->resize(IntSize(10, 20)); |
| 557 EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 628 EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, |
| 558 drawingBuffer->hasDepthBuffer()); | 629 drawingBuffer->hasDepthBuffer()); |
| 559 EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 630 EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, |
| 560 drawingBuffer->hasStencilBuffer()); | 631 drawingBuffer->hasStencilBuffer()); |
| 561 EXPECT_EQ(cases[i].expectedRenderBuffers, | 632 EXPECT_EQ(cases[i].expectedRenderBuffers, |
| 562 trackingGL->numAllocatedRenderBuffer()); | 633 trackingGL->numAllocatedRenderBuffer()); |
| 563 if (cases[i].requestDepth || cases[i].requestStencil) { | 634 if (cases[i].requestDepth || cases[i].requestStencil) { |
| 564 EXPECT_NE(0u, trackingGL->depthStencilAttachment()); | 635 EXPECT_NE(0u, trackingGL->depthStencilAttachment()); |
| 565 EXPECT_EQ(0u, trackingGL->depthAttachment()); | 636 EXPECT_EQ(0u, trackingGL->depthAttachment()); |
| 566 EXPECT_EQ(0u, trackingGL->stencilAttachment()); | 637 EXPECT_EQ(0u, trackingGL->stencilAttachment()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 589 m_drawingBuffer->setIsHidden(true); | 660 m_drawingBuffer->setIsHidden(true); |
| 590 releaseCallback->Run(waitSyncToken, false /* lostResource */); | 661 releaseCallback->Run(waitSyncToken, false /* lostResource */); |
| 591 // m_drawingBuffer deletes mailbox immediately when hidden. | 662 // m_drawingBuffer deletes mailbox immediately when hidden. |
| 592 | 663 |
| 593 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); | 664 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); |
| 594 | 665 |
| 595 m_drawingBuffer->beginDestruction(); | 666 m_drawingBuffer->beginDestruction(); |
| 596 } | 667 } |
| 597 | 668 |
| 598 } // namespace blink | 669 } // namespace blink |
| OLD | NEW |