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

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

Issue 169933002: WebGL: Don't destroy mailbox textures in the destructor until they're released. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Improve comment. make m_recycledMailboxQueue more succinct. Created 6 years, 8 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 WebGLId m_boundTexture; 98 WebGLId m_boundTexture;
99 HashMap<WebGLId, IntSize> m_textureSizes; 99 HashMap<WebGLId, IntSize> m_textureSizes;
100 WGC3Dbyte m_currentMailboxByte; 100 WGC3Dbyte m_currentMailboxByte;
101 IntSize m_mostRecentlyProducedSize; 101 IntSize m_mostRecentlyProducedSize;
102 }; 102 };
103 103
104 static const int initialWidth = 100; 104 static const int initialWidth = 100;
105 static const int initialHeight = 100; 105 static const int initialHeight = 100;
106 static const int alternateHeight = 50; 106 static const int alternateHeight = 50;
107 107
108 class DrawingBufferForTests : public DrawingBuffer {
109 public:
110 static PassRefPtr<DrawingBufferForTests> create(PassOwnPtr<blink::WebGraphic sContext3D> context,
111 const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextE victionManager> contextEvictionManager)
112 {
113 RefPtr<DrawingBufferForTests> drawingBuffer =
114 adoptRef(new DrawingBufferForTests(context, preserve, contextEvictio nManager));
115 if (!drawingBuffer->initialize(size)) {
116 drawingBuffer->beginDestruction();
117 return PassRefPtr<DrawingBufferForTests>();
118 }
119 return drawingBuffer.release();
120 }
121
122 DrawingBufferForTests(PassOwnPtr<blink::WebGraphicsContext3D> context, Prese rveDrawingBuffer preserve,
123 PassRefPtr<ContextEvictionManager> contextEvictionManager)
124 : DrawingBuffer(context, false /* multisampleExtensionSupported */,
125 false /* packedDepthStencilExtensionSupported */, preserve, contextE victionManager)
126 , m_live(0)
127 { }
128
129 virtual ~DrawingBufferForTests()
130 {
131 if (m_live)
132 *m_live = false;
133 }
134
135 bool* m_live;
136 };
137
108 class DrawingBufferTest : public Test { 138 class DrawingBufferTest : public Test {
109 protected: 139 protected:
110 virtual void SetUp() 140 virtual void SetUp()
111 { 141 {
112 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new FakeContextEvictionManager()); 142 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new FakeContextEvictionManager());
113 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests); 143 OwnPtr<WebGraphicsContext3DForTests> context = adoptPtr(new WebGraphicsC ontext3DForTests);
114 m_context = context.get(); 144 m_context = context.get();
115 m_drawingBuffer = DrawingBuffer::create(context.release(), IntSize(initi alWidth, initialHeight), DrawingBuffer::Preserve, contextEvictionManager.release ()); 145 m_drawingBuffer = DrawingBufferForTests::create(context.release(),
146 IntSize(initialWidth, initialHeight), DrawingBuffer::Preserve, conte xtEvictionManager.release());
116 } 147 }
117 148
118 WebGraphicsContext3DForTests* webContext() 149 WebGraphicsContext3DForTests* webContext()
119 { 150 {
120 return m_context; 151 return m_context;
121 } 152 }
122 153
123 WebGraphicsContext3DForTests* m_context; 154 WebGraphicsContext3DForTests* m_context;
124 RefPtr<DrawingBuffer> m_drawingBuffer; 155 RefPtr<DrawingBufferForTests> m_drawingBuffer;
125 }; 156 };
126 157
127 TEST_F(DrawingBufferTest, testPaintRenderingResultsToCanvas) 158 TEST_F(DrawingBufferTest, testPaintRenderingResultsToCanvas)
128 { 159 {
129 OwnPtr<ImageBufferSurface> imageBufferSurface = adoptPtr(new UnacceleratedIm ageBufferSurface(IntSize(initialWidth, initialHeight))); 160 OwnPtr<ImageBufferSurface> imageBufferSurface = adoptPtr(new UnacceleratedIm ageBufferSurface(IntSize(initialWidth, initialHeight)));
130 EXPECT_FALSE(!imageBufferSurface); 161 EXPECT_FALSE(!imageBufferSurface);
131 EXPECT_TRUE(imageBufferSurface->isValid()); 162 EXPECT_TRUE(imageBufferSurface->isValid());
132 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(imageBufferSurface.rel ease()); 163 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(imageBufferSurface.rel ease());
133 EXPECT_FALSE(!imageBuffer); 164 EXPECT_FALSE(!imageBuffer);
134 EXPECT_FALSE(imageBuffer->isAccelerated()); 165 EXPECT_FALSE(imageBuffer->isAccelerated());
135 EXPECT_FALSE(imageBuffer->bitmap().isNull()); 166 EXPECT_FALSE(imageBuffer->bitmap().isNull());
136 m_drawingBuffer->paintRenderingResultsToCanvas(imageBuffer.get()); 167 m_drawingBuffer->paintRenderingResultsToCanvas(imageBuffer.get());
137 EXPECT_FALSE(imageBuffer->isAccelerated()); 168 EXPECT_FALSE(imageBuffer->isAccelerated());
138 EXPECT_FALSE(imageBuffer->bitmap().isNull()); 169 EXPECT_FALSE(imageBuffer->bitmap().isNull());
170 m_drawingBuffer->beginDestruction();
139 } 171 }
140 172
141 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes) 173 TEST_F(DrawingBufferTest, verifyResizingProperlyAffectsMailboxes)
142 { 174 {
143 blink::WebExternalTextureMailbox mailbox; 175 blink::WebExternalTextureMailbox mailbox;
144 176
145 IntSize initialSize(initialWidth, initialHeight); 177 IntSize initialSize(initialWidth, initialHeight);
146 IntSize alternateSize(initialWidth, alternateHeight); 178 IntSize alternateSize(initialWidth, alternateHeight);
147 179
148 // Produce one mailbox at size 100x100. 180 // Produce one mailbox at size 100x100.
(...skipping 17 matching lines...) Expand all
166 // Prepare another mailbox and verify that it's the correct size. 198 // Prepare another mailbox and verify that it's the correct size.
167 m_drawingBuffer->markContentsChanged(); 199 m_drawingBuffer->markContentsChanged();
168 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); 200 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
169 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); 201 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
170 202
171 // Prepare one final mailbox and verify that it's the correct size. 203 // Prepare one final mailbox and verify that it's the correct size.
172 m_drawingBuffer->mailboxReleased(mailbox); 204 m_drawingBuffer->mailboxReleased(mailbox);
173 m_drawingBuffer->markContentsChanged(); 205 m_drawingBuffer->markContentsChanged();
174 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0)); 206 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
175 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize()); 207 EXPECT_EQ(initialSize, webContext()->mostRecentlyProducedSize());
208 m_drawingBuffer->beginDestruction();
176 } 209 }
177 210
211 TEST_F(DrawingBufferTest, verifyDestructionCompleteAfterAllMailboxesReleased)
212 {
213 bool live = true;
214 m_drawingBuffer->m_live = &live;
215
216 blink::WebExternalTextureMailbox mailbox1;
217 blink::WebExternalTextureMailbox mailbox2;
218 blink::WebExternalTextureMailbox mailbox3;
219
220 IntSize initialSize(initialWidth, initialHeight);
221
222 // Produce mailboxes.
223 m_drawingBuffer->markContentsChanged();
224 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox1, 0));
225 m_drawingBuffer->markContentsChanged();
226 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox2, 0));
227 m_drawingBuffer->markContentsChanged();
228 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&mailbox3, 0));
229
230 m_drawingBuffer->markContentsChanged();
231 m_drawingBuffer->mailboxReleased(mailbox1);
232
233 m_drawingBuffer->beginDestruction();
234 EXPECT_EQ(live, true);
235
236 DrawingBufferForTests* weakPointer = m_drawingBuffer.get();
237 m_drawingBuffer.clear();
238 EXPECT_EQ(live, true);
239
240 weakPointer->markContentsChanged();
241 weakPointer->mailboxReleased(mailbox2);
242 EXPECT_EQ(live, true);
243
244 weakPointer->markContentsChanged();
245 weakPointer->mailboxReleased(mailbox3);
246 EXPECT_EQ(live, false);
247 }
248
249
178 class TextureMailboxWrapper { 250 class TextureMailboxWrapper {
179 public: 251 public:
180 explicit TextureMailboxWrapper(const blink::WebExternalTextureMailbox& mailb ox) 252 explicit TextureMailboxWrapper(const blink::WebExternalTextureMailbox& mailb ox)
181 : m_mailbox(mailbox) 253 : m_mailbox(mailbox)
182 { } 254 { }
183 255
184 bool operator==(const TextureMailboxWrapper& other) const 256 bool operator==(const TextureMailboxWrapper& other) const
185 { 257 {
186 return !memcmp(m_mailbox.name, other.m_mailbox.name, sizeof(m_mailbox.na me)); 258 return !memcmp(m_mailbox.name, other.m_mailbox.name, sizeof(m_mailbox.na me));
187 } 259 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 294
223 // The second recycled mailbox must be 3. 295 // The second recycled mailbox must be 3.
224 m_drawingBuffer->markContentsChanged(); 296 m_drawingBuffer->markContentsChanged();
225 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&recycledMailbox, 0)); 297 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&recycledMailbox, 0));
226 EXPECT_EQ(TextureMailboxWrapper(mailbox3), TextureMailboxWrapper(recycledMai lbox)); 298 EXPECT_EQ(TextureMailboxWrapper(mailbox3), TextureMailboxWrapper(recycledMai lbox));
227 299
228 // The third recycled mailbox must be 1. 300 // The third recycled mailbox must be 1.
229 m_drawingBuffer->markContentsChanged(); 301 m_drawingBuffer->markContentsChanged();
230 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&recycledMailbox, 0)); 302 EXPECT_TRUE(m_drawingBuffer->prepareMailbox(&recycledMailbox, 0));
231 EXPECT_EQ(TextureMailboxWrapper(mailbox1), TextureMailboxWrapper(recycledMai lbox)); 303 EXPECT_EQ(TextureMailboxWrapper(mailbox1), TextureMailboxWrapper(recycledMai lbox));
304
305 m_drawingBuffer->mailboxReleased(mailbox1);
306 m_drawingBuffer->mailboxReleased(mailbox2);
307 m_drawingBuffer->mailboxReleased(mailbox3);
308 m_drawingBuffer->beginDestruction();
232 } 309 }
233 310
234 } // namespace 311 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698