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

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: Fix release 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
« no previous file with comments | « Source/platform/graphics/gpu/DrawingBuffer.cpp ('k') | Source/web/WebRuntimeFeatures.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10 matching lines...) Expand all
55 void forciblyLoseOldestContext(const String& reason) { } 56 void forciblyLoseOldestContext(const String& reason) { }
56 IntSize oldestContextSize() { return IntSize(); } 57 IntSize oldestContextSize() { return IntSize(); }
57 }; 58 };
58 59
59 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D { 60 class WebGraphicsContext3DForTests : public MockWebGraphicsContext3D {
60 public: 61 public:
61 WebGraphicsContext3DForTests() 62 WebGraphicsContext3DForTests()
62 : MockWebGraphicsContext3D() 63 : MockWebGraphicsContext3D()
63 , m_boundTexture(0) 64 , m_boundTexture(0)
64 , m_currentMailboxByte(0) 65 , m_currentMailboxByte(0)
65 , m_mostRecentlyWaitedSyncPoint(0) { } 66 , m_mostRecentlyWaitedSyncPoint(0)
67 , m_currentImageId(1) { }
66 68
67 virtual void bindTexture(WGC3Denum target, WebGLId texture) 69 virtual void bindTexture(WGC3Denum target, WebGLId texture)
68 { 70 {
69 if (target == GL_TEXTURE_2D) { 71 if (target == GL_TEXTURE_2D) {
70 m_boundTexture = texture; 72 m_boundTexture = texture;
71 } 73 }
72 } 74 }
73 75
74 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denum type, const void* pixels) 76 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denum type, const void* pixels)
75 { 77 {
(...skipping 24 matching lines...) Expand all
100 { 102 {
101 static unsigned syncPointGenerator = 0; 103 static unsigned syncPointGenerator = 0;
102 return ++syncPointGenerator; 104 return ++syncPointGenerator;
103 } 105 }
104 106
105 virtual void waitSyncPoint(unsigned syncPoint) 107 virtual void waitSyncPoint(unsigned syncPoint)
106 { 108 {
107 m_mostRecentlyWaitedSyncPoint = syncPoint; 109 m_mostRecentlyWaitedSyncPoint = syncPoint;
108 } 110 }
109 111
112 virtual WGC3Duint createImageCHROMIUM(WGC3Dsizei width, WGC3Dsizei height, W GC3Denum internalformat, WGC3Denum usage)
113 {
114 m_imageSizes.set(m_currentImageId, IntSize(width, height));
115 return m_currentImageId++;
116 }
117
118 MOCK_METHOD1(destroyImageMock, void(WGC3Duint imageId));
119 void destroyImageCHROMIUM(WGC3Duint imageId)
120 {
121 m_imageSizes.remove(imageId);
122 // No textures should be bound to this.
123 ASSERT(m_imageToTextureMap.find(imageId) == m_imageToTextureMap.end());
124 m_imageSizes.remove(imageId);
125 destroyImageMock(imageId);
126 }
127
128 MOCK_METHOD1(bindTexImage2DMock, void(WGC3Dint imageId));
129 void bindTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId)
130 {
131 if (target == GL_TEXTURE_2D) {
132 m_textureSizes.set(m_boundTexture, m_imageSizes.find(imageId)->value );
133 m_imageToTextureMap.set(imageId, m_boundTexture);
134 bindTexImage2DMock(imageId);
135 }
136 }
137
138 MOCK_METHOD1(releaseTexImage2DMock, void(WGC3Dint imageId));
139 void releaseTexImage2DCHROMIUM(WGC3Denum target, WGC3Dint imageId)
140 {
141 if (target == GL_TEXTURE_2D) {
142 m_imageSizes.set(m_currentImageId, IntSize());
143 m_imageToTextureMap.remove(imageId);
144 releaseTexImage2DMock(imageId);
145 }
146 }
147
110 unsigned mostRecentlyWaitedSyncPoint() 148 unsigned mostRecentlyWaitedSyncPoint()
111 { 149 {
112 return m_mostRecentlyWaitedSyncPoint; 150 return m_mostRecentlyWaitedSyncPoint;
113 } 151 }
114 152
153 WGC3Duint nextImageIdToBeCreated()
154 {
155 return m_currentImageId;
156 }
157
115 private: 158 private:
116 WebGLId m_boundTexture; 159 WebGLId m_boundTexture;
117 HashMap<WebGLId, IntSize> m_textureSizes; 160 HashMap<WebGLId, IntSize> m_textureSizes;
118 WGC3Dbyte m_currentMailboxByte; 161 WGC3Dbyte m_currentMailboxByte;
119 IntSize m_mostRecentlyProducedSize; 162 IntSize m_mostRecentlyProducedSize;
120 unsigned m_mostRecentlyWaitedSyncPoint; 163 unsigned m_mostRecentlyWaitedSyncPoint;
164 WGC3Duint m_currentImageId;
165 HashMap<WGC3Duint, IntSize> m_imageSizes;
166 HashMap<WGC3Duint, WebGLId> m_imageToTextureMap;
121 }; 167 };
122 168
123 static const int initialWidth = 100; 169 static const int initialWidth = 100;
124 static const int initialHeight = 100; 170 static const int initialHeight = 100;
125 static const int alternateHeight = 50; 171 static const int alternateHeight = 50;
126 172
127 class DrawingBufferForTests : public DrawingBuffer { 173 class DrawingBufferForTests : public DrawingBuffer {
128 public: 174 public:
129 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<blink::WebGraphic sContext3D> context, 175 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<blink::WebGraphic sContext3D> context,
130 const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextE victionManager> contextEvictionManager) 176 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()); 396 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint());
351 397
352 m_drawingBuffer->beginDestruction(); 398 m_drawingBuffer->beginDestruction();
353 waitSyncPoint = webContext()->insertSyncPoint(); 399 waitSyncPoint = webContext()->insertSyncPoint();
354 mailbox.syncPoint = waitSyncPoint; 400 mailbox.syncPoint = waitSyncPoint;
355 m_drawingBuffer->mailboxReleased(mailbox); 401 m_drawingBuffer->mailboxReleased(mailbox);
356 // m_drawingBuffer waits for the sync point because the destruction is in pr ogress. 402 // m_drawingBuffer waits for the sync point because the destruction is in pr ogress.
357 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint()); 403 EXPECT_EQ(waitSyncPoint, webContext()->mostRecentlyWaitedSyncPoint());
358 } 404 }
359 405
406 class DrawingBufferImageChromiumTest : public DrawingBufferTest {
407 protected:
408 virtual void SetUp()
409 {
410 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new FakeContextEvictionManager());
411 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests);
412 m_context = context.get();
413 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(true);
414 m_imageId0 = webContext()->nextImageIdToBeCreated();
415 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId0)).Times(1);
416 m_drawingBuffer = DrawingBufferForTests::create(context.release(),
417 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve, conte xtEvictionManager.release());
418 testing::Mock::VerifyAndClearExpectations(webContext());
419 }
420
421 virtual void TearDown()
422 {
423 RuntimeEnabledFeatures::setWebGLImageChromiumEnabled(false);
424 }
425 WGC3Duint m_imageId0;
426 };
427
428 TEST_F(DrawingBufferImageChromiumTest, verifyResizingReallocatesImages)
429 {
430 blink::WebExternalTextureMailbox mailbox;
431
432 IntSize initialSize(initialWidth, initialHeight);
433 IntSize alternateSize(initialWidth, alternateHeight);
434
435 WGC3Duint m_imageId1 = webContext()->nextImageIdToBeCreated();
436 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId1)).Times(1);
437 // Produce one mailbox at size 100x100.
438 m_drawingBuffer->markContentsChanged();
439 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
440 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
441 EXPECT_TRUE(mailbox.allowOverlay);
442 testing::Mock::VerifyAndClearExpectations(webContext());
443
444 WGC3Duint m_imageId2 = webContext()->nextImageIdToBeCreated();
445 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId2)).Times(1);
446 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId0)).Times(1);
447 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId0)).Times(1);
448 // Resize to 100x50.
449 m_drawingBuffer->reset(IntSize(initialWidth, alternateHeight));
450 m_drawingBuffer->mailboxReleased(mailbox);
451 testing::Mock::VerifyAndClearExpectations(webContext());
452
453 WGC3Duint m_imageId3 = webContext()->nextImageIdToBeCreated();
454 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId3)).Times(1);
455 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId1)).Times(1);
456 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId1)).Times(1);
457 // Produce a mailbox at this size.
458 m_drawingBuffer->markContentsChanged();
459 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
460 EXPECT_EQ(alternateSize, webContext()->mostRecentlyProducedSize());
461 EXPECT_TRUE(mailbox.allowOverlay);
462 testing::Mock::VerifyAndClearExpectations(webContext());
463
464 WGC3Duint m_imageId4 = webContext()->nextImageIdToBeCreated();
465 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId4)).Times(1);
466 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId2)).Times(1);
467 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId2)).Times(1);
468 // Reset to initial size.
469 m_drawingBuffer->reset(IntSize(initialWidth, initialHeight));
470 m_drawingBuffer->mailboxReleased(mailbox);
471 testing::Mock::VerifyAndClearExpectations(webContext());
472
473 WGC3Duint m_imageId5 = webContext()->nextImageIdToBeCreated();
474 EXPECT_CALL(*webContext(), bindTexImage2DMock(m_imageId5)).Times(1);
475 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId3)).Times(1);
476 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId3)).Times(1);
477 // Prepare another mailbox and verify that it's the correct size.
478 m_drawingBuffer->markContentsChanged();
479 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
480 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
481 EXPECT_TRUE(mailbox.allowOverlay);
482 testing::Mock::VerifyAndClearExpectations(webContext());
483
484 // Prepare one final mailbox and verify that it's the correct size.
485 m_drawingBuffer->mailboxReleased(mailbox);
486 m_drawingBuffer->markContentsChanged();
487 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
488 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
489 EXPECT_TRUE(mailbox.allowOverlay);
490 m_drawingBuffer->mailboxReleased(mailbox);
491
492 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId5)).Times(1);
493 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId5)).Times(1);
494 EXPECT_CALL(*webContext(), destroyImageMock(m_imageId4)).Times(1);
495 EXPECT_CALL(*webContext(), releaseTexImage2DMock(m_imageId4)).Times(1);
496 m_drawingBuffer->beginDestruction();
497 testing::Mock::VerifyAndClearExpectations(webContext());
498 }
499
360 } // namespace 500 } // namespace
OLDNEW
« no previous file with comments | « Source/platform/graphics/gpu/DrawingBuffer.cpp ('k') | Source/web/WebRuntimeFeatures.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698