Chromium Code Reviews| 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 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa ceForTests); | |
| 49 std::unique_ptr<WebGraphicsContext3DProviderSoftwareRenderingForTests> p rovider = wrapUnique(new WebGraphicsContext3DProviderSoftwareRenderingForTests(s td::move(gl))); | |
| 50 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), Int Size(InitialWidth, InitialHeight), DrawingBuffer::Preserve); | |
| 51 CHECK(m_drawingBuffer); | |
| 52 } | |
| 53 | |
| 54 RefPtr<DrawingBufferForTests> m_drawingBuffer; | |
| 55 bool m_isSoftwareRendering = false; | |
| 56 }; | |
| 57 | |
| 58 TEST_F(DrawingBufferSoftwareRenderingTest, bitmapRecycling) | |
| 59 { | |
| 60 cc::TextureMailbox textureMailbox; | |
| 61 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1; | |
| 62 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2; | |
|
xidachen
2016/09/22 01:48:16
callback2 doesn't seem to be used in this test.
| |
| 63 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3; | |
| 64 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback4; | |
| 65 | |
| 66 m_drawingBuffer->reset(IntSize(InitialWidth, InitialHeight)); | |
| 67 m_drawingBuffer->markContentsChanged(); | |
| 68 m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &releaseCallback1); // create a bitmap. | |
| 69 EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | |
| 70 releaseCallback1->Run(gpu::SyncToken(), false /* lostResource */); // releas e bitmap to the recycling queue | |
| 71 EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | |
| 72 m_drawingBuffer->markContentsChanged(); | |
| 73 m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &releaseCallback3); // recycle a bitmap. | |
| 74 EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | |
| 75 releaseCallback3->Run(gpu::SyncToken(), false /* lostResource */); // releas e bitmap to the recycling queue | |
| 76 EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | |
| 77 m_drawingBuffer->reset(IntSize(InitialWidth, AlternateHeight)); | |
| 78 m_drawingBuffer->markContentsChanged(); | |
| 79 // Regression test for crbug.com/647896 - Next line must not crash | |
| 80 m_drawingBuffer->PrepareTextureMailbox(&textureMailbox, &releaseCallback4); // cause recycling queue to be purged due to resize | |
| 81 EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount()); | |
| 82 releaseCallback4->Run(gpu::SyncToken(), false /* lostResource */); | |
| 83 EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount()); | |
| 84 | |
| 85 m_drawingBuffer->beginDestruction(); | |
| 86 } | |
| 87 | |
| 88 } // unnamed namespace | |
| 89 } // blink | |
| OLD | NEW |