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