| OLD | NEW | 
|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "platform/graphics/gpu/DrawingBuffer.h" | 5 #include "platform/graphics/gpu/DrawingBuffer.h" | 
| 6 | 6 | 
| 7 #include "cc/resources/single_release_callback.h" | 7 #include "cc/resources/single_release_callback.h" | 
| 8 #include "cc/resources/texture_mailbox.h" | 8 #include "cc/resources/texture_mailbox.h" | 
| 9 #include "gpu/command_buffer/client/gles2_interface_stub.h" | 9 #include "gpu/command_buffer/client/gles2_interface_stub.h" | 
| 10 #include "platform/graphics/gpu/DrawingBufferTestHelpers.h" | 10 #include "platform/graphics/gpu/DrawingBufferTestHelpers.h" | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 47  protected: | 47  protected: | 
| 48   void SetUp() override { | 48   void SetUp() override { | 
| 49     IntSize initialSize(InitialWidth, InitialHeight); | 49     IntSize initialSize(InitialWidth, InitialHeight); | 
| 50     std::unique_ptr<GLES2InterfaceForTests> gl = | 50     std::unique_ptr<GLES2InterfaceForTests> gl = | 
| 51         wrapUnique(new GLES2InterfaceForTests); | 51         wrapUnique(new GLES2InterfaceForTests); | 
| 52     std::unique_ptr<WebGraphicsContext3DProviderSoftwareRenderingForTests> | 52     std::unique_ptr<WebGraphicsContext3DProviderSoftwareRenderingForTests> | 
| 53         provider = wrapUnique( | 53         provider = wrapUnique( | 
| 54             new WebGraphicsContext3DProviderSoftwareRenderingForTests( | 54             new WebGraphicsContext3DProviderSoftwareRenderingForTests( | 
| 55                 std::move(gl))); | 55                 std::move(gl))); | 
| 56     m_drawingBuffer = DrawingBufferForTests::create( | 56     m_drawingBuffer = DrawingBufferForTests::create( | 
| 57         std::move(provider), initialSize, DrawingBuffer::Preserve); | 57         std::move(provider), nullptr, initialSize, DrawingBuffer::Preserve); | 
| 58     CHECK(m_drawingBuffer); | 58     CHECK(m_drawingBuffer); | 
| 59   } | 59   } | 
| 60 | 60 | 
| 61   RefPtr<DrawingBufferForTests> m_drawingBuffer; | 61   RefPtr<DrawingBufferForTests> m_drawingBuffer; | 
| 62   bool m_isSoftwareRendering = false; | 62   bool m_isSoftwareRendering = false; | 
| 63 }; | 63 }; | 
| 64 | 64 | 
| 65 TEST_F(DrawingBufferSoftwareRenderingTest, bitmapRecycling) { | 65 TEST_F(DrawingBufferSoftwareRenderingTest, bitmapRecycling) { | 
| 66   cc::TextureMailbox textureMailbox; | 66   cc::TextureMailbox textureMailbox; | 
| 67   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 67   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 
| 68   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 68   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 
| 69   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 69   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 
| 70   IntSize initialSize(InitialWidth, InitialHeight); | 70   IntSize initialSize(InitialWidth, InitialHeight); | 
| 71   IntSize alternateSize(InitialWidth, AlternateHeight); | 71   IntSize alternateSize(InitialWidth, AlternateHeight); | 
| 72 | 72 | 
| 73   m_drawingBuffer->reset(initialSize); | 73   m_drawingBuffer->resize(initialSize); | 
| 74   m_drawingBuffer->markContentsChanged(); | 74   m_drawingBuffer->markContentsChanged(); | 
| 75   m_drawingBuffer->PrepareTextureMailbox( | 75   m_drawingBuffer->PrepareTextureMailbox( | 
| 76       &textureMailbox, &releaseCallback1);  // create a bitmap. | 76       &textureMailbox, &releaseCallback1);  // create a bitmap. | 
| 77   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 77   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 
| 78   releaseCallback1->Run( | 78   releaseCallback1->Run( | 
| 79       gpu::SyncToken(), | 79       gpu::SyncToken(), | 
| 80       false /* lostResource */);  // release bitmap to the recycling queue | 80       false /* lostResource */);  // release bitmap to the recycling queue | 
| 81   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 81   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 
| 82   m_drawingBuffer->markContentsChanged(); | 82   m_drawingBuffer->markContentsChanged(); | 
| 83   m_drawingBuffer->PrepareTextureMailbox( | 83   m_drawingBuffer->PrepareTextureMailbox( | 
| 84       &textureMailbox, &releaseCallback2);  // recycle a bitmap. | 84       &textureMailbox, &releaseCallback2);  // recycle a bitmap. | 
| 85   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 85   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 
| 86   releaseCallback2->Run( | 86   releaseCallback2->Run( | 
| 87       gpu::SyncToken(), | 87       gpu::SyncToken(), | 
| 88       false /* lostResource */);  // release bitmap to the recycling queue | 88       false /* lostResource */);  // release bitmap to the recycling queue | 
| 89   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 89   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 
| 90   m_drawingBuffer->reset(alternateSize); | 90   m_drawingBuffer->resize(alternateSize); | 
| 91   m_drawingBuffer->markContentsChanged(); | 91   m_drawingBuffer->markContentsChanged(); | 
| 92   // Regression test for crbug.com/647896 - Next line must not crash | 92   // Regression test for crbug.com/647896 - Next line must not crash | 
| 93   m_drawingBuffer->PrepareTextureMailbox( | 93   m_drawingBuffer->PrepareTextureMailbox( | 
| 94       &textureMailbox, | 94       &textureMailbox, | 
| 95       &releaseCallback3);  // cause recycling queue to be purged due to resize | 95       &releaseCallback3);  // cause recycling queue to be purged due to resize | 
| 96   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 96   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 
| 97   releaseCallback3->Run(gpu::SyncToken(), false /* lostResource */); | 97   releaseCallback3->Run(gpu::SyncToken(), false /* lostResource */); | 
| 98   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 98   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 
| 99 | 99 | 
| 100   m_drawingBuffer->beginDestruction(); | 100   m_drawingBuffer->beginDestruction(); | 
| 101 } | 101 } | 
| 102 | 102 | 
| 103 }  // unnamed namespace | 103 }  // unnamed namespace | 
| 104 }  // blink | 104 }  // blink | 
| OLD | NEW | 
|---|