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 24 matching lines...) Expand all Loading... |
35 #include "platform/RuntimeEnabledFeatures.h" | 35 #include "platform/RuntimeEnabledFeatures.h" |
36 #include "platform/graphics/ImageBuffer.h" | 36 #include "platform/graphics/ImageBuffer.h" |
37 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 37 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
38 #include "platform/graphics/gpu/Extensions3DUtil.h" | 38 #include "platform/graphics/gpu/Extensions3DUtil.h" |
39 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
40 #include "public/platform/WebExternalTextureMailbox.h" | 40 #include "public/platform/WebExternalTextureMailbox.h" |
41 #include "public/platform/WebGraphicsContext3DProvider.h" | 41 #include "public/platform/WebGraphicsContext3DProvider.h" |
42 #include "public/platform/functional/WebFunction.h" | 42 #include "public/platform/functional/WebFunction.h" |
43 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
44 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
45 #include "wtf/PtrUtil.h" | |
46 #include "wtf/RefPtr.h" | 45 #include "wtf/RefPtr.h" |
47 #include <memory> | |
48 | 46 |
49 using testing::Test; | 47 using testing::Test; |
50 using testing::_; | 48 using testing::_; |
51 | 49 |
52 namespace blink { | 50 namespace blink { |
53 | 51 |
54 namespace { | 52 namespace { |
55 | 53 |
56 // The target to use when binding a texture to a Chromium image. | 54 // The target to use when binding a texture to a Chromium image. |
57 GLenum imageCHROMIUMTextureTarget() | 55 GLenum imageCHROMIUMTextureTarget() |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 HashMap<GLuint, IntSize> m_imageSizes; | 208 HashMap<GLuint, IntSize> m_imageSizes; |
211 HashMap<GLuint, GLuint> m_imageToTextureMap; | 209 HashMap<GLuint, GLuint> m_imageToTextureMap; |
212 }; | 210 }; |
213 | 211 |
214 static const int initialWidth = 100; | 212 static const int initialWidth = 100; |
215 static const int initialHeight = 100; | 213 static const int initialHeight = 100; |
216 static const int alternateHeight = 50; | 214 static const int alternateHeight = 50; |
217 | 215 |
218 class DrawingBufferForTests : public DrawingBuffer { | 216 class DrawingBufferForTests : public DrawingBuffer { |
219 public: | 217 public: |
220 static PassRefPtr<DrawingBufferForTests> create(std::unique_ptr<WebGraphicsC
ontext3DProvider> contextProvider, const IntSize& size, PreserveDrawingBuffer pr
eserve) | 218 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<WebGraphicsContex
t3DProvider> contextProvider, const IntSize& size, PreserveDrawingBuffer preserv
e) |
221 { | 219 { |
222 std::unique_ptr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::cre
ate(contextProvider->contextGL()); | 220 OwnPtr<Extensions3DUtil> extensionsUtil = Extensions3DUtil::create(conte
xtProvider->contextGL()); |
223 RefPtr<DrawingBufferForTests> drawingBuffer = adoptRef(new DrawingBuffer
ForTests(std::move(contextProvider), std::move(extensionsUtil), preserve)); | 221 RefPtr<DrawingBufferForTests> drawingBuffer = adoptRef(new DrawingBuffer
ForTests(std::move(contextProvider), std::move(extensionsUtil), preserve)); |
224 bool multisampleExtensionSupported = false; | 222 bool multisampleExtensionSupported = false; |
225 if (!drawingBuffer->initialize(size, multisampleExtensionSupported)) { | 223 if (!drawingBuffer->initialize(size, multisampleExtensionSupported)) { |
226 drawingBuffer->beginDestruction(); | 224 drawingBuffer->beginDestruction(); |
227 return nullptr; | 225 return nullptr; |
228 } | 226 } |
229 return drawingBuffer.release(); | 227 return drawingBuffer.release(); |
230 } | 228 } |
231 | 229 |
232 DrawingBufferForTests(std::unique_ptr<WebGraphicsContext3DProvider> contextP
rovider, std::unique_ptr<Extensions3DUtil> extensionsUtil, PreserveDrawingBuffer
preserve) | 230 DrawingBufferForTests(PassOwnPtr<WebGraphicsContext3DProvider> contextProvid
er, PassOwnPtr<Extensions3DUtil> extensionsUtil, PreserveDrawingBuffer preserve) |
233 : DrawingBuffer(std::move(contextProvider), std::move(extensionsUtil), f
alse /* discardFramebufferSupported */, true /* wantAlphaChannel */, false /* pr
emultipliedAlpha */, preserve, false /* wantDepth */, false /* wantStencil */) | 231 : DrawingBuffer(std::move(contextProvider), std::move(extensionsUtil), f
alse /* discardFramebufferSupported */, true /* wantAlphaChannel */, false /* pr
emultipliedAlpha */, preserve, false /* wantDepth */, false /* wantStencil */) |
234 , m_live(0) | 232 , m_live(0) |
235 { } | 233 { } |
236 | 234 |
237 ~DrawingBufferForTests() override | 235 ~DrawingBufferForTests() override |
238 { | 236 { |
239 if (m_live) | 237 if (m_live) |
240 *m_live = false; | 238 *m_live = false; |
241 } | 239 } |
242 | 240 |
243 bool* m_live; | 241 bool* m_live; |
244 }; | 242 }; |
245 | 243 |
246 class WebGraphicsContext3DProviderForTests : public WebGraphicsContext3DProvider
{ | 244 class WebGraphicsContext3DProviderForTests : public WebGraphicsContext3DProvider
{ |
247 public: | 245 public: |
248 WebGraphicsContext3DProviderForTests(std::unique_ptr<gpu::gles2::GLES2Interf
ace> gl) | 246 WebGraphicsContext3DProviderForTests(PassOwnPtr<gpu::gles2::GLES2Interface>
gl) |
249 : m_gl(std::move(gl)) | 247 : m_gl(std::move(gl)) |
250 { | 248 { |
251 } | 249 } |
252 | 250 |
253 gpu::gles2::GLES2Interface* contextGL() override { return m_gl.get(); } | 251 gpu::gles2::GLES2Interface* contextGL() override { return m_gl.get(); } |
254 // Not used by WebGL code. | 252 // Not used by WebGL code. |
255 GrContext* grContext() override { return nullptr; } | 253 GrContext* grContext() override { return nullptr; } |
256 bool bindToCurrentThread() override { return false; } | 254 bool bindToCurrentThread() override { return false; } |
257 gpu::Capabilities getCapabilities() | 255 gpu::Capabilities getCapabilities() |
258 { | 256 { |
259 return gpu::Capabilities(); | 257 return gpu::Capabilities(); |
260 } | 258 } |
261 void setLostContextCallback(WebClosure) {} | 259 void setLostContextCallback(WebClosure) {} |
262 void setErrorMessageCallback(WebFunction<void(const char*, int32_t id)>) {} | 260 void setErrorMessageCallback(WebFunction<void(const char*, int32_t id)>) {} |
263 | 261 |
264 private: | 262 private: |
265 std::unique_ptr<gpu::gles2::GLES2Interface> m_gl; | 263 OwnPtr<gpu::gles2::GLES2Interface> m_gl; |
266 }; | 264 }; |
267 | 265 |
268 class DrawingBufferTest : public Test { | 266 class DrawingBufferTest : public Test { |
269 protected: | 267 protected: |
270 void SetUp() override | 268 void SetUp() override |
271 { | 269 { |
272 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa
ceForTests); | 270 OwnPtr<GLES2InterfaceForTests> gl = adoptPtr(new GLES2InterfaceForTests)
; |
273 m_gl = gl.get(); | 271 m_gl = gl.get(); |
274 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUni
que(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 272 OwnPtr<WebGraphicsContext3DProviderForTests> provider = adoptPtr(new Web
GraphicsContext3DProviderForTests(std::move(gl))); |
275 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), Int
Size(initialWidth, initialHeight), DrawingBuffer::Preserve); | 273 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), Int
Size(initialWidth, initialHeight), DrawingBuffer::Preserve); |
276 CHECK(m_drawingBuffer); | 274 CHECK(m_drawingBuffer); |
277 } | 275 } |
278 | 276 |
279 GLES2InterfaceForTests* m_gl; | 277 GLES2InterfaceForTests* m_gl; |
280 RefPtr<DrawingBufferForTests> m_drawingBuffer; | 278 RefPtr<DrawingBufferForTests> m_drawingBuffer; |
281 }; | 279 }; |
282 | 280 |
283 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) | 281 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) |
284 { | 282 { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 mailbox.validSyncToken = true; | 482 mailbox.validSyncToken = true; |
485 m_drawingBuffer->mailboxReleased(mailbox, false); | 483 m_drawingBuffer->mailboxReleased(mailbox, false); |
486 // m_drawingBuffer waits for the sync point because the destruction is in pr
ogress. | 484 // m_drawingBuffer waits for the sync point because the destruction is in pr
ogress. |
487 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); | 485 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); |
488 } | 486 } |
489 | 487 |
490 class DrawingBufferImageChromiumTest : public DrawingBufferTest { | 488 class DrawingBufferImageChromiumTest : public DrawingBufferTest { |
491 protected: | 489 protected: |
492 void SetUp() override | 490 void SetUp() override |
493 { | 491 { |
494 std::unique_ptr<GLES2InterfaceForTests> gl = wrapUnique(new GLES2Interfa
ceForTests); | 492 OwnPtr<GLES2InterfaceForTests> gl = adoptPtr(new GLES2InterfaceForTests)
; |
495 m_gl = gl.get(); | 493 m_gl = gl.get(); |
496 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUni
que(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 494 OwnPtr<WebGraphicsContext3DProviderForTests> provider = adoptPtr(new Web
GraphicsContext3DProviderForTests(std::move(gl))); |
497 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); | 495 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true); |
498 m_imageId0 = m_gl->nextImageIdToBeCreated(); | 496 m_imageId0 = m_gl->nextImageIdToBeCreated(); |
499 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId0)).Times(1); | 497 EXPECT_CALL(*m_gl, BindTexImage2DMock(m_imageId0)).Times(1); |
500 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), | 498 m_drawingBuffer = DrawingBufferForTests::create(std::move(provider), |
501 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); | 499 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve); |
502 CHECK(m_drawingBuffer); | 500 CHECK(m_drawingBuffer); |
503 testing::Mock::VerifyAndClearExpectations(m_gl); | 501 testing::Mock::VerifyAndClearExpectations(m_gl); |
504 } | 502 } |
505 | 503 |
506 void TearDown() override | 504 void TearDown() override |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 { | 700 { |
703 DepthStencilTestCase cases[] = { | 701 DepthStencilTestCase cases[] = { |
704 DepthStencilTestCase(false, false, 0, "neither"), | 702 DepthStencilTestCase(false, false, 0, "neither"), |
705 DepthStencilTestCase(true, false, 1, "stencil only"), | 703 DepthStencilTestCase(true, false, 1, "stencil only"), |
706 DepthStencilTestCase(false, true, 1, "depth only"), | 704 DepthStencilTestCase(false, true, 1, "depth only"), |
707 DepthStencilTestCase(true, true, 1, "both"), | 705 DepthStencilTestCase(true, true, 1, "both"), |
708 }; | 706 }; |
709 | 707 |
710 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cases); i++) { | 708 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cases); i++) { |
711 SCOPED_TRACE(cases[i].testCaseName); | 709 SCOPED_TRACE(cases[i].testCaseName); |
712 std::unique_ptr<DepthStencilTrackingGLES2Interface> gl = wrapUnique(new
DepthStencilTrackingGLES2Interface); | 710 OwnPtr<DepthStencilTrackingGLES2Interface> gl = adoptPtr(new DepthStenci
lTrackingGLES2Interface); |
713 DepthStencilTrackingGLES2Interface* trackingGL = gl.get(); | 711 DepthStencilTrackingGLES2Interface* trackingGL = gl.get(); |
714 std::unique_ptr<WebGraphicsContext3DProviderForTests> provider = wrapUni
que(new WebGraphicsContext3DProviderForTests(std::move(gl))); | 712 OwnPtr<WebGraphicsContext3DProviderForTests> provider = adoptPtr(new Web
GraphicsContext3DProviderForTests(std::move(gl))); |
715 DrawingBuffer::PreserveDrawingBuffer preserve = DrawingBuffer::Preserve; | 713 DrawingBuffer::PreserveDrawingBuffer preserve = DrawingBuffer::Preserve; |
716 | 714 |
717 bool premultipliedAlpha = false; | 715 bool premultipliedAlpha = false; |
718 bool wantAlphaChannel = true; | 716 bool wantAlphaChannel = true; |
719 bool wantDepthBuffer = cases[i].requestDepth; | 717 bool wantDepthBuffer = cases[i].requestDepth; |
720 bool wantStencilBuffer = cases[i].requestStencil; | 718 bool wantStencilBuffer = cases[i].requestStencil; |
721 bool wantAntialiasing = false; | 719 bool wantAntialiasing = false; |
722 RefPtr<DrawingBuffer> drawingBuffer = DrawingBuffer::create( | 720 RefPtr<DrawingBuffer> drawingBuffer = DrawingBuffer::create( |
723 std::move(provider), | 721 std::move(provider), |
724 IntSize(10, 10), | 722 IntSize(10, 10), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 // m_drawingBuffer deletes mailbox immediately when hidden. | 774 // m_drawingBuffer deletes mailbox immediately when hidden. |
777 | 775 |
778 GLuint waitSyncToken = 0; | 776 GLuint waitSyncToken = 0; |
779 memcpy(&waitSyncToken, mailbox.syncToken, sizeof(waitSyncToken)); | 777 memcpy(&waitSyncToken, mailbox.syncToken, sizeof(waitSyncToken)); |
780 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); | 778 EXPECT_EQ(waitSyncToken, m_gl->mostRecentlyWaitedSyncToken()); |
781 | 779 |
782 m_drawingBuffer->beginDestruction(); | 780 m_drawingBuffer->beginDestruction(); |
783 } | 781 } |
784 | 782 |
785 } // namespace blink | 783 } // namespace blink |
OLD | NEW |