Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(957)

Side by Side Diff: Source/platform/graphics/gpu/DrawingBufferTest.cpp

Issue 274833002: Enable WebGL rendering into ImageCHROMIUM, backed by a scanout buffer to enable overlay suppor… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 "RuntimeEnabledFeatures.h"
35 #include "platform/graphics/ImageBuffer.h" 36 #include "platform/graphics/ImageBuffer.h"
36 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 37 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
37 #include "platform/graphics/gpu/Extensions3DUtil.h" 38 #include "platform/graphics/gpu/Extensions3DUtil.h"
38 #include "platform/graphics/test/MockWebGraphicsContext3D.h" 39 #include "platform/graphics/test/MockWebGraphicsContext3D.h"
39 #include "public/platform/Platform.h" 40 #include "public/platform/Platform.h"
40 #include "public/platform/WebExternalTextureMailbox.h" 41 #include "public/platform/WebExternalTextureMailbox.h"
41 #include "wtf/RefPtr.h" 42 #include "wtf/RefPtr.h"
42 43
43 #include <gmock/gmock.h> 44 #include <gmock/gmock.h>
44 #include <gtest/gtest.h> 45 #include <gtest/gtest.h>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 { 101 {
101 static unsigned syncPointGenerator = 0; 102 static unsigned syncPointGenerator = 0;
102 return ++syncPointGenerator; 103 return ++syncPointGenerator;
103 } 104 }
104 105
105 virtual void waitSyncPoint(unsigned syncPoint) 106 virtual void waitSyncPoint(unsigned syncPoint)
106 { 107 {
107 m_mostRecentlyWaitedSyncPoint = syncPoint; 108 m_mostRecentlyWaitedSyncPoint = syncPoint;
108 } 109 }
109 110
111 virtual WGC3Duint createImageCHROMIUM(WGC3Dsizei width, WGC3Dsizei height, W GC3Denum internalformat, WGC3Denum usage)
112 {
113 m_imageSizes.set(m_currentImageId, IntSize(width, height));
114 return m_currentImageId++;
115 }
116
117 MOCK_METHOD1(destroyImageMock, void(WGC3Duint imageId));
118 void destroyImageCHROMIUM(WGC3Duint imageId)
119 {
120 m_imageSizes.remove(imageId);
121 // No textures should be bound to this.
122 ASSERT(m_imageToTextureMap.find(imageId) == m_imageToTextureMap.end());
123 m_imageSizes.remove(imageId);
124 destroyImageMock(imageId);
125 }
126
127 MOCK_METHOD1(bindTexImage2DMock, void(WGC3Dint imageId));
128 void bindTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId)
129 {
130 if (target == GL_TEXTURE_2D) {
131 m_textureSizes.set(m_boundTexture, m_imageSizes.find(imageId)->value );
132 m_imageToTextureMap.set(imageId, m_boundTexture);
133 bindTexImage2DMock(imageId);
134 }
135 }
136
137 MOCK_METHOD1(releaseTexImage2DMock, void(WGC3Dint imageId));
138 void releaseTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId)
139 {
140 if (target == GL_TEXTURE_2D) {
141 m_imageSizes.set(m_currentImageId, IntSize());
142 m_imageToTextureMap.remove(imageId);
143 releaseTexImage2DMock(imageId);
144 }
145 }
146
110 unsigned mostRecentlyWaitedSyncPoint() 147 unsigned mostRecentlyWaitedSyncPoint()
111 { 148 {
112 return m_mostRecentlyWaitedSyncPoint; 149 return m_mostRecentlyWaitedSyncPoint;
113 } 150 }
114 151
152 WGC3Duint nextImageIdToBeCreated()
153 {
154 return m_currentImageId;
155 }
156
115 private: 157 private:
116 WebGLId m_boundTexture; 158 WebGLId m_boundTexture;
117 HashMap<WebGLId, IntSize> m_textureSizes; 159 HashMap<WebGLId, IntSize> m_textureSizes;
118 WGC3Dbyte m_currentMailboxByte; 160 WGC3Dbyte m_currentMailboxByte;
119 IntSize m_mostRecentlyProducedSize; 161 IntSize m_mostRecentlyProducedSize;
120 unsigned m_mostRecentlyWaitedSyncPoint; 162 unsigned m_mostRecentlyWaitedSyncPoint;
163 WGC3Duint m_currentImageId;
164 HashMap<WGC3Duint, IntSize> m_imageSizes;
165 HashMap<WGC3Duint, WebGLId> m_imageToTextureMap;
121 }; 166 };
122 167
123 static const int initialWidth = 100; 168 static const int initialWidth = 100;
124 static const int initialHeight = 100; 169 static const int initialHeight = 100;
125 static const int alternateHeight = 50; 170 static const int alternateHeight = 50;
126 171
127 class DrawingBufferForTests : public DrawingBuffer { 172 class DrawingBufferForTests : public DrawingBuffer {
128 public: 173 public:
129 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<blink::WebGraphic sContext3D> context, 174 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<blink::WebGraphic sContext3D> context,
130 const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextE victionManager> contextEvictionManager) 175 const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextE victionManager> contextEvictionManager)
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint()); 395 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint());
351 396
352 m_drawingBuffer->beginDestruction(); 397 m_drawingBuffer->beginDestruction();
353 waitSyncPoint = webContext()->insertSyncPoint(); 398 waitSyncPoint = webContext()->insertSyncPoint();
354 mailbox.syncPoint = waitSyncPoint; 399 mailbox.syncPoint = waitSyncPoint;
355 m_drawingBuffer->mailboxReleased(mailbox); 400 m_drawingBuffer->mailboxReleased(mailbox);
356 // m_drawingBuffer waits for the sync point because the destruction is in pr ogress. 401 // m_drawingBuffer waits for the sync point because the destruction is in pr ogress.
357 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint()); 402 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint());
358 } 403 }
359 404
405 class DrawingBufferImageChromiumTest : public DrawingBufferTest {
406 protected:
407 virtual void SetUp()
408 {
409 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new FakeContextEvictionManager());
410 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests);
411 m_context = context.get();
412 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true);
413 m_imageId0 = webContext()->nextImageIdToBeCreated();
414 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId0)).Times(1);
415 m_drawingBuffer = DrawingBufferForTests::create(context.release(),
416 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve, conte xtEvictionManager.release());
417 testing::Mock::VerifyAndClearExpectations(webContext());
418 }
419
420 virtual void TearDown()
421 {
422 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false);
423 }
424 WGC3Duint m_imageId0;
425 };
426
427 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages)
428 {
429 blink::WebExternalTextureMailbox mailbox;
430
431 IntSize initialSize(initialWidth, initialHeight);
432 IntSize alternateSize(initialWidth, alternateHeight);
433
434 WGC3Duint m_imageId1 = webContext()->nextImageIdToBeCreated();
435 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId1)).Times(1);
436 // Produce one mailbox at size 100x100.
437 m_drawingBuffer->markContentsChanged();
438 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
439 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
440 EXPECT_TRUE(mailbox.allowOverlay);
441 testing::Mock::VerifyAndClearExpectations(webContext());
442
443 WGC3Duint m_imageId2 = webContext()->nextImageIdToBeCreated();
444 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId2)).Times(1);
445 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId0)).Times(1);
446 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId0)).Times(1);
447 // Resize to 100x50.
448 m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight));
449 m_drawingBuffer->mailboxReleased(mailbox);
450 testing::Mock::VerifyAndClearExpectations(webContext());
451
452 WGC3Duint m_imageId3 = webContext()->nextImageIdToBeCreated();
453 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId3)).Times(1);
454 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId1)).Times(1);
455 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId1)).Times(1);
456 // Produce a mailbox at this size.
457 m_drawingBuffer->markContentsChanged();
458 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
459 EXPECT_EQ(alternateSize, webContext()->mostRecentlyProducedSize());
460 EXPECT_TRUE(mailbox.allowOverlay);
461 testing::Mock::VerifyAndClearExpectations(webContext());
462
463 WGC3Duint m_imageId4 = webContext()->nextImageIdToBeCreated();
464 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId4)).Times(1);
465 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId2)).Times(1);
466 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId2)).Times(1);
467 // Reset to initial size.
468 m_drawingBuffer->reset(IntSize(initialWidth, initialHeight));
469 m_drawingBuffer->mailboxReleased(mailbox);
470 testing::Mock::VerifyAndClearExpectations(webContext());
471
472 WGC3Duint m_imageId5 = webContext()->nextImageIdToBeCreated();
473 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId5)).Times(1);
474 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId3)).Times(1);
475 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId3)).Times(1);
476 // Prepare another mailbox and verify that it's the correct size.
477 m_drawingBuffer->markContentsChanged();
478 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
479 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
480 EXPECT_TRUE(mailbox.allowOverlay);
481 testing::Mock::VerifyAndClearExpectations(webContext());
482
483 // Prepare one final mailbox and verify that it's the correct size.
484 m_drawingBuffer->mailboxReleased(mailbox);
485 m_drawingBuffer->markContentsChanged();
486 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
487 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
488 EXPECT_TRUE(mailbox.allowOverlay);
489 m_drawingBuffer->mailboxReleased(mailbox);
490
491 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId5)).Times(1);
492 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId5)).Times(1);
493 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId4)).Times(1);
494 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId4)).Times(1);
495 m_drawingBuffer->beginDestruction();
496 testing::Mock::VerifyAndClearExpectations(webContext());
497 }
498
360 } // namespace 499 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698