| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 42 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" | 
| 43 #include "wtf/PtrUtil.h" | 43 #include "wtf/PtrUtil.h" | 
| 44 #include "wtf/RefPtr.h" | 44 #include "wtf/RefPtr.h" | 
| 45 #include <memory> | 45 #include <memory> | 
| 46 | 46 | 
| 47 using testing::Test; | 47 using testing::Test; | 
| 48 using testing::_; | 48 using testing::_; | 
| 49 | 49 | 
| 50 namespace blink { | 50 namespace blink { | 
| 51 | 51 | 
| 52 class DrawingBufferTest : public Test { | 52 class DrawingBufferTest : public Test, public DrawingBufferStateTracker { | 
| 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     InitializeRestoreState(); | 
|  | 60     SetRestoreState(); | 
| 59     std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = | 61     std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = | 
| 60         wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 62         wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 
| 61     m_drawingBuffer = DrawingBufferForTests::create( | 63     m_drawingBuffer = DrawingBufferForTests::create( | 
| 62         std::move(provider), initialSize, DrawingBuffer::Preserve); | 64         std::move(provider), this, initialSize, DrawingBuffer::Preserve); | 
| 63     CHECK(m_drawingBuffer); | 65     CHECK(m_drawingBuffer); | 
| 64   } | 66   } | 
| 65 | 67 | 
|  | 68   void GetDrawingBufferRestoreState( | 
|  | 69       DrawingBufferRestoreState* restoreState) override { | 
|  | 70     *restoreState = m_restoreState; | 
|  | 71   } | 
|  | 72 | 
|  | 73   void InitializeRestoreState() { | 
|  | 74     m_restoreState.scissorEnabled = true; | 
|  | 75     m_restoreState.clearColor[0] = 0.5; | 
|  | 76     m_restoreState.clearColor[3] = 0.8; | 
|  | 77     m_restoreState.clearDepth = 0.8; | 
|  | 78     m_restoreState.clearStencil = 37; | 
|  | 79     m_restoreState.colorMask[1] = GL_TRUE; | 
|  | 80     m_restoreState.colorMask[2] = GL_TRUE; | 
|  | 81     m_restoreState.depthMask = GL_FALSE; | 
|  | 82     m_restoreState.stencilMask = GL_FALSE; | 
|  | 83     m_restoreState.packAlignment = 7; | 
|  | 84     m_restoreState.activeTexture2DBinding = 0xbeef1; | 
|  | 85     m_restoreState.renderbufferBinding = 0xbeef2; | 
|  | 86     m_restoreState.drawFramebufferBinding = 0xbeef3; | 
|  | 87     m_restoreState.readFramebufferBinding = 0xbeef4; | 
|  | 88     m_restoreState.pixelUnpackBufferBinding = 0xbeef5; | 
|  | 89   } | 
|  | 90 | 
|  | 91   void SetRestoreState() { | 
|  | 92     if (m_restoreState.scissorEnabled) | 
|  | 93       m_gl->Enable(GL_SCISSOR_TEST); | 
|  | 94     else | 
|  | 95       m_gl->Disable(GL_SCISSOR_TEST); | 
|  | 96 | 
|  | 97     m_gl->ClearColor(m_restoreState.clearColor[0], m_restoreState.clearColor[1], | 
|  | 98                      m_restoreState.clearColor[2], | 
|  | 99                      m_restoreState.clearColor[3]); | 
|  | 100     m_gl->ClearDepthf(m_restoreState.clearDepth); | 
|  | 101     m_gl->ClearStencil(m_restoreState.clearStencil); | 
|  | 102     m_gl->ColorMask(m_restoreState.colorMask[0], m_restoreState.colorMask[1], | 
|  | 103                     m_restoreState.colorMask[2], m_restoreState.colorMask[3]); | 
|  | 104     m_gl->DepthMask(m_restoreState.depthMask); | 
|  | 105     m_gl->StencilMask(m_restoreState.stencilMask); | 
|  | 106     m_gl->PixelStorei(GL_PACK_ALIGNMENT, m_restoreState.packAlignment); | 
|  | 107     m_gl->BindTexture(GL_TEXTURE_2D, m_restoreState.activeTexture2DBinding); | 
|  | 108     m_gl->BindRenderbuffer(GL_RENDERBUFFER, m_restoreState.renderbufferBinding); | 
|  | 109     m_gl->BindFramebuffer(GL_DRAW_FRAMEBUFFER, | 
|  | 110                           m_restoreState.drawFramebufferBinding); | 
|  | 111     m_gl->BindFramebuffer(GL_READ_FRAMEBUFFER, | 
|  | 112                           m_restoreState.readFramebufferBinding); | 
|  | 113     m_gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, | 
|  | 114                      m_restoreState.pixelUnpackBufferBinding); | 
|  | 115   } | 
|  | 116   void VerifyStateWasRestored() { | 
|  | 117     DrawingBufferRestoreState actual = m_gl->getActualRestoreState(); | 
|  | 118     for (size_t i = 0; i < 4; ++i) { | 
|  | 119       EXPECT_EQ(actual.clearColor[0], m_restoreState.clearColor[0]); | 
|  | 120       EXPECT_EQ(actual.colorMask[0], m_restoreState.colorMask[0]); | 
|  | 121     } | 
|  | 122     EXPECT_EQ(actual.clearDepth, m_restoreState.clearDepth); | 
|  | 123     EXPECT_EQ(actual.clearStencil, m_restoreState.clearStencil); | 
|  | 124     EXPECT_EQ(actual.depthMask, m_restoreState.depthMask); | 
|  | 125     EXPECT_EQ(actual.stencilMask, m_restoreState.stencilMask); | 
|  | 126     EXPECT_EQ(actual.packAlignment, m_restoreState.packAlignment); | 
|  | 127     EXPECT_EQ(actual.activeTexture2DBinding, | 
|  | 128               m_restoreState.activeTexture2DBinding); | 
|  | 129     EXPECT_EQ(actual.renderbufferBinding, m_restoreState.renderbufferBinding); | 
|  | 130     EXPECT_EQ(actual.drawFramebufferBinding, | 
|  | 131               m_restoreState.drawFramebufferBinding); | 
|  | 132     EXPECT_EQ(actual.readFramebufferBinding, | 
|  | 133               m_restoreState.readFramebufferBinding); | 
|  | 134     EXPECT_EQ(actual.pixelUnpackBufferBinding, | 
|  | 135               m_restoreState.pixelUnpackBufferBinding); | 
|  | 136   } | 
|  | 137 | 
| 66   GLES2InterfaceForTests* m_gl; | 138   GLES2InterfaceForTests* m_gl; | 
| 67   RefPtr<DrawingBufferForTests> m_drawingBuffer; | 139   RefPtr<DrawingBufferForTests> m_drawingBuffer; | 
|  | 140   DrawingBufferRestoreState m_restoreState; | 
| 68 }; | 141 }; | 
| 69 | 142 | 
| 70 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) { | 143 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) { | 
|  | 144   VerifyStateWasRestored(); | 
| 71   cc::TextureMailbox textureMailbox; | 145   cc::TextureMailbox textureMailbox; | 
| 72   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 146   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 
| 73 | 147 | 
| 74   IntSize initialSize(InitialWidth, InitialHeight); | 148   IntSize initialSize(InitialWidth, InitialHeight); | 
| 75   IntSize alternateSize(InitialWidth, AlternateHeight); | 149   IntSize alternateSize(InitialWidth, AlternateHeight); | 
| 76 | 150 | 
| 77   // Produce one mailbox at size 100x100. | 151   // Produce one mailbox at size 100x100. | 
| 78   m_drawingBuffer->markContentsChanged(); | 152   m_drawingBuffer->markContentsChanged(); | 
| 79   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 153   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 
| 80                                                      &releaseCallback)); | 154                                                      &releaseCallback)); | 
|  | 155   VerifyStateWasRestored(); | 
| 81   EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 156   EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 
| 82 | 157 | 
| 83   // Resize to 100x50. | 158   // Resize to 100x50. | 
| 84   m_drawingBuffer->reset(alternateSize); | 159   m_drawingBuffer->resize(alternateSize); | 
|  | 160   VerifyStateWasRestored(); | 
| 85   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 161   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 
|  | 162   VerifyStateWasRestored(); | 
| 86 | 163 | 
| 87   // Produce a mailbox at this size. | 164   // Produce a mailbox at this size. | 
| 88   m_drawingBuffer->markContentsChanged(); | 165   m_drawingBuffer->markContentsChanged(); | 
| 89   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 166   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 
| 90                                                      &releaseCallback)); | 167                                                      &releaseCallback)); | 
| 91   EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); | 168   EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); | 
|  | 169   VerifyStateWasRestored(); | 
| 92 | 170 | 
| 93   // Reset to initial size. | 171   // Reset to initial size. | 
| 94   m_drawingBuffer->reset(initialSize); | 172   m_drawingBuffer->resize(initialSize); | 
|  | 173   VerifyStateWasRestored(); | 
| 95   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 174   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 
|  | 175   VerifyStateWasRestored(); | 
| 96 | 176 | 
| 97   // Prepare another mailbox and verify that it's the correct size. | 177   // Prepare another mailbox and verify that it's the correct size. | 
| 98   m_drawingBuffer->markContentsChanged(); | 178   m_drawingBuffer->markContentsChanged(); | 
| 99   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 179   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 
| 100                                                      &releaseCallback)); | 180                                                      &releaseCallback)); | 
| 101   EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 181   EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 
|  | 182   VerifyStateWasRestored(); | 
| 102 | 183 | 
| 103   // Prepare one final mailbox and verify that it's the correct size. | 184   // Prepare one final mailbox and verify that it's the correct size. | 
| 104   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 185   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 
| 105   m_drawingBuffer->markContentsChanged(); | 186   m_drawingBuffer->markContentsChanged(); | 
| 106   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 187   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 
| 107                                                      &releaseCallback)); | 188                                                      &releaseCallback)); | 
|  | 189   VerifyStateWasRestored(); | 
| 108   EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 190   EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 
| 109   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 191   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 
| 110   m_drawingBuffer->beginDestruction(); | 192   m_drawingBuffer->beginDestruction(); | 
| 111 } | 193 } | 
| 112 | 194 | 
| 113 TEST_F(DrawingBufferTest, verifyDestructionCompleteAfterAllMailboxesReleased) { | 195 TEST_F(DrawingBufferTest, verifyDestructionCompleteAfterAllMailboxesReleased) { | 
| 114   bool live = true; | 196   bool live = true; | 
| 115   m_drawingBuffer->m_live = &live; | 197   m_drawingBuffer->m_live = &live; | 
| 116 | 198 | 
| 117   cc::TextureMailbox textureMailbox1; | 199   cc::TextureMailbox textureMailbox1; | 
| 118   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 200   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 
| 119   cc::TextureMailbox textureMailbox2; | 201   cc::TextureMailbox textureMailbox2; | 
| 120   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 202   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 
| 121   cc::TextureMailbox textureMailbox3; | 203   cc::TextureMailbox textureMailbox3; | 
| 122   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 204   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 
| 123 | 205 | 
| 124   IntSize initialSize(InitialWidth, InitialHeight); | 206   IntSize initialSize(InitialWidth, InitialHeight); | 
| 125 | 207 | 
| 126   // Produce mailboxes. | 208   // Produce mailboxes. | 
| 127   m_drawingBuffer->markContentsChanged(); | 209   m_drawingBuffer->markContentsChanged(); | 
|  | 210   m_drawingBuffer->clearFramebuffers(GL_STENCIL_BUFFER_BIT); | 
|  | 211   VerifyStateWasRestored(); | 
| 128   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, | 212   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, | 
| 129                                                      &releaseCallback1)); | 213                                                      &releaseCallback1)); | 
| 130   m_drawingBuffer->markContentsChanged(); | 214   m_drawingBuffer->markContentsChanged(); | 
|  | 215   m_drawingBuffer->clearFramebuffers(GL_DEPTH_BUFFER_BIT); | 
|  | 216   VerifyStateWasRestored(); | 
| 131   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, | 217   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, | 
| 132                                                      &releaseCallback2)); | 218                                                      &releaseCallback2)); | 
| 133   m_drawingBuffer->markContentsChanged(); | 219   m_drawingBuffer->markContentsChanged(); | 
|  | 220   m_drawingBuffer->clearFramebuffers(GL_COLOR_BUFFER_BIT); | 
|  | 221   VerifyStateWasRestored(); | 
| 134   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, | 222   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, | 
| 135                                                      &releaseCallback3)); | 223                                                      &releaseCallback3)); | 
| 136 | 224 | 
| 137   m_drawingBuffer->markContentsChanged(); | 225   m_drawingBuffer->markContentsChanged(); | 
| 138   releaseCallback1->Run(gpu::SyncToken(), false /* lostResource */); | 226   releaseCallback1->Run(gpu::SyncToken(), false /* lostResource */); | 
| 139 | 227 | 
| 140   m_drawingBuffer->beginDestruction(); | 228   m_drawingBuffer->beginDestruction(); | 
| 141   ASSERT_EQ(live, true); | 229   ASSERT_EQ(live, true); | 
| 142 | 230 | 
| 143   DrawingBufferForTests* rawPointer = m_drawingBuffer.get(); | 231   DrawingBufferForTests* rawPointer = m_drawingBuffer.get(); | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 160   cc::TextureMailbox textureMailbox1; | 248   cc::TextureMailbox textureMailbox1; | 
| 161   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 249   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 
| 162   cc::TextureMailbox textureMailbox2; | 250   cc::TextureMailbox textureMailbox2; | 
| 163   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 251   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 
| 164   cc::TextureMailbox textureMailbox3; | 252   cc::TextureMailbox textureMailbox3; | 
| 165   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 253   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 
| 166 | 254 | 
| 167   m_drawingBuffer->markContentsChanged(); | 255   m_drawingBuffer->markContentsChanged(); | 
| 168   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, | 256   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, | 
| 169                                                      &releaseCallback1)); | 257                                                      &releaseCallback1)); | 
|  | 258   VerifyStateWasRestored(); | 
| 170   m_drawingBuffer->markContentsChanged(); | 259   m_drawingBuffer->markContentsChanged(); | 
| 171   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, | 260   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, | 
| 172                                                      &releaseCallback2)); | 261                                                      &releaseCallback2)); | 
|  | 262   VerifyStateWasRestored(); | 
| 173   m_drawingBuffer->markContentsChanged(); | 263   m_drawingBuffer->markContentsChanged(); | 
| 174   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, | 264   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, | 
| 175                                                      &releaseCallback3)); | 265                                                      &releaseCallback3)); | 
|  | 266   VerifyStateWasRestored(); | 
| 176 | 267 | 
| 177   m_drawingBuffer->markContentsChanged(); | 268   m_drawingBuffer->markContentsChanged(); | 
| 178   releaseCallback1->Run(gpu::SyncToken(), true /* lostResource */); | 269   releaseCallback1->Run(gpu::SyncToken(), true /* lostResource */); | 
| 179   EXPECT_EQ(live, true); | 270   EXPECT_EQ(live, true); | 
| 180 | 271 | 
| 181   m_drawingBuffer->beginDestruction(); | 272   m_drawingBuffer->beginDestruction(); | 
| 182   EXPECT_EQ(live, true); | 273   EXPECT_EQ(live, true); | 
| 183 | 274 | 
| 184   m_drawingBuffer->markContentsChanged(); | 275   m_drawingBuffer->markContentsChanged(); | 
| 185   releaseCallback2->Run(gpu::SyncToken(), false /* lostResource */); | 276   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()); | 371   EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); | 
| 281 } | 372 } | 
| 282 | 373 | 
| 283 class DrawingBufferImageChromiumTest : public DrawingBufferTest { | 374 class DrawingBufferImageChromiumTest : public DrawingBufferTest { | 
| 284  protected: | 375  protected: | 
| 285   void SetUp() override { | 376   void SetUp() override { | 
| 286     IntSize initialSize(InitialWidth, InitialHeight); | 377     IntSize initialSize(InitialWidth, InitialHeight); | 
| 287     std::unique_ptr<GLES2InterfaceForTests> gl = | 378     std::unique_ptr<GLES2InterfaceForTests> gl = | 
| 288         wrapUnique(new GLES2InterfaceForTests); | 379         wrapUnique(new GLES2InterfaceForTests); | 
| 289     m_gl = gl.get(); | 380     m_gl = gl.get(); | 
|  | 381     InitializeRestoreState(); | 
|  | 382     SetRestoreState(); | 
| 290     std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = | 383     std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = | 
| 291         wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 384         wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 
| 292     RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); | 385     RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); | 
| 293     m_imageId0 = m_gl->nextImageIdToBeCreated(); | 386     m_imageId0 = m_gl->nextImageIdToBeCreated(); | 
| 294     EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId0)).Times(1); | 387     EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId0)).Times(1); | 
| 295     m_drawingBuffer = DrawingBufferForTests::create( | 388     m_drawingBuffer = DrawingBufferForTests::create( | 
| 296         std::move(provider), initialSize, DrawingBuffer::Preserve); | 389         std::move(provider), this, initialSize, DrawingBuffer::Preserve); | 
| 297     CHECK(m_drawingBuffer); | 390     CHECK(m_drawingBuffer); | 
| 298     testing::Mock::VerifyAndClearExpectations(m_gl); | 391     testing::Mock::VerifyAndClearExpectations(m_gl); | 
| 299   } | 392   } | 
| 300 | 393 | 
| 301   void TearDown() override { | 394   void TearDown() override { | 
| 302     RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false); | 395     RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false); | 
| 303   } | 396   } | 
| 304 | 397 | 
| 305   GLuint m_imageId0; | 398   GLuint m_imageId0; | 
| 306 }; | 399 }; | 
| 307 | 400 | 
| 308 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) { | 401 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages) { | 
| 309   cc::TextureMailbox textureMailbox; | 402   cc::TextureMailbox textureMailbox; | 
| 310   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 403   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 
| 311 | 404 | 
| 312   IntSize initialSize(InitialWidth, InitialHeight); | 405   IntSize initialSize(InitialWidth, InitialHeight); | 
| 313   IntSize alternateSize(InitialWidth, AlternateHeight); | 406   IntSize alternateSize(InitialWidth, AlternateHeight); | 
| 314 | 407 | 
| 315   GLuint m_imageId1 = m_gl->nextImageIdToBeCreated(); | 408   GLuint m_imageId1 = m_gl->nextImageIdToBeCreated(); | 
| 316   EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId1)).Times(1); | 409   EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId1)).Times(1); | 
| 317   // Produce one mailbox at size 100x100. | 410   // Produce one mailbox at size 100x100. | 
| 318   m_drawingBuffer->markContentsChanged(); | 411   m_drawingBuffer->markContentsChanged(); | 
| 319   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 412   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 
| 320                                                      &releaseCallback)); | 413                                                      &releaseCallback)); | 
| 321   EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 414   EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 
| 322   EXPECT_TRUE(textureMailbox.is_overlay_candidate()); | 415   EXPECT_TRUE(textureMailbox.is_overlay_candidate()); | 
| 323   testing::Mock::VerifyAndClearExpectations(m_gl); | 416   testing::Mock::VerifyAndClearExpectations(m_gl); | 
|  | 417   VerifyStateWasRestored(); | 
| 324 | 418 | 
| 325   GLuint m_imageId2 = m_gl->nextImageIdToBeCreated(); | 419   GLuint m_imageId2 = m_gl->nextImageIdToBeCreated(); | 
| 326   EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId2)).Times(1); | 420   EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId2)).Times(1); | 
| 327   EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId0)).Times(1); | 421   EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId0)).Times(1); | 
| 328   EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId0)).Times(1); | 422   EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId0)).Times(1); | 
| 329   EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId1)).Times(1); | 423   EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId1)).Times(1); | 
| 330   EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId1)).Times(1); | 424   EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId1)).Times(1); | 
| 331   // Resize to 100x50. | 425   // Resize to 100x50. | 
| 332   m_drawingBuffer->reset(alternateSize); | 426   m_drawingBuffer->resize(alternateSize); | 
|  | 427   VerifyStateWasRestored(); | 
| 333   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 428   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 
|  | 429   VerifyStateWasRestored(); | 
| 334   testing::Mock::VerifyAndClearExpectations(m_gl); | 430   testing::Mock::VerifyAndClearExpectations(m_gl); | 
| 335 | 431 | 
| 336   GLuint m_imageId3 = m_gl->nextImageIdToBeCreated(); | 432   GLuint m_imageId3 = m_gl->nextImageIdToBeCreated(); | 
| 337   EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId3)).Times(1); | 433   EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId3)).Times(1); | 
| 338   // Produce a mailbox at this size. | 434   // Produce a mailbox at this size. | 
| 339   m_drawingBuffer->markContentsChanged(); | 435   m_drawingBuffer->markContentsChanged(); | 
| 340   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 436   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 
| 341                                                      &releaseCallback)); | 437                                                      &releaseCallback)); | 
| 342   EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); | 438   EXPECT_EQ(alternateSize, m_gl->mostRecentlyProducedSize()); | 
| 343   EXPECT_TRUE(textureMailbox.is_overlay_candidate()); | 439   EXPECT_TRUE(textureMailbox.is_overlay_candidate()); | 
| 344   testing::Mock::VerifyAndClearExpectations(m_gl); | 440   testing::Mock::VerifyAndClearExpectations(m_gl); | 
| 345 | 441 | 
| 346   GLuint m_imageId4 = m_gl->nextImageIdToBeCreated(); | 442   GLuint m_imageId4 = m_gl->nextImageIdToBeCreated(); | 
| 347   EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId4)).Times(1); | 443   EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId4)).Times(1); | 
| 348   EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId2)).Times(1); | 444   EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId2)).Times(1); | 
| 349   EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId2)).Times(1); | 445   EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId2)).Times(1); | 
| 350   EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId3)).Times(1); | 446   EXPECT_CALL(*m_gl, DestroyImageMock(m_imageId3)).Times(1); | 
| 351   EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId3)).Times(1); | 447   EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(m_imageId3)).Times(1); | 
| 352   // Reset to initial size. | 448   // Reset to initial size. | 
| 353   m_drawingBuffer->reset(initialSize); | 449   m_drawingBuffer->resize(initialSize); | 
|  | 450   VerifyStateWasRestored(); | 
| 354   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 451   releaseCallback->Run(gpu::SyncToken(), false /* lostResource */); | 
|  | 452   VerifyStateWasRestored(); | 
| 355   testing::Mock::VerifyAndClearExpectations(m_gl); | 453   testing::Mock::VerifyAndClearExpectations(m_gl); | 
| 356 | 454 | 
| 357   GLuint m_imageId5 = m_gl->nextImageIdToBeCreated(); | 455   GLuint m_imageId5 = m_gl->nextImageIdToBeCreated(); | 
| 358   EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId5)).Times(1); | 456   EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId5)).Times(1); | 
| 359   // Prepare another mailbox and verify that it's the correct size. | 457   // Prepare another mailbox and verify that it's the correct size. | 
| 360   m_drawingBuffer->markContentsChanged(); | 458   m_drawingBuffer->markContentsChanged(); | 
| 361   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 459   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, | 
| 362                                                      &releaseCallback)); | 460                                                      &releaseCallback)); | 
| 363   EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 461   EXPECT_EQ(initialSize, m_gl->mostRecentlyProducedSize()); | 
| 364   EXPECT_TRUE(textureMailbox.is_overlay_candidate()); | 462   EXPECT_TRUE(textureMailbox.is_overlay_candidate()); | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 391 | 489 | 
| 392   // Request a mailbox. An image should already be created. Everything works | 490   // Request a mailbox. An image should already be created. Everything works | 
| 393   // as expected. | 491   // as expected. | 
| 394   EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); | 492   EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); | 
| 395   IntSize initialSize(InitialWidth, InitialHeight); | 493   IntSize initialSize(InitialWidth, InitialHeight); | 
| 396   m_drawingBuffer->markContentsChanged(); | 494   m_drawingBuffer->markContentsChanged(); | 
| 397   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, | 495   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox1, | 
| 398                                                      &releaseCallback1)); | 496                                                      &releaseCallback1)); | 
| 399   EXPECT_TRUE(textureMailbox1.is_overlay_candidate()); | 497   EXPECT_TRUE(textureMailbox1.is_overlay_candidate()); | 
| 400   testing::Mock::VerifyAndClearExpectations(m_gl); | 498   testing::Mock::VerifyAndClearExpectations(m_gl); | 
|  | 499   VerifyStateWasRestored(); | 
| 401 | 500 | 
| 402   // Force image CHROMIUM creation failure. Request another mailbox. It should | 501   // Force image CHROMIUM creation failure. Request another mailbox. It should | 
| 403   // still be provided, but this time with allowOverlay = false. | 502   // still be provided, but this time with allowOverlay = false. | 
| 404   m_gl->setCreateImageChromiumFail(true); | 503   m_gl->setCreateImageChromiumFail(true); | 
| 405   m_drawingBuffer->markContentsChanged(); | 504   m_drawingBuffer->markContentsChanged(); | 
| 406   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, | 505   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox2, | 
| 407                                                      &releaseCallback2)); | 506                                                      &releaseCallback2)); | 
| 408   EXPECT_FALSE(textureMailbox2.is_overlay_candidate()); | 507   EXPECT_FALSE(textureMailbox2.is_overlay_candidate()); | 
|  | 508   VerifyStateWasRestored(); | 
| 409 | 509 | 
| 410   // Check that if image CHROMIUM starts working again, mailboxes are | 510   // Check that if image CHROMIUM starts working again, mailboxes are | 
| 411   // correctly created with allowOverlay = true. | 511   // correctly created with allowOverlay = true. | 
| 412   EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); | 512   EXPECT_CALL(*m_gl, BindTexImage2DMock(_)).Times(1); | 
| 413   m_gl->setCreateImageChromiumFail(false); | 513   m_gl->setCreateImageChromiumFail(false); | 
| 414   m_drawingBuffer->markContentsChanged(); | 514   m_drawingBuffer->markContentsChanged(); | 
| 415   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, | 515   EXPECT_TRUE(m_drawingBuffer->PrepareTextureMailbox(&textureMailbox3, | 
| 416                                                      &releaseCallback3)); | 516                                                      &releaseCallback3)); | 
| 417   EXPECT_TRUE(textureMailbox3.is_overlay_candidate()); | 517   EXPECT_TRUE(textureMailbox3.is_overlay_candidate()); | 
| 418   testing::Mock::VerifyAndClearExpectations(m_gl); | 518   testing::Mock::VerifyAndClearExpectations(m_gl); | 
|  | 519   VerifyStateWasRestored(); | 
| 419 | 520 | 
| 420   releaseCallback1->Run(gpu::SyncToken(), false /* lostResource */); | 521   releaseCallback1->Run(gpu::SyncToken(), false /* lostResource */); | 
| 421   releaseCallback2->Run(gpu::SyncToken(), false /* lostResource */); | 522   releaseCallback2->Run(gpu::SyncToken(), false /* lostResource */); | 
| 422   releaseCallback3->Run(gpu::SyncToken(), false /* lostResource */); | 523   releaseCallback3->Run(gpu::SyncToken(), false /* lostResource */); | 
| 423 | 524 | 
| 424   EXPECT_CALL(*m_gl, DestroyImageMock(_)).Times(3); | 525   EXPECT_CALL(*m_gl, DestroyImageMock(_)).Times(3); | 
| 425   EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(_)).Times(3); | 526   EXPECT_CALL(*m_gl, ReleaseTexImage2DMock(_)).Times(3); | 
| 426   m_drawingBuffer->beginDestruction(); | 527   m_drawingBuffer->beginDestruction(); | 
| 427   testing::Mock::VerifyAndClearExpectations(m_gl); | 528   testing::Mock::VerifyAndClearExpectations(m_gl); | 
| 428 } | 529 } | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 525     std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = | 626     std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = | 
| 526         wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 627         wrapUnique(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 
| 527     DrawingBuffer::PreserveDrawingBuffer preserve = DrawingBuffer::Preserve; | 628     DrawingBuffer::PreserveDrawingBuffer preserve = DrawingBuffer::Preserve; | 
| 528 | 629 | 
| 529     bool premultipliedAlpha = false; | 630     bool premultipliedAlpha = false; | 
| 530     bool wantAlphaChannel = true; | 631     bool wantAlphaChannel = true; | 
| 531     bool wantDepthBuffer = cases[i].requestDepth; | 632     bool wantDepthBuffer = cases[i].requestDepth; | 
| 532     bool wantStencilBuffer = cases[i].requestStencil; | 633     bool wantStencilBuffer = cases[i].requestStencil; | 
| 533     bool wantAntialiasing = false; | 634     bool wantAntialiasing = false; | 
| 534     RefPtr<DrawingBuffer> drawingBuffer = DrawingBuffer::create( | 635     RefPtr<DrawingBuffer> drawingBuffer = DrawingBuffer::create( | 
| 535         std::move(provider), IntSize(10, 10), premultipliedAlpha, | 636         std::move(provider), nullptr, IntSize(10, 10), premultipliedAlpha, | 
| 536         wantAlphaChannel, wantDepthBuffer, wantStencilBuffer, wantAntialiasing, | 637         wantAlphaChannel, wantDepthBuffer, wantStencilBuffer, wantAntialiasing, | 
| 537         preserve, DrawingBuffer::WebGL1, DrawingBuffer::AllowChromiumImage); | 638         preserve, DrawingBuffer::WebGL1, DrawingBuffer::AllowChromiumImage); | 
| 538 | 639 | 
| 539     // When we request a depth or a stencil buffer, we will get both. | 640     // When we request a depth or a stencil buffer, we will get both. | 
| 540     EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 641     EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 
| 541               drawingBuffer->hasDepthBuffer()); | 642               drawingBuffer->hasDepthBuffer()); | 
| 542     EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 643     EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 
| 543               drawingBuffer->hasStencilBuffer()); | 644               drawingBuffer->hasStencilBuffer()); | 
| 544     EXPECT_EQ(cases[i].expectedRenderBuffers, | 645     EXPECT_EQ(cases[i].expectedRenderBuffers, | 
| 545               trackingGL->numAllocatedRenderBuffer()); | 646               trackingGL->numAllocatedRenderBuffer()); | 
| 546     if (cases[i].requestDepth || cases[i].requestStencil) { | 647     if (cases[i].requestDepth || cases[i].requestStencil) { | 
| 547       EXPECT_NE(0u, trackingGL->depthStencilAttachment()); | 648       EXPECT_NE(0u, trackingGL->depthStencilAttachment()); | 
| 548       EXPECT_EQ(0u, trackingGL->depthAttachment()); | 649       EXPECT_EQ(0u, trackingGL->depthAttachment()); | 
| 549       EXPECT_EQ(0u, trackingGL->stencilAttachment()); | 650       EXPECT_EQ(0u, trackingGL->stencilAttachment()); | 
| 550     } else { | 651     } else { | 
| 551       EXPECT_EQ(0u, trackingGL->depthStencilAttachment()); | 652       EXPECT_EQ(0u, trackingGL->depthStencilAttachment()); | 
| 552       EXPECT_EQ(0u, trackingGL->depthAttachment()); | 653       EXPECT_EQ(0u, trackingGL->depthAttachment()); | 
| 553       EXPECT_EQ(0u, trackingGL->stencilAttachment()); | 654       EXPECT_EQ(0u, trackingGL->stencilAttachment()); | 
| 554     } | 655     } | 
| 555 | 656 | 
| 556     drawingBuffer->reset(IntSize(10, 20)); | 657     drawingBuffer->resize(IntSize(10, 20)); | 
| 557     EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 658     EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 
| 558               drawingBuffer->hasDepthBuffer()); | 659               drawingBuffer->hasDepthBuffer()); | 
| 559     EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 660     EXPECT_EQ(cases[i].requestDepth || cases[i].requestStencil, | 
| 560               drawingBuffer->hasStencilBuffer()); | 661               drawingBuffer->hasStencilBuffer()); | 
| 561     EXPECT_EQ(cases[i].expectedRenderBuffers, | 662     EXPECT_EQ(cases[i].expectedRenderBuffers, | 
| 562               trackingGL->numAllocatedRenderBuffer()); | 663               trackingGL->numAllocatedRenderBuffer()); | 
| 563     if (cases[i].requestDepth || cases[i].requestStencil) { | 664     if (cases[i].requestDepth || cases[i].requestStencil) { | 
| 564       EXPECT_NE(0u, trackingGL->depthStencilAttachment()); | 665       EXPECT_NE(0u, trackingGL->depthStencilAttachment()); | 
| 565       EXPECT_EQ(0u, trackingGL->depthAttachment()); | 666       EXPECT_EQ(0u, trackingGL->depthAttachment()); | 
| 566       EXPECT_EQ(0u, trackingGL->stencilAttachment()); | 667       EXPECT_EQ(0u, trackingGL->stencilAttachment()); | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 589   m_drawingBuffer->setIsHidden(true); | 690   m_drawingBuffer->setIsHidden(true); | 
| 590   releaseCallback->Run(waitSyncToken, false /* lostResource */); | 691   releaseCallback->Run(waitSyncToken, false /* lostResource */); | 
| 591   // m_drawingBuffer deletes mailbox immediately when hidden. | 692   // m_drawingBuffer deletes mailbox immediately when hidden. | 
| 592 | 693 | 
| 593   EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); | 694   EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); | 
| 594 | 695 | 
| 595   m_drawingBuffer->beginDestruction(); | 696   m_drawingBuffer->beginDestruction(); | 
| 596 } | 697 } | 
| 597 | 698 | 
| 598 }  // namespace blink | 699 }  // namespace blink | 
| OLD | NEW | 
|---|