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/ImageBuffer.h" | 35 #include "platform/graphics/ImageBuffer.h" |
36 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 36 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 37 #include "platform/graphics/gpu/Extensions3DUtil.h" |
37 #include "platform/graphics/test/MockWebGraphicsContext3D.h" | 38 #include "platform/graphics/test/MockWebGraphicsContext3D.h" |
38 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
39 #include "public/platform/WebExternalTextureMailbox.h" | 40 #include "public/platform/WebExternalTextureMailbox.h" |
40 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
41 | 42 |
42 #include <gmock/gmock.h> | 43 #include <gmock/gmock.h> |
43 #include <gtest/gtest.h> | 44 #include <gtest/gtest.h> |
44 | 45 |
45 using namespace WebCore; | 46 using namespace WebCore; |
46 using namespace blink; | 47 using namespace blink; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 WebGLId m_boundTexture; | 99 WebGLId m_boundTexture; |
99 HashMap<WebGLId, IntSize> m_textureSizes; | 100 HashMap<WebGLId, IntSize> m_textureSizes; |
100 WGC3Dbyte m_currentMailboxByte; | 101 WGC3Dbyte m_currentMailboxByte; |
101 IntSize m_mostRecentlyProducedSize; | 102 IntSize m_mostRecentlyProducedSize; |
102 }; | 103 }; |
103 | 104 |
104 static const int initialWidth = 100; | 105 static const int initialWidth = 100; |
105 static const int initialHeight = 100; | 106 static const int initialHeight = 100; |
106 static const int alternateHeight = 50; | 107 static const int alternateHeight = 50; |
107 | 108 |
| 109 class DrawingBufferForTests : public DrawingBuffer { |
| 110 public: |
| 111 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<blink::WebGraphic
sContext3D> context, |
| 112 const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextE
victionManager> contextEvictionManager) |
| 113 { |
| 114 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(conte
xt.get()); |
| 115 RefPtr<DrawingBufferForTests> drawingBuffer = |
| 116 adoptRef(new DrawingBufferForTests(context, extensionsUtil.release()
, preserve, contextEvictionManager)); |
| 117 if (!drawingBuffer->initialize(size)) { |
| 118 drawingBuffer->beginDestruction(); |
| 119 return PassRefPtr<DrawingBufferForTests>(); |
| 120 } |
| 121 return drawingBuffer.release(); |
| 122 } |
| 123 |
| 124 DrawingBufferForTests(PassOwnPtr<blink::WebGraphicsContext3D> context, |
| 125 PassOwnPtr<Extensions3DUtil> extensionsUtil, |
| 126 PreserveDrawingBuffer preserve, |
| 127 PassRefPtr<ContextEvictionManager> contextEvictionManager) |
| 128 : DrawingBuffer(context, extensionsUtil, false /* multisampleExtensionSu
pported */, |
| 129 false /* packedDepthStencilExtensionSupported */, preserve, contextE
victionManager) |
| 130 , m_live(0) |
| 131 { } |
| 132 |
| 133 virtual ~DrawingBufferForTests() |
| 134 { |
| 135 if (m_live) |
| 136 *m_live = false; |
| 137 } |
| 138 |
| 139 bool* m_live; |
| 140 }; |
| 141 |
108 class DrawingBufferTest : public Test { | 142 class DrawingBufferTest : public Test { |
109 protected: | 143 protected: |
110 virtual void SetUp() | 144 virtual void SetUp() |
111 { | 145 { |
112 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new
FakeContextEvictionManager()); | 146 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new
FakeContextEvictionManager()); |
113 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC
ontext3DForTests); | 147 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC
ontext3DForTests); |
114 m_context = context.get(); | 148 m_context = context.get(); |
115 m_drawingBuffer = DrawingBuffer::create(context.release(), IntSize(initi
alWidth, initialHeight), DrawingBuffer::Preserve, contextEvictionManager.release
()); | 149 m_drawingBuffer = DrawingBufferForTests::create(context.release(), |
| 150 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve, conte
xtEvictionManager.release()); |
116 } | 151 } |
117 | 152 |
118 WebGraphicsContext3DForTests* webContext() | 153 WebGraphicsContext3DForTests* webContext() |
119 { | 154 { |
120 return m_context; | 155 return m_context; |
121 } | 156 } |
122 | 157 |
123 WebGraphicsContext3DForTests* m_context; | 158 WebGraphicsContext3DForTests* m_context; |
124 RefPtr<DrawingBuffer> m_drawingBuffer; | 159 RefPtr<DrawingBufferForTests> m_drawingBuffer; |
125 }; | 160 }; |
126 | 161 |
127 TEST_F(DrawingBufferTest, testPaintRenderingResultsToCanvas) | 162 TEST_F(DrawingBufferTest, testPaintRenderingResultsToCanvas) |
128 { | 163 { |
129 OwnPtr<ImageBufferSurface> imageBufferSurface = adoptPtr(new UnacceleratedIm
ageBufferSurface(IntSize(initialWidth, initialHeight))); | 164 OwnPtr<ImageBufferSurface> imageBufferSurface = adoptPtr(new UnacceleratedIm
ageBufferSurface(IntSize(initialWidth, initialHeight))); |
130 EXPECT_FALSE(!imageBufferSurface); | 165 EXPECT_FALSE(!imageBufferSurface); |
131 EXPECT_TRUE(imageBufferSurface->isValid()); | 166 EXPECT_TRUE(imageBufferSurface->isValid()); |
132 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(imageBufferSurface.rel
ease()); | 167 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(imageBufferSurface.rel
ease()); |
133 EXPECT_FALSE(!imageBuffer); | 168 EXPECT_FALSE(!imageBuffer); |
134 EXPECT_FALSE(imageBuffer->isAccelerated()); | 169 EXPECT_FALSE(imageBuffer->isAccelerated()); |
135 EXPECT_FALSE(imageBuffer->bitmap().isNull()); | 170 EXPECT_FALSE(imageBuffer->bitmap().isNull()); |
136 m_drawingBuffer->paintRenderingResultsToCanvas(imageBuffer.get()); | 171 m_drawingBuffer->paintRenderingResultsToCanvas(imageBuffer.get()); |
137 EXPECT_FALSE(imageBuffer->isAccelerated()); | 172 EXPECT_FALSE(imageBuffer->isAccelerated()); |
138 EXPECT_FALSE(imageBuffer->bitmap().isNull()); | 173 EXPECT_FALSE(imageBuffer->bitmap().isNull()); |
| 174 m_drawingBuffer->beginDestruction(); |
139 } | 175 } |
140 | 176 |
141 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) | 177 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) |
142 { | 178 { |
143 blink::WebExternalTextureMailbox mailbox; | 179 blink::WebExternalTextureMailbox mailbox; |
144 | 180 |
145 IntSize initialSize(initialWidth, initialHeight); | 181 IntSize initialSize(initialWidth, initialHeight); |
146 IntSize alternateSize(initialWidth, alternateHeight); | 182 IntSize alternateSize(initialWidth, alternateHeight); |
147 | 183 |
148 // Produce one mailbox at size 100x100. | 184 // Produce one mailbox at size 100x100. |
(...skipping 17 matching lines...) Expand all Loading... |
166 // Prepare another mailbox and verify that it's the correct size. | 202 // Prepare another mailbox and verify that it's the correct size. |
167 m_drawingBuffer->markContentsChanged(); | 203 m_drawingBuffer->markContentsChanged(); |
168 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); | 204 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
169 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); | 205 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); |
170 | 206 |
171 // Prepare one final mailbox and verify that it's the correct size. | 207 // Prepare one final mailbox and verify that it's the correct size. |
172 m_drawingBuffer->mailboxReleased(mailbox); | 208 m_drawingBuffer->mailboxReleased(mailbox); |
173 m_drawingBuffer->markContentsChanged(); | 209 m_drawingBuffer->markContentsChanged(); |
174 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); | 210 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); |
175 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); | 211 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); |
| 212 m_drawingBuffer->beginDestruction(); |
176 } | 213 } |
177 | 214 |
| 215 TEST_F(DrawingBufferTest, verifyDestructionCompleteAfterAllMailboxesReleased) |
| 216 { |
| 217 bool live = true; |
| 218 m_drawingBuffer->m_live = &live; |
| 219 |
| 220 blink::WebExternalTextureMailbox mailbox1; |
| 221 blink::WebExternalTextureMailbox mailbox2; |
| 222 blink::WebExternalTextureMailbox mailbox3; |
| 223 |
| 224 IntSize initialSize(initialWidth, initialHeight); |
| 225 |
| 226 // Produce mailboxes. |
| 227 m_drawingBuffer->markContentsChanged(); |
| 228 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox1, 0)); |
| 229 m_drawingBuffer->markContentsChanged(); |
| 230 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox2, 0)); |
| 231 m_drawingBuffer->markContentsChanged(); |
| 232 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox3, 0)); |
| 233 |
| 234 m_drawingBuffer->markContentsChanged(); |
| 235 m_drawingBuffer->mailboxReleased(mailbox1); |
| 236 |
| 237 m_drawingBuffer->beginDestruction(); |
| 238 EXPECT_EQ(live, true); |
| 239 |
| 240 DrawingBufferForTests* weakPointer = m_drawingBuffer.get(); |
| 241 m_drawingBuffer.clear(); |
| 242 EXPECT_EQ(live, true); |
| 243 |
| 244 weakPointer->markContentsChanged(); |
| 245 weakPointer->mailboxReleased(mailbox2); |
| 246 EXPECT_EQ(live, true); |
| 247 |
| 248 weakPointer->markContentsChanged(); |
| 249 weakPointer->mailboxReleased(mailbox3); |
| 250 EXPECT_EQ(live, false); |
| 251 } |
| 252 |
| 253 |
178 class TextureMailboxWrapper { | 254 class TextureMailboxWrapper { |
179 public: | 255 public: |
180 explicit TextureMailboxWrapper(const blink::WebExternalTextureMailbox& mailb
ox) | 256 explicit TextureMailboxWrapper(const blink::WebExternalTextureMailbox& mailb
ox) |
181 : m_mailbox(mailbox) | 257 : m_mailbox(mailbox) |
182 { } | 258 { } |
183 | 259 |
184 bool operator==(const TextureMailboxWrapper& other) const | 260 bool operator==(const TextureMailboxWrapper& other) const |
185 { | 261 { |
186 return !memcmp(m_mailbox.name, other.m_mailbox.name, sizeof(m_mailbox.na
me)); | 262 return !memcmp(m_mailbox.name, other.m_mailbox.name, sizeof(m_mailbox.na
me)); |
187 } | 263 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 298 |
223 // The second recycled mailbox must be 3. | 299 // The second recycled mailbox must be 3. |
224 m_drawingBuffer->markContentsChanged(); | 300 m_drawingBuffer->markContentsChanged(); |
225 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&recycledMailbox, 0)); | 301 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&recycledMailbox, 0)); |
226 EXPECT_EQ(TextureMailboxWrapper(mailbox3), TextureMailboxWrapper(recycledMai
lbox)); | 302 EXPECT_EQ(TextureMailboxWrapper(mailbox3), TextureMailboxWrapper(recycledMai
lbox)); |
227 | 303 |
228 // The third recycled mailbox must be 1. | 304 // The third recycled mailbox must be 1. |
229 m_drawingBuffer->markContentsChanged(); | 305 m_drawingBuffer->markContentsChanged(); |
230 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&recycledMailbox, 0)); | 306 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&recycledMailbox, 0)); |
231 EXPECT_EQ(TextureMailboxWrapper(mailbox1), TextureMailboxWrapper(recycledMai
lbox)); | 307 EXPECT_EQ(TextureMailboxWrapper(mailbox1), TextureMailboxWrapper(recycledMai
lbox)); |
| 308 |
| 309 m_drawingBuffer->mailboxReleased(mailbox1); |
| 310 m_drawingBuffer->mailboxReleased(mailbox2); |
| 311 m_drawingBuffer->mailboxReleased(mailbox3); |
| 312 m_drawingBuffer->beginDestruction(); |
232 } | 313 } |
233 | 314 |
234 } // namespace | 315 } // namespace |
OLD | NEW |