| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 46  protected: | 46  protected: | 
| 47   void SetUp() override { | 47   void SetUp() override { | 
| 48     IntSize initialSize(InitialWidth, InitialHeight); | 48     IntSize initialSize(InitialWidth, InitialHeight); | 
| 49     std::unique_ptr<GLES2InterfaceForTests> gl = | 49     std::unique_ptr<GLES2InterfaceForTests> gl = | 
| 50         wrapUnique(new GLES2InterfaceForTests); | 50         wrapUnique(new GLES2InterfaceForTests); | 
| 51     std::unique_ptr<WebGraphicsContext3DProviderSoftwareRenderingForTests> | 51     std::unique_ptr<WebGraphicsContext3DProviderSoftwareRenderingForTests> | 
| 52         provider = wrapUnique( | 52         provider = wrapUnique( | 
| 53             new WebGraphicsContext3DProviderSoftwareRenderingForTests( | 53             new WebGraphicsContext3DProviderSoftwareRenderingForTests( | 
| 54                 std::move(gl))); | 54                 std::move(gl))); | 
| 55     m_drawingBuffer = DrawingBufferForTests::create( | 55     m_drawingBuffer = DrawingBufferForTests::create( | 
| 56         std::move(provider), initialSize, DrawingBuffer::Preserve); | 56         std::move(provider), nullptr, initialSize, DrawingBuffer::Preserve); | 
| 57     CHECK(m_drawingBuffer); | 57     CHECK(m_drawingBuffer); | 
| 58   } | 58   } | 
| 59 | 59 | 
| 60   RefPtr<DrawingBufferForTests> m_drawingBuffer; | 60   RefPtr<DrawingBufferForTests> m_drawingBuffer; | 
| 61   bool m_isSoftwareRendering = false; | 61   bool m_isSoftwareRendering = false; | 
| 62 }; | 62 }; | 
| 63 | 63 | 
| 64 TEST_F(DrawingBufferSoftwareRenderingTest, bitmapRecycling) { | 64 TEST_F(DrawingBufferSoftwareRenderingTest, bitmapRecycling) { | 
| 65   cc::TextureMailbox textureMailbox; | 65   cc::TextureMailbox textureMailbox; | 
| 66   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 66   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | 
| 67   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 67   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | 
| 68   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 68   std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | 
| 69   IntSize initialSize(InitialWidth, InitialHeight); | 69   IntSize initialSize(InitialWidth, InitialHeight); | 
| 70   IntSize alternateSize(InitialWidth, AlternateHeight); | 70   IntSize alternateSize(InitialWidth, AlternateHeight); | 
| 71 | 71 | 
| 72   m_drawingBuffer->reset(initialSize); | 72   m_drawingBuffer->resize(initialSize); | 
| 73   m_drawingBuffer->markContentsChanged(); | 73   m_drawingBuffer->markContentsChanged(); | 
| 74   m_drawingBuffer->PrepareTextureMailbox( | 74   m_drawingBuffer->PrepareTextureMailbox( | 
| 75       &textureMailbox, &releaseCallback1);  // create a bitmap. | 75       &textureMailbox, &releaseCallback1);  // create a bitmap. | 
| 76   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 76   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 
| 77   releaseCallback1->Run( | 77   releaseCallback1->Run( | 
| 78       gpu::SyncToken(), | 78       gpu::SyncToken(), | 
| 79       false /* lostResource */);  // release bitmap to the recycling queue | 79       false /* lostResource */);  // release bitmap to the recycling queue | 
| 80   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 80   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 
| 81   m_drawingBuffer->markContentsChanged(); | 81   m_drawingBuffer->markContentsChanged(); | 
| 82   m_drawingBuffer->PrepareTextureMailbox( | 82   m_drawingBuffer->PrepareTextureMailbox( | 
| 83       &textureMailbox, &releaseCallback2);  // recycle a bitmap. | 83       &textureMailbox, &releaseCallback2);  // recycle a bitmap. | 
| 84   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 84   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 
| 85   releaseCallback2->Run( | 85   releaseCallback2->Run( | 
| 86       gpu::SyncToken(), | 86       gpu::SyncToken(), | 
| 87       false /* lostResource */);  // release bitmap to the recycling queue | 87       false /* lostResource */);  // release bitmap to the recycling queue | 
| 88   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 88   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 
| 89   m_drawingBuffer->reset(alternateSize); | 89   m_drawingBuffer->resize(alternateSize); | 
| 90   m_drawingBuffer->markContentsChanged(); | 90   m_drawingBuffer->markContentsChanged(); | 
| 91   // Regression test for crbug.com/647896 - Next line must not crash | 91   // Regression test for crbug.com/647896 - Next line must not crash | 
| 92   m_drawingBuffer->PrepareTextureMailbox( | 92   m_drawingBuffer->PrepareTextureMailbox( | 
| 93       &textureMailbox, | 93       &textureMailbox, | 
| 94       &releaseCallback3);  // cause recycling queue to be purged due to resize | 94       &releaseCallback3);  // cause recycling queue to be purged due to resize | 
| 95   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 95   EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | 
| 96   releaseCallback3->Run(gpu::SyncToken(), false /* lostResource */); | 96   releaseCallback3->Run(gpu::SyncToken(), false /* lostResource */); | 
| 97   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 97   EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | 
| 98 | 98 | 
| 99   m_drawingBuffer->beginDestruction(); | 99   m_drawingBuffer->beginDestruction(); | 
| 100 } | 100 } | 
| 101 | 101 | 
| 102 }  // unnamed namespace | 102 }  // unnamed namespace | 
| 103 }  // blink | 103 }  // blink | 
| OLD | NEW | 
|---|