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

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

Issue 251023004: WebGL: Free temporary GPU resources held by inactive or hidden WebGL. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase to ToT 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) 2010, Google Inc. All rights reserved. 2 * Copyright (c) 2010, 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 , m_contentsChangeCommitted(false) 140 , m_contentsChangeCommitted(false)
141 , m_layerComposited(false) 141 , m_layerComposited(false)
142 , m_multisampleMode(None) 142 , m_multisampleMode(None)
143 , m_internalColorFormat(0) 143 , m_internalColorFormat(0)
144 , m_colorFormat(0) 144 , m_colorFormat(0)
145 , m_internalRenderbufferFormat(0) 145 , m_internalRenderbufferFormat(0)
146 , m_maxTextureSize(0) 146 , m_maxTextureSize(0)
147 , m_sampleCount(0) 147 , m_sampleCount(0)
148 , m_packAlignment(4) 148 , m_packAlignment(4)
149 , m_destructionInProgress(false) 149 , m_destructionInProgress(false)
150 , m_isHidden(false)
150 , m_contextEvictionManager(contextEvictionManager) 151 , m_contextEvictionManager(contextEvictionManager)
151 { 152 {
152 // Used by browser tests to detect the use of a DrawingBuffer. 153 // Used by browser tests to detect the use of a DrawingBuffer.
153 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation"); 154 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation");
154 #ifndef NDEBUG 155 #ifndef NDEBUG
155 drawingBufferCounter.increment(); 156 drawingBufferCounter.increment();
156 #endif 157 #endif
157 } 158 }
158 159
159 DrawingBuffer::~DrawingBuffer() 160 DrawingBuffer::~DrawingBuffer()
(...skipping 17 matching lines...) Expand all
177 bool DrawingBuffer::layerComposited() const 178 bool DrawingBuffer::layerComposited() const
178 { 179 {
179 return m_layerComposited; 180 return m_layerComposited;
180 } 181 }
181 182
182 void DrawingBuffer::markLayerComposited() 183 void DrawingBuffer::markLayerComposited()
183 { 184 {
184 m_layerComposited = true; 185 m_layerComposited = true;
185 } 186 }
186 187
188
189 void DrawingBuffer::setIsHidden(bool hidden)
Ken Russell (switch to Gerrit) 2014/04/28 20:51:45 What happens when the DrawingBuffer is un-hidden?
dshwang 2014/04/29 16:07:04 When un-hidden, DrawingBuffer recreate mailbox for
190 {
191 ASSERT(!m_destructionInProgress);
192 bool newHiddenValue = hidden || m_destructionInProgress;
193 if (m_isHidden == newHiddenValue)
194 return;
195
196 m_isHidden = newHiddenValue;
197 if (m_isHidden)
198 freeRecycledMailboxes();
Justin Novosad 2014/04/28 15:21:42 This is a good start. Eventually we should experim
Ken Russell (switch to Gerrit) 2014/04/28 20:51:45 zmo@ is actively working on deciding when to evict
dshwang 2014/04/29 16:07:04 IMO, it's not overlapped with evicting contexts. T
199 }
200
201 void DrawingBuffer::freeRecycledMailboxes()
202 {
203 while (!m_recycledMailboxQueue.isEmpty())
204 deleteMailbox(m_recycledMailboxQueue.takeLast());
205 }
206
187 blink::WebGraphicsContext3D* DrawingBuffer::context() 207 blink::WebGraphicsContext3D* DrawingBuffer::context()
188 { 208 {
189 return m_context.get(); 209 return m_context.get();
190 } 210 }
191 211
192 bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox, blink::WebExternalBitmap* bitmap) 212 bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox, blink::WebExternalBitmap* bitmap)
193 { 213 {
194 if (!m_contentsChanged) 214 if (!m_contentsChanged || m_isHidden)
195 return false; 215 return false;
196 216
197 if (m_destructionInProgress) { 217 if (m_destructionInProgress) {
198 // It can be hit in the following sequence. 218 // It can be hit in the following sequence.
199 // 1. WebGL draws something. 219 // 1. WebGL draws something.
200 // 2. The compositor begins the frame. 220 // 2. The compositor begins the frame.
201 // 3. Javascript makes a context lost using WEBGL_lose_context extension . 221 // 3. Javascript makes a context lost using WEBGL_lose_context extension .
202 // 4. Here. 222 // 4. Here.
203 return false; 223 return false;
204 } 224 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h as live mailboxes 287 // set m_parentDrawingBuffer to make sure 'this' stays alive as long as it h as live mailboxes
268 ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer); 288 ASSERT(!frontColorBufferMailbox->m_parentDrawingBuffer);
269 frontColorBufferMailbox->m_parentDrawingBuffer = this; 289 frontColorBufferMailbox->m_parentDrawingBuffer = this;
270 *outMailbox = frontColorBufferMailbox->mailbox; 290 *outMailbox = frontColorBufferMailbox->mailbox;
271 m_frontColorBuffer = frontColorBufferMailbox->textureId; 291 m_frontColorBuffer = frontColorBufferMailbox->textureId;
272 return true; 292 return true;
273 } 293 }
274 294
275 void DrawingBuffer::mailboxReleased(const blink::WebExternalTextureMailbox& mail box) 295 void DrawingBuffer::mailboxReleased(const blink::WebExternalTextureMailbox& mail box)
276 { 296 {
277 if (m_destructionInProgress) { 297 if (m_destructionInProgress || m_isHidden) {
278 mailboxReleasedWhileDestructionInProgress(mailbox); 298 mailboxReleasedWithoutRecycling(mailbox);
279 return; 299 return;
280 } 300 }
281 301
282 for (size_t i = 0; i < m_textureMailboxes.size(); i++) { 302 for (size_t i = 0; i < m_textureMailboxes.size(); i++) {
283 RefPtr<MailboxInfo> mailboxInfo = m_textureMailboxes[i]; 303 RefPtr<MailboxInfo> mailboxInfo = m_textureMailboxes[i];
284 if (nameEquals(mailboxInfo->mailbox, mailbox)) { 304 if (nameEquals(mailboxInfo->mailbox, mailbox)) {
285 mailboxInfo->mailbox.syncPoint = mailbox.syncPoint; 305 mailboxInfo->mailbox.syncPoint = mailbox.syncPoint;
286 ASSERT(mailboxInfo->m_parentDrawingBuffer.get() == this); 306 ASSERT(mailboxInfo->m_parentDrawingBuffer.get() == this);
287 mailboxInfo->m_parentDrawingBuffer.clear(); 307 mailboxInfo->m_parentDrawingBuffer.clear();
288 m_recycledMailboxQueue.prepend(mailboxInfo->mailbox); 308 m_recycledMailboxQueue.prepend(mailboxInfo->mailbox);
289 return; 309 return;
290 } 310 }
291 } 311 }
292 ASSERT_NOT_REACHED(); 312 ASSERT_NOT_REACHED();
293 } 313 }
294 314
295 void DrawingBuffer::mailboxReleasedWhileDestructionInProgress(const blink::WebEx ternalTextureMailbox& mailbox) 315 void DrawingBuffer::mailboxReleasedWithoutRecycling(const blink::WebExternalText ureMailbox& mailbox)
296 { 316 {
297 ASSERT(m_textureMailboxes.size()); 317 ASSERT(m_textureMailboxes.size());
298 m_context->makeContextCurrent(); 318 m_context->makeContextCurrent();
299 // Ensure not to call the destructor until deleteMailbox() is completed. 319 // Ensure not to call the destructor until deleteMailbox() is completed.
300 RefPtr<DrawingBuffer> self = this; 320 RefPtr<DrawingBuffer> self = this;
301 deleteMailbox(mailbox); 321 deleteMailbox(mailbox);
302 } 322 }
303 323
304 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() 324 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox()
305 { 325 {
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 } 1034 }
1015 } 1035 }
1016 1036
1017 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLint unpackAlignment) 1037 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLint unpackAlignment)
1018 { 1038 {
1019 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 || unpackAlignment == 8); 1039 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 || unpackAlignment == 8);
1020 m_context->texImage2D(target, level, internalformat, width, height, border, format, type, 0); 1040 m_context->texImage2D(target, level, internalformat, width, height, border, format, type, 0);
1021 } 1041 }
1022 1042
1023 } // namespace WebCore 1043 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698