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

Side by Side Diff: Source/core/platform/graphics/chromium/Canvas2DLayerBridge.cpp

Issue 16032003: Fixing Canvas2DLayerBridge to handle lost graphics contexts (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 16 matching lines...) Expand all
27 27
28 #include "core/platform/graphics/chromium/Canvas2DLayerBridge.h" 28 #include "core/platform/graphics/chromium/Canvas2DLayerBridge.h"
29 29
30 #include "GrContext.h" 30 #include "GrContext.h"
31 #include "SkDevice.h" 31 #include "SkDevice.h"
32 #include "SkSurface.h" 32 #include "SkSurface.h"
33 #include "core/platform/chromium/TraceEvent.h" 33 #include "core/platform/chromium/TraceEvent.h"
34 #include "core/platform/graphics/GraphicsContext3D.h" 34 #include "core/platform/graphics/GraphicsContext3D.h"
35 #include "core/platform/graphics/chromium/Canvas2DLayerManager.h" 35 #include "core/platform/graphics/chromium/Canvas2DLayerManager.h"
36 #include "core/platform/graphics/chromium/GraphicsLayerChromium.h" 36 #include "core/platform/graphics/chromium/GraphicsLayerChromium.h"
37 #include "core/platform/graphics/gpu/SharedGraphicsContext3D.h"
37 #include <public/Platform.h> 38 #include <public/Platform.h>
38 #include <public/WebCompositorSupport.h> 39 #include <public/WebCompositorSupport.h>
39 #include <public/WebGraphicsContext3D.h> 40 #include <public/WebGraphicsContext3D.h>
40 41
41 using WebKit::WebExternalTextureLayer; 42 using WebKit::WebExternalTextureLayer;
42 using WebKit::WebGraphicsContext3D; 43 using WebKit::WebGraphicsContext3D;
43 using WebKit::WebTextureUpdater; 44 using WebKit::WebTextureUpdater;
44 45
45 namespace WebCore { 46 namespace WebCore {
46 47
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (m_didRecordDrawCommand) { 91 if (m_didRecordDrawCommand) {
91 m_framesPending++; 92 m_framesPending++;
92 m_didRecordDrawCommand = false; 93 m_didRecordDrawCommand = false;
93 if (m_framesPending > 1) 94 if (m_framesPending > 1)
94 flush(); 95 flush();
95 } 96 }
96 } 97 }
97 98
98 void Canvas2DLayerBridge::prepareForDraw() 99 void Canvas2DLayerBridge::prepareForDraw()
99 { 100 {
101 if (!contextIsValid()) {
102 if (m_canvas) {
103 // drop pending commands because there is no surface to draw to
104 m_canvas->silentFlush();
105 }
106 return;
107 }
100 #if !ENABLE(CANVAS_USES_MAILBOX) 108 #if !ENABLE(CANVAS_USES_MAILBOX)
101 m_layer->willModifyTexture(); 109 m_layer->willModifyTexture();
102 #endif 110 #endif
103 m_context->makeContextCurrent(); 111 m_context->makeContextCurrent();
104 } 112 }
105 113
106 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca ted) 114 void Canvas2DLayerBridge::storageAllocatedForRecordingChanged(size_t bytesAlloca ted)
107 { 115 {
108 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated; 116 intptr_t delta = (intptr_t)bytesAllocated - (intptr_t)m_bytesAllocated;
109 m_bytesAllocated = bytesAllocated; 117 m_bytesAllocated = bytesAllocated;
(...skipping 26 matching lines...) Expand all
136 } 144 }
137 145
138 void Canvas2DLayerBridge::flush() 146 void Canvas2DLayerBridge::flush()
139 { 147 {
140 if (m_canvas->hasPendingCommands()) 148 if (m_canvas->hasPendingCommands())
141 m_canvas->flush(); 149 m_canvas->flush();
142 } 150 }
143 151
144 unsigned Canvas2DLayerBridge::prepareTexture(WebTextureUpdater& updater) 152 unsigned Canvas2DLayerBridge::prepareTexture(WebTextureUpdater& updater)
145 { 153 {
154 if (!contextIsValid())
155 return 0;
146 #if ENABLE(CANVAS_USES_MAILBOX) 156 #if ENABLE(CANVAS_USES_MAILBOX)
147 ASSERT_NOT_REACHED(); 157 ASSERT_NOT_REACHED();
148 return 0; 158 return 0;
149 #else 159 #else
150 m_context->makeContextCurrent(); 160 m_context->makeContextCurrent();
151 161
152 TRACE_EVENT0("cc", "Canvas2DLayerBridge::SkCanvas::flush"); 162 TRACE_EVENT0("cc", "Canvas2DLayerBridge::SkCanvas::flush");
153 m_canvas->flush(); 163 m_canvas->flush();
154 m_context->flush(); 164 m_context->flush();
155 165
156 // Notify skia that the state of the backing store texture object will be to uched by the compositor 166 // Notify skia that the state of the backing store texture object will be to uched by the compositor
157 GrRenderTarget* renderTarget = reinterpret_cast<GrRenderTarget*>(m_canvas->g etDevice()->accessRenderTarget()); 167 GrRenderTarget* renderTarget = reinterpret_cast<GrRenderTarget*>(m_canvas->g etDevice()->accessRenderTarget());
158 if (renderTarget) { 168 if (renderTarget) {
159 GrTexture* texture = renderTarget->asTexture(); 169 GrTexture* texture = renderTarget->asTexture();
160 texture->invalidateCachedState(); 170 texture->invalidateCachedState();
161 return texture->getTextureHandle(); 171 return texture->getTextureHandle();
162 } 172 }
163 return 0; 173 return 0;
164 #endif // !ENABLE(CANVAS_USES_MAILBOX) 174 #endif // !ENABLE(CANVAS_USES_MAILBOX)
165 } 175 }
166 176
167 WebGraphicsContext3D* Canvas2DLayerBridge::context() 177 WebGraphicsContext3D* Canvas2DLayerBridge::context()
168 { 178 {
179 ASSERT(m_context.get());
169 return m_context->webContext(); 180 return m_context->webContext();
170 } 181 }
171 182
183 bool Canvas2DLayerBridge::contextIsValid()
184 {
185 RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get();
186 if (!sharedContext || sharedContext->webContext()->isContextLost()) {
danakj 2013/05/24 17:42:36 Do you actually see a way to have isContextLost()
187 // Context was lost since last call to contextIsValid and
188 // SharedGraphicsContext3D has not recovered.
189 m_context.clear();
190 m_layer->clearTexture();
191 return false;
192 }
193 if (m_context != sharedContext) {
194 ASSERT(sharedContext.get());
195 // Old context was lost and sharedContext has recoverred.
Stephen White 2013/05/24 17:51:01 Nit: recovered.
196 // Use the new context to recover the layer
197 m_context = sharedContext;
198 m_layer->clearTexture();
199 GrContext* gr = m_context->grContext();
200 if (gr) {
201 gr->resetContext();
202 SkImage::Info info;
203 info.fWidth = m_canvas->getTopDevice()->width();
204 info.fHeight = m_canvas->getTopDevice()->height();
205 info.fColorType = SkImage::kPMColor_ColorType;
206 info.fAlphaType = SkImage::kPremul_AlphaType;
207 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(gr, info) );
Stephen White 2013/05/24 17:51:01 This should be refactored with the same code in Im
208 if (surface.get()) {
209 m_canvas->setSurface(surface.get());
210 // FIXME: draw sad canvas picture into new buffer crbug.com/
Stephen White 2013/05/24 17:51:01 Need bug ID. :)
211 } else {
212 // Surface allocation failed. Reset m_context to trigger subsequ ent retry
213 m_context.clear();
214 return false;
215 }
216 } else {
217 m_context.clear();
218 return false;
219 }
220 #if !ENABLE(CANVAS_USES_MAILBOX)
221 GrRenderTarget* renderTarget = reinterpret_cast<GrRenderTarget*>(m_canva s->getDevice()->accessRenderTarget());
222 if (renderTarget)
223 m_layer->setTextureId(renderTarget->asTexture()->getTextureHandle()) ;
224 #endif
225 }
226 return true;
227 }
228
172 bool Canvas2DLayerBridge::prepareMailbox(WebKit::WebExternalTextureMailbox* outM ailbox) 229 bool Canvas2DLayerBridge::prepareMailbox(WebKit::WebExternalTextureMailbox* outM ailbox)
173 { 230 {
174 #if ENABLE(CANVAS_USES_MAILBOX) 231 #if ENABLE(CANVAS_USES_MAILBOX)
232 if (!m_canvas.get() || !contextIsValid())
233 return false;
175 // Release to skia textures that were previouosly released by the 234 // Release to skia textures that were previouosly released by the
176 // compositor. We do this before acquiring the next snapshot in 235 // compositor. We do this before acquiring the next snapshot in
177 // order to cap maximum gpu memory consumption. 236 // order to cap maximum gpu memory consumption.
178 m_context->makeContextCurrent(); 237 m_context->makeContextCurrent();
179 Vector<MailboxInfo>::iterator mailboxInfo; 238 Vector<MailboxInfo>::iterator mailboxInfo;
180 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) { 239 for (mailboxInfo = m_mailboxes.begin(); mailboxInfo < m_mailboxes.end(); mai lboxInfo++) {
181 if (mailboxInfo->m_status == MailboxReleased) { 240 if (mailboxInfo->m_status == MailboxReleased) {
182 if (mailboxInfo->m_mailbox.syncPoint) { 241 if (mailboxInfo->m_mailbox.syncPoint) {
183 context()->waitSyncPoint(mailboxInfo->m_mailbox.syncPoint); 242 context()->waitSyncPoint(mailboxInfo->m_mailbox.syncPoint);
184 mailboxInfo->m_mailbox.syncPoint = 0; 243 mailboxInfo->m_mailbox.syncPoint = 0;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // This copy constructor should only be used for Vector reallocation 349 // This copy constructor should only be used for Vector reallocation
291 // Assuming 'other' is to be destroyed, we swap m_image ownership 350 // Assuming 'other' is to be destroyed, we swap m_image ownership
292 // rather than do a refcount dance. 351 // rather than do a refcount dance.
293 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); 352 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox));
294 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image)); 353 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image));
295 m_status = other.m_status; 354 m_status = other.m_status;
296 } 355 }
297 #endif 356 #endif
298 357
299 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698