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

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp

Issue 2191533003: Refactor Timer classes in preparation for landing FrameTimers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More build fixes Created 4 years, 4 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, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved.
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
10 * 10 *
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 209 }
210 210
211 DEFINE_TRACE(CanvasRenderingContext2D) 211 DEFINE_TRACE(CanvasRenderingContext2D)
212 { 212 {
213 visitor->trace(m_hitRegionManager); 213 visitor->trace(m_hitRegionManager);
214 CanvasRenderingContext::trace(visitor); 214 CanvasRenderingContext::trace(visitor);
215 BaseRenderingContext2D::trace(visitor); 215 BaseRenderingContext2D::trace(visitor);
216 SVGResourceClient::trace(visitor); 216 SVGResourceClient::trace(visitor);
217 } 217 }
218 218
219 void CanvasRenderingContext2D::dispatchContextLostEvent(Timer<CanvasRenderingCon text2D>*) 219 void CanvasRenderingContext2D::dispatchContextLostEvent(TimerBase*)
220 { 220 {
221 if (canvas() && contextLostRestoredEventsEnabled()) { 221 if (canvas() && contextLostRestoredEventsEnabled()) {
222 Event* event = Event::createCancelable(EventTypeNames::contextlost); 222 Event* event = Event::createCancelable(EventTypeNames::contextlost);
223 canvas()->dispatchEvent(event); 223 canvas()->dispatchEvent(event);
224 if (event->defaultPrevented()) { 224 if (event->defaultPrevented()) {
225 m_contextRestorable = false; 225 m_contextRestorable = false;
226 } 226 }
227 } 227 }
228 228
229 // If RealLostContext, it means the context was not lost due to surface fail ure 229 // If RealLostContext, it means the context was not lost due to surface fail ure
230 // but rather due to a an eviction, which means image buffer exists. 230 // but rather due to a an eviction, which means image buffer exists.
231 if (m_contextRestorable && m_contextLostMode == RealLostContext) { 231 if (m_contextRestorable && m_contextLostMode == RealLostContext) {
232 m_tryRestoreContextAttemptCount = 0; 232 m_tryRestoreContextAttemptCount = 0;
233 m_tryRestoreContextEventTimer.startRepeating(TryRestoreContextInterval, BLINK_FROM_HERE); 233 m_tryRestoreContextEventTimer.startRepeating(TryRestoreContextInterval, BLINK_FROM_HERE);
234 } 234 }
235 } 235 }
236 236
237 void CanvasRenderingContext2D::tryRestoreContextEvent(Timer<CanvasRenderingConte xt2D>* timer) 237 void CanvasRenderingContext2D::tryRestoreContextEvent(TimerBase* timer)
238 { 238 {
239 if (m_contextLostMode == NotLostContext) { 239 if (m_contextLostMode == NotLostContext) {
240 // Canvas was already restored (possibly thanks to a resize), so stop tr ying. 240 // Canvas was already restored (possibly thanks to a resize), so stop tr ying.
241 m_tryRestoreContextEventTimer.stop(); 241 m_tryRestoreContextEventTimer.stop();
242 return; 242 return;
243 } 243 }
244 244
245 DCHECK(m_contextLostMode == RealLostContext); 245 DCHECK(m_contextLostMode == RealLostContext);
246 if (canvas()->hasImageBuffer() && canvas()->buffer()->restoreSurface()) { 246 if (canvas()->hasImageBuffer() && canvas()->buffer()->restoreSurface()) {
247 m_tryRestoreContextEventTimer.stop(); 247 m_tryRestoreContextEventTimer.stop();
248 dispatchContextRestoredEvent(nullptr); 248 dispatchContextRestoredEvent(nullptr);
249 } 249 }
250 250
251 if (++m_tryRestoreContextAttemptCount > MaxTryRestoreContextAttempts) { 251 if (++m_tryRestoreContextAttemptCount > MaxTryRestoreContextAttempts) {
252 // final attempt: allocate a brand new image buffer instead of restoring 252 // final attempt: allocate a brand new image buffer instead of restoring
253 canvas()->discardImageBuffer(); 253 canvas()->discardImageBuffer();
254 m_tryRestoreContextEventTimer.stop(); 254 m_tryRestoreContextEventTimer.stop();
255 if (canvas()->buffer()) 255 if (canvas()->buffer())
256 dispatchContextRestoredEvent(nullptr); 256 dispatchContextRestoredEvent(nullptr);
257 } 257 }
258 } 258 }
259 259
260 void CanvasRenderingContext2D::dispatchContextRestoredEvent(Timer<CanvasRenderin gContext2D>*) 260 void CanvasRenderingContext2D::dispatchContextRestoredEvent(TimerBase*)
261 { 261 {
262 if (m_contextLostMode == NotLostContext) 262 if (m_contextLostMode == NotLostContext)
263 return; 263 return;
264 reset(); 264 reset();
265 m_contextLostMode = NotLostContext; 265 m_contextLostMode = NotLostContext;
266 if (contextLostRestoredEventsEnabled()) { 266 if (contextLostRestoredEventsEnabled()) {
267 Event* event(Event::create(EventTypeNames::contextrestored)); 267 Event* event(Event::create(EventTypeNames::contextrestored));
268 canvas()->dispatchEvent(event); 268 canvas()->dispatchEvent(event);
269 } 269 }
270 } 270 }
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 return true; 1097 return true;
1098 } 1098 }
1099 1099
1100 void CanvasRenderingContext2D::resetUsageTracking() 1100 void CanvasRenderingContext2D::resetUsageTracking()
1101 { 1101 {
1102 UsageCounters newCounters; 1102 UsageCounters newCounters;
1103 m_usageCounters = newCounters; 1103 m_usageCounters = newCounters;
1104 } 1104 }
1105 1105
1106 } // namespace blink 1106 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698