OLD | NEW |
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 bool Canvas2DLayerBridge::shouldAccelerate(AccelerationHint hint) const | 163 bool Canvas2DLayerBridge::shouldAccelerate(AccelerationHint hint) const |
164 { | 164 { |
165 bool accelerate; | 165 bool accelerate; |
166 if (m_softwareRenderingWhileHidden) | 166 if (m_softwareRenderingWhileHidden) |
167 accelerate = false; | 167 accelerate = false; |
168 else if (m_accelerationMode == ForceAccelerationForTesting) | 168 else if (m_accelerationMode == ForceAccelerationForTesting) |
169 accelerate = true; | 169 accelerate = true; |
170 else if (m_accelerationMode == DisableAcceleration) | 170 else if (m_accelerationMode == DisableAcceleration) |
171 accelerate = false; | 171 accelerate = false; |
172 else | 172 else |
173 accelerate = hint == PreferAcceleration; | 173 accelerate = hint == PreferAcceleration || hint == PreferAccelerationAft
erVisibilityChange; |
174 | 174 |
175 if (accelerate && (!m_contextProvider || m_contextProvider->context3d()->isC
ontextLost())) | 175 if (accelerate && (!m_contextProvider || m_contextProvider->context3d()->isC
ontextLost())) |
176 accelerate = false; | 176 accelerate = false; |
177 return accelerate; | 177 return accelerate; |
178 } | 178 } |
179 | 179 |
180 bool Canvas2DLayerBridge::isAccelerated() const | 180 bool Canvas2DLayerBridge::isAccelerated() const |
181 { | 181 { |
182 if (isHibernating()) | 182 if (isHibernating()) |
183 return false; | 183 return false; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } else { | 244 } else { |
245 m_logger->reportHibernationEvent(HibernationAbortedDueToAllocationFailur
e); | 245 m_logger->reportHibernationEvent(HibernationAbortedDueToAllocationFailur
e); |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint) | 249 SkSurface* Canvas2DLayerBridge::getOrCreateSurface(AccelerationHint hint) |
250 { | 250 { |
251 if (m_surface) | 251 if (m_surface) |
252 return m_surface.get(); | 252 return m_surface.get(); |
253 | 253 |
254 if (m_layer && !isHibernating()) | 254 if (m_layer && !isHibernating() && hint == PreferAcceleration) { |
255 return nullptr; // re-creation will happen through restore() | 255 return nullptr; // re-creation will happen through restore() |
| 256 } |
256 | 257 |
257 bool wantAcceleration = shouldAccelerate(hint); | 258 bool wantAcceleration = shouldAccelerate(hint); |
258 bool surfaceIsAccelerated; | 259 bool surfaceIsAccelerated; |
259 | 260 |
260 if (isHidden() && wantAcceleration) { | 261 if (isHidden() && wantAcceleration) { |
261 wantAcceleration = false; | 262 wantAcceleration = false; |
262 m_softwareRenderingWhileHidden = true; | 263 m_softwareRenderingWhileHidden = true; |
263 } | 264 } |
264 | 265 |
265 m_surface = createSkSurface(wantAcceleration ? m_contextProvider->grContext(
) : nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated); | 266 m_surface = createSkSurface(wantAcceleration ? m_contextProvider->grContext(
) : nullptr, m_size, m_msaaSampleCount, m_opacityMode, &surfaceIsAccelerated); |
(...skipping 16 matching lines...) Expand all Loading... |
282 m_logger->reportHibernationEvent(HibernationEndedWithFallbackToS
W); | 283 m_logger->reportHibernationEvent(HibernationEndedWithFallbackToS
W); |
283 } | 284 } |
284 | 285 |
285 SkPaint copyPaint; | 286 SkPaint copyPaint; |
286 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode); | 287 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
287 m_surface->getCanvas()->drawImage(m_hibernationImage.get(), 0, 0, ©P
aint); | 288 m_surface->getCanvas()->drawImage(m_hibernationImage.get(), 0, 0, ©P
aint); |
288 m_hibernationImage.clear(); | 289 m_hibernationImage.clear(); |
289 | 290 |
290 if (m_imageBuffer) | 291 if (m_imageBuffer) |
291 m_imageBuffer->updateGPUMemoryUsage(); | 292 m_imageBuffer->updateGPUMemoryUsage(); |
| 293 |
| 294 if (m_imageBuffer && !m_isDeferralEnabled) |
| 295 m_imageBuffer->resetCanvas(m_surface->getCanvas()); |
292 } | 296 } |
293 return m_surface.get(); | 297 return m_surface.get(); |
294 } | 298 } |
295 | 299 |
296 SkCanvas* Canvas2DLayerBridge::canvas() | 300 SkCanvas* Canvas2DLayerBridge::canvas() |
297 { | 301 { |
298 if (!m_isDeferralEnabled) { | 302 if (!m_isDeferralEnabled) { |
299 SkSurface* s = getOrCreateSurface(); | 303 SkSurface* s = getOrCreateSurface(); |
300 return s ? s->getCanvas() : nullptr; | 304 return s ? s->getCanvas() : nullptr; |
301 } | 305 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 m_layer->clearTexture(); | 391 m_layer->clearTexture(); |
388 m_logger->reportHibernationEvent(HibernationScheduled); | 392 m_logger->reportHibernationEvent(HibernationScheduled); |
389 Platform::current()->currentThread()->scheduler()->postIdleTask(BLINK_FR
OM_HERE, WTF::bind<double>(&hibernateWrapper, m_weakPtrFactory.createWeakPtr()))
; | 393 Platform::current()->currentThread()->scheduler()->postIdleTask(BLINK_FR
OM_HERE, WTF::bind<double>(&hibernateWrapper, m_weakPtrFactory.createWeakPtr()))
; |
390 } | 394 } |
391 if (!isHidden() && m_softwareRenderingWhileHidden) { | 395 if (!isHidden() && m_softwareRenderingWhileHidden) { |
392 flushRecordingOnly(); | 396 flushRecordingOnly(); |
393 SkPaint copyPaint; | 397 SkPaint copyPaint; |
394 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode); | 398 copyPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
395 RefPtr<SkSurface> oldSurface = m_surface.release(); | 399 RefPtr<SkSurface> oldSurface = m_surface.release(); |
396 m_softwareRenderingWhileHidden = false; | 400 m_softwareRenderingWhileHidden = false; |
397 SkSurface* newSurface = getOrCreateSurface(); | 401 SkSurface* newSurface = getOrCreateSurface(PreferAccelerationAfterVisibi
lityChange); |
398 if (newSurface) { | 402 if (newSurface) { |
399 oldSurface->draw(newSurface->getCanvas(), 0, 0, ©Paint); | 403 oldSurface->draw(newSurface->getCanvas(), 0, 0, ©Paint); |
| 404 if (m_imageBuffer && !m_isDeferralEnabled) { |
| 405 m_imageBuffer->resetCanvas(m_surface->getCanvas()); |
| 406 } |
400 } | 407 } |
401 } | 408 } |
402 if (!isHidden() && isHibernating()) { | 409 if (!isHidden() && isHibernating()) { |
403 getOrCreateSurface(); // Rude awakening | 410 getOrCreateSurface(); // Rude awakening |
404 } | 411 } |
405 } | 412 } |
406 | 413 |
407 bool Canvas2DLayerBridge::writePixels(const SkImageInfo& origInfo, const void* p
ixels, size_t rowBytes, int x, int y) | 414 bool Canvas2DLayerBridge::writePixels(const SkImageInfo& origInfo, const void* p
ixels, size_t rowBytes, int x, int y) |
408 { | 415 { |
409 if (!getOrCreateSurface()) | 416 if (!getOrCreateSurface()) |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 m_image = other.m_image; | 783 m_image = other.m_image; |
777 m_parentLayerBridge = other.m_parentLayerBridge; | 784 m_parentLayerBridge = other.m_parentLayerBridge; |
778 } | 785 } |
779 | 786 |
780 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) | 787 void Canvas2DLayerBridge::Logger::reportHibernationEvent(HibernationEvent event) |
781 { | 788 { |
782 blink::Platform::current()->histogramEnumeration("Canvas.HibernationEvents",
event, HibernationEventCount); | 789 blink::Platform::current()->histogramEnumeration("Canvas.HibernationEvents",
event, HibernationEventCount); |
783 } | 790 } |
784 | 791 |
785 } // namespace blink | 792 } // namespace blink |
OLD | NEW |