OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/graphics/gpu/DrawingBuffer.h" |
| 6 |
| 7 #include "cc/resources/single_release_callback.h" |
| 8 #include "cc/resources/texture_mailbox.h" |
| 9 #include "gpu/command_buffer/client/gles2_interface_stub.h" |
| 10 #include "platform/graphics/gpu/DrawingBufferTestHelpers.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 // These unit tests are separate from DrawingBufferTests.cpp because they are bu
ilt |
| 14 // as a part of webkit_unittests instead blink_platform_unittests because the |
| 15 // software rendering mode has a dependency on the blink::Platform interface |
| 16 // for buffer allocations. |
| 17 |
| 18 namespace blink { |
| 19 namespace { |
| 20 |
| 21 using namespace testing; |
| 22 |
| 23 class WebGraphicsContext3DProviderSoftwareRenderingForTests : public WebGraphics
Context3DProvider { |
| 24 public: |
| 25 WebGraphicsContext3DProviderSoftwareRenderingForTests(std::unique_ptr<gpu::g
les2::GLES2Interface> gl) |
| 26 : m_gl(std::move(gl)) |
| 27 { |
| 28 } |
| 29 |
| 30 gpu::gles2::GLES2Interface* contextGL() override { return m_gl.get(); } |
| 31 bool isSoftwareRendering() const override { return true; } |
| 32 |
| 33 // Not used by WebGL code. |
| 34 GrContext* grContext() override { return nullptr; } |
| 35 bool bindToCurrentThread() override { return false; } |
| 36 gpu::Capabilities getCapabilities() override { return gpu::Capabilities(); } |
| 37 void setLostContextCallback(WebClosure) {} |
| 38 void setErrorMessageCallback(WebFunction<void(const char*, int32_t id)>) {} |
| 39 |
| 40 private: |
| 41 std::unique_ptr<gpu::gles2::GLES2Interface> m_gl; |
| 42 }; |
| 43 |
| 44 class DrawingBufferSoftwareRenderingTest : public Test { |
| 45 protected: |
| 46 void SetUp() override |
| 47 { |
| 48 IntSize initialSize(InitialWidth, InitialHeight); |
| 49 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa
ceForTests); |
| 50 std::unique_ptr<WebGraphicsContext3DProviderSoftwareRenderingForTests> p
rovider = wrapUnique(new WebGraphicsContext3DProviderSoftwareRenderingForTests(s
td::move(gl))); |
| 51 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), ini
tialSize, DrawingBuffer::Preserve); |
| 52 CHECK(m_drawingBuffer); |
| 53 } |
| 54 |
| 55 RefPtr<DrawingBufferForTests> m_drawingBuffer; |
| 56 bool m_isSoftwareRendering = false; |
| 57 }; |
| 58 |
| 59 TEST_F(DrawingBufferSoftwareRenderingTest, bitmapRecycling) |
| 60 { |
| 61 cc::TextureMailbox textureMailbox; |
| 62 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; |
| 63 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; |
| 64 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; |
| 65 IntSize initialSize(InitialWidth, InitialHeight); |
| 66 IntSize alternateSize(InitialWidth, AlternateHeight); |
| 67 |
| 68 m_drawingBuffer->reset(initialSize); |
| 69 m_drawingBuffer->markContentsChanged(); |
| 70 m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &releaseCallback1);
// create a bitmap. |
| 71 EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); |
| 72 releaseCallback1->Run(gpu::SyncToken(), false /* lostResource */); // releas
e bitmap to the recycling queue |
| 73 EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); |
| 74 m_drawingBuffer->markContentsChanged(); |
| 75 m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &releaseCallback2);
// recycle a bitmap. |
| 76 EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); |
| 77 releaseCallback2->Run(gpu::SyncToken(), false /* lostResource */); // releas
e bitmap to the recycling queue |
| 78 EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); |
| 79 m_drawingBuffer->reset(alternateSize); |
| 80 m_drawingBuffer->markContentsChanged(); |
| 81 // Regression test for crbug.com/647896 - Next line must not crash |
| 82 m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &releaseCallback3);
// cause recycling queue to be purged due to resize |
| 83 EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); |
| 84 releaseCallback3->Run(gpu::SyncToken(), false /* lostResource */); |
| 85 EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); |
| 86 |
| 87 m_drawingBuffer->beginDestruction(); |
| 88 } |
| 89 |
| 90 } // unnamed namespace |
| 91 } // blink |
OLD | NEW |