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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

Issue 2141793002: Improving canvas 2D performance by switching graphics rendering pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 4 years, 5 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) 2004, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) 140 inline HTMLCanvasElement::HTMLCanvasElement(Document& document)
141 : HTMLElement(canvasTag, document) 141 : HTMLElement(canvasTag, document)
142 , ContextLifecycleObserver(&document) 142 , ContextLifecycleObserver(&document)
143 , PageVisibilityObserver(document.page()) 143 , PageVisibilityObserver(document.page())
144 , m_size(DefaultWidth, DefaultHeight) 144 , m_size(DefaultWidth, DefaultHeight)
145 , m_ignoreReset(false) 145 , m_ignoreReset(false)
146 , m_externallyAllocatedMemory(0) 146 , m_externallyAllocatedMemory(0)
147 , m_originClean(true) 147 , m_originClean(true)
148 , m_didFailToCreateImageBuffer(false) 148 , m_didFailToCreateImageBuffer(false)
149 , m_imageBufferIsClear(false) 149 , m_imageBufferIsClear(false)
150 , m_numFramesSinceLastRenderingModeSwitch(0)
150 { 151 {
151 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::CanvasCreated); 152 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::CanvasCreated);
152 } 153 }
153 154
154 DEFINE_NODE_FACTORY(HTMLCanvasElement) 155 DEFINE_NODE_FACTORY(HTMLCanvasElement)
155 156
156 HTMLCanvasElement::~HTMLCanvasElement() 157 HTMLCanvasElement::~HTMLCanvasElement()
157 { 158 {
158 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory); 159 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory);
159 } 160 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 FloatRect inflatedRect = rect; 286 FloatRect inflatedRect = rect;
286 inflatedRect.inflate(1); 287 inflatedRect.inflate(1);
287 m_dirtyRect.unite(inflatedRect); 288 m_dirtyRect.unite(inflatedRect);
288 } else { 289 } else {
289 m_dirtyRect.unite(rect); 290 m_dirtyRect.unite(rect);
290 } 291 }
291 if (m_context && m_context->is2d() && hasImageBuffer()) 292 if (m_context && m_context->is2d() && hasImageBuffer())
292 buffer()->didDraw(rect); 293 buffer()->didDraw(rect);
293 } 294 }
294 295
296 static void disableAccelerationWrapper(WeakPtr<ImageBuffer> buffer)
297 {
298 if (buffer) {
299 buffer->disableAcceleration();
300 }
301 }
302
295 void HTMLCanvasElement::didFinalizeFrame() 303 void HTMLCanvasElement::didFinalizeFrame()
296 { 304 {
297 notifyListenersCanvasChanged(); 305 notifyListenersCanvasChanged();
298 306
299 if (m_dirtyRect.isEmpty()) 307 if (m_dirtyRect.isEmpty())
300 return; 308 return;
301 309
302 // Propagate the m_dirtyRect accumulated so far to the compositor 310 // Propagate the m_dirtyRect accumulated so far to the compositor
303 // before restarting with a blank dirty rect. 311 // before restarting with a blank dirty rect.
304 FloatRect srcRect(0, 0, size().width(), size().height()); 312 FloatRect srcRect(0, 0, size().width(), size().height());
305 m_dirtyRect.intersect(srcRect); 313 m_dirtyRect.intersect(srcRect);
306 LayoutBox* ro = layoutBox(); 314 LayoutBox* ro = layoutBox();
307 // Canvas content updates do not need to be propagated as 315 // Canvas content updates do not need to be propagated as
308 // paint invalidations if the canvas is accelerated, since 316 // paint invalidations if the canvas is accelerated, since
309 // the canvas contents are sent separately through a texture layer. 317 // the canvas contents are sent separately through a texture layer.
310 if (ro && (!m_context || !m_context->isAccelerated())) { 318 if (ro && (!m_context || !m_context->isAccelerated())) {
311 LayoutRect mappedDirtyRect(enclosingIntRect(mapRect(m_dirtyRect, srcRect , FloatRect(ro->contentBoxRect())))); 319 LayoutRect mappedDirtyRect(enclosingIntRect(mapRect(m_dirtyRect, srcRect , FloatRect(ro->contentBoxRect()))));
312 // For querying PaintLayer::compositingState() 320 // For querying PaintLayer::compositingState()
313 // FIXME: is this invalidation using the correct compositing state? 321 // FIXME: is this invalidation using the correct compositing state?
314 DisableCompositingQueryAsserts disabler; 322 DisableCompositingQueryAsserts disabler;
315 ro->invalidatePaintRectangle(mappedDirtyRect); 323 ro->invalidatePaintRectangle(mappedDirtyRect);
316 } 324 }
317 m_dirtyRect = FloatRect(); 325 m_dirtyRect = FloatRect();
326
327 m_numFramesSinceLastRenderingModeSwitch++;
328 if (m_context->is2d() && buffer()->isAccelerated()
329 && m_numFramesSinceLastRenderingModeSwitch >= ExpensiveCanvasHeuristicPa rameters::MinFramesBeforeSwitch) {
330 if (RuntimeEnabledFeatures::enableCanvas2dDynamicRenderingModeEnabled()) {
331 if (!m_context->isAccelerationOptimalForCanvasContent()) {
332 Platform::current()->currentThread()->getWebTaskRunner()->postTa sk(
Justin Novosad 2016/07/14 18:07:10 Add a comment to explain why the switch is asynchr
sebastienlc 2016/07/14 22:26:53 Done.
333 BLINK_FROM_HERE, WTF::bind(&disableAccelerationWrapper, m_im ageBuffer->m_weakPtrFactory.createWeakPtr()));
Stephen White 2016/07/14 18:53:04 Out of curiosity, would it be possible to use a la
sebastienlc 2016/07/14 22:26:53 Done.
334 m_numFramesSinceLastRenderingModeSwitch = 0;
335 }
336 }
337 }
318 } 338 }
319 339
320 void HTMLCanvasElement::didDisableAcceleration() 340 void HTMLCanvasElement::didDisableAcceleration()
321 { 341 {
322 // We must force a paint invalidation on the canvas even if it's 342 // We must force a paint invalidation on the canvas even if it's
323 // content did not change because it layer was destroyed. 343 // content did not change because it layer was destroyed.
324 didDraw(FloatRect(0, 0, size().width(), size().height())); 344 didDraw(FloatRect(0, 0, size().width(), size().height()));
325 } 345 }
326 346
327 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const 347 void HTMLCanvasElement::restoreCanvasMatrixClipStack(SkCanvas* canvas) const
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 1214
1195 bool HTMLCanvasElement::createSurfaceLayer() 1215 bool HTMLCanvasElement::createSurfaceLayer()
1196 { 1216 {
1197 DCHECK(!m_surfaceLayerBridge); 1217 DCHECK(!m_surfaceLayerBridge);
1198 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl()); 1218 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl());
1199 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient))); 1219 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient)));
1200 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( )); 1220 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( ));
1201 } 1221 }
1202 1222
1203 } // namespace blink 1223 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698