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 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include "platform/graphics/gpu/DrawingBuffer.h" | 33 #include "platform/graphics/gpu/DrawingBuffer.h" |
34 | 34 |
35 #include "platform/graphics/GraphicsContext3D.h" | 35 #include "platform/graphics/GraphicsContext3D.h" |
36 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
| 37 #include "public/platform/WebExternalTextureMailbox.h" |
37 #include "web/tests/MockWebGraphicsContext3D.h" | 38 #include "web/tests/MockWebGraphicsContext3D.h" |
38 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
39 | 40 |
40 #include <gmock/gmock.h> | 41 #include <gmock/gmock.h> |
41 #include <gtest/gtest.h> | 42 #include <gtest/gtest.h> |
42 | 43 |
43 using namespace WebCore; | 44 using namespace WebCore; |
44 using namespace blink; | 45 using namespace blink; |
45 using testing::Test; | 46 using testing::Test; |
46 using testing::_; | 47 using testing::_; |
47 | 48 |
48 namespace { | 49 namespace { |
49 | 50 |
50 class FakeContextEvictionManager : public ContextEvictionManager { | 51 class FakeContextEvictionManager : public ContextEvictionManager { |
51 public: | 52 public: |
52 void forciblyLoseOldestContext(const String& reason) { } | 53 void forciblyLoseOldestContext(const String& reason) { } |
53 IntSize oldestContextSize() { return IntSize(); } | 54 IntSize oldestContextSize() { return IntSize(); } |
54 }; | 55 }; |
55 | 56 |
| 57 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D { |
| 58 public: |
| 59 WebGraphicsContext3DForTests() |
| 60 : MockWebGraphicsContext3D() |
| 61 , m_boundTexture(0) |
| 62 , m_currentMailboxByte(0) { } |
| 63 |
| 64 virtual void bindTexture(WGC3Denum target, WebGLId texture) |
| 65 { |
| 66 if (target == GraphicsContext3D::TEXTURE_2D) { |
| 67 m_boundTexture = texture; |
| 68 } |
| 69 } |
| 70 |
| 71 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal
format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format,
WGC3Denum type, const void* pixels) |
| 72 { |
| 73 if (target == GraphicsContext3D::TEXTURE_2D && !level) { |
| 74 m_textureSizes.set(m_boundTexture, IntSize(width, height)); |
| 75 } |
| 76 } |
| 77 |
| 78 virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) |
| 79 { |
| 80 ++m_currentMailboxByte; |
| 81 WebExternalTextureMailbox temp; |
| 82 memset(mailbox, m_currentMailboxByte, sizeof(temp.name)); |
| 83 } |
| 84 |
| 85 virtual void produceTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailb
ox) |
| 86 { |
| 87 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D); |
| 88 m_mostRecentlyProducedSize = m_textureSizes.get(m_boundTexture); |
| 89 } |
| 90 |
| 91 IntSize mostRecentlyProducedSize() |
| 92 { |
| 93 return m_mostRecentlyProducedSize; |
| 94 } |
| 95 |
| 96 private: |
| 97 WebGLId m_boundTexture; |
| 98 HashMap<WebGLId, IntSize> m_textureSizes; |
| 99 WGC3Dbyte m_currentMailboxByte; |
| 100 IntSize m_mostRecentlyProducedSize; |
| 101 }; |
| 102 |
| 103 static const int initialWidth = 100; |
| 104 static const int initialHeight = 100; |
| 105 static const int alternateHeight = 50; |
| 106 |
56 } // namespace | 107 } // namespace |
57 | 108 |
58 class DrawingBufferTest : public Test { | 109 class DrawingBufferTest : public Test { |
59 protected: | 110 protected: |
60 virtual void SetUp() | 111 virtual void SetUp() |
61 { | 112 { |
62 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new
FakeContextEvictionManager()); | 113 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new
FakeContextEvictionManager()); |
63 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon
textFromWebContext(adoptPtr(new MockWebGraphicsContext3D)); | 114 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon
textFromWebContext(adoptPtr(new WebGraphicsContext3DForTests)); |
64 const IntSize size(100, 100); | 115 m_drawingBuffer = DrawingBuffer::create(context.get(), IntSize(initialWi
dth, initialHeight), DrawingBuffer::Discard, contextEvictionManager.release()); |
65 m_drawingBuffer = DrawingBuffer::create(context.get(), size, DrawingBuff
er::Discard, contextEvictionManager.release()); | 116 } |
| 117 |
| 118 WebGraphicsContext3DForTests* webContext() |
| 119 { |
| 120 return static_cast<WebGraphicsContext3DForTests*>(m_drawingBuffer->conte
xt()); |
66 } | 121 } |
67 | 122 |
68 RefPtr<DrawingBuffer> m_drawingBuffer; | 123 RefPtr<DrawingBuffer> m_drawingBuffer; |
69 }; | 124 }; |
70 | 125 |
71 namespace { | 126 namespace { |
72 | 127 |
73 TEST_F(DrawingBufferTest, verifyNoNewBuffersAfterContextLostWithMailboxes) | 128 TEST_F(DrawingBufferTest, verifyNoNewBuffersAfterContextLostWithMailboxes) |
74 { | 129 { |
75 // Tell the buffer its contents changed and context was lost. | 130 // Tell the buffer its contents changed and context was lost. |
76 m_drawingBuffer->markContentsChanged(); | 131 m_drawingBuffer->markContentsChanged(); |
77 m_drawingBuffer->releaseResources(); | 132 m_drawingBuffer->releaseResources(); |
78 | 133 |
79 blink::WebExternalTextureMailbox mailbox; | 134 blink::WebExternalTextureMailbox mailbox; |
80 EXPECT_FALSE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); | 135 EXPECT_FALSE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
81 } | 136 } |
82 | 137 |
| 138 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) |
| 139 { |
| 140 blink::WebExternalTextureMailbox mailbox; |
| 141 |
| 142 IntSize initialSize(initialWidth, initialHeight); |
| 143 IntSize alternateSize(initialWidth, alternateHeight); |
| 144 |
| 145 // Produce one mailbox at size 100x100. |
| 146 m_drawingBuffer->markContentsChanged(); |
| 147 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
| 148 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); |
| 149 |
| 150 // Resize to 100x50. |
| 151 m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight)); |
| 152 m_drawingBuffer->mailboxReleased(mailbox); |
| 153 |
| 154 // Produce a mailbox at this size. |
| 155 m_drawingBuffer->markContentsChanged(); |
| 156 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
| 157 EXPECT_EQ(alternateSize, webContext()->mostRecentlyProducedSize()); |
| 158 |
| 159 // Reset to initial size. |
| 160 m_drawingBuffer->reset(IntSize(initialWidth, initialHeight)); |
| 161 m_drawingBuffer->mailboxReleased(mailbox); |
| 162 |
| 163 // Prepare another mailbox and verify that it's the correct size. |
| 164 m_drawingBuffer->markContentsChanged(); |
| 165 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
| 166 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); |
| 167 |
| 168 // Prepare one final mailbox and verify that it's the correct size. |
| 169 m_drawingBuffer->mailboxReleased(mailbox); |
| 170 m_drawingBuffer->markContentsChanged(); |
| 171 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
| 172 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); |
| 173 } |
| 174 |
83 } // namespace | 175 } // namespace |
OLD | NEW |