Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 // For querying PaintLayer::compositingState() | 297 // For querying PaintLayer::compositingState() |
| 298 // FIXME: is this invalidation using the correct compositing state? | 298 // FIXME: is this invalidation using the correct compositing state? |
| 299 DisableCompositingQueryAsserts disabler; | 299 DisableCompositingQueryAsserts disabler; |
| 300 ro->invalidatePaintRectangle(mappedDirtyRect); | 300 ro->invalidatePaintRectangle(mappedDirtyRect); |
| 301 } | 301 } |
| 302 m_dirtyRect = FloatRect(); | 302 m_dirtyRect = FloatRect(); |
| 303 | 303 |
| 304 m_numFramesSinceLastRenderingModeSwitch++; | 304 m_numFramesSinceLastRenderingModeSwitch++; |
| 305 if (RuntimeEnabledFeatures::enableCanvas2dDynamicRenderingModeSwitchingEnabl ed() | 305 if (RuntimeEnabledFeatures::enableCanvas2dDynamicRenderingModeSwitchingEnabl ed() |
| 306 && !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { | 306 && !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { |
| 307 if (m_context->is2d() && buffer()->isAccelerated() | 307 if (m_context->is2d() && buffer()->isAccelerated() |
|
xidachen
2016/09/13 16:53:03
should we worry about this call site?
| |
| 308 && m_numFramesSinceLastRenderingModeSwitch >= ExpensiveCanvasHeurist icParameters::MinFramesBeforeSwitch | 308 && m_numFramesSinceLastRenderingModeSwitch >= ExpensiveCanvasHeurist icParameters::MinFramesBeforeSwitch |
| 309 && !m_pendingRenderingModeSwitch) { | 309 && !m_pendingRenderingModeSwitch) { |
| 310 if (!m_context->isAccelerationOptimalForCanvasContent()) { | 310 if (!m_context->isAccelerationOptimalForCanvasContent()) { |
| 311 // The switch must be done asynchronously in order to avoid swit ching during the paint invalidation step. | 311 // The switch must be done asynchronously in order to avoid swit ching during the paint invalidation step. |
| 312 Platform::current()->currentThread()->getWebTaskRunner()->postTa sk( | 312 Platform::current()->currentThread()->getWebTaskRunner()->postTa sk( |
| 313 BLINK_FROM_HERE, | 313 BLINK_FROM_HERE, |
| 314 WTF::bind([](WeakPtr<ImageBuffer> buffer) { | 314 WTF::bind([](WeakPtr<ImageBuffer> buffer) { |
| 315 if (buffer) { | 315 if (buffer) { |
| 316 buffer->disableAcceleration(); | 316 buffer->disableAcceleration(); |
| 317 } | 317 } |
| 318 }, | 318 }, |
| 319 m_imageBuffer->m_weakPtrFactory.createWeakPtr())); | 319 m_imageBuffer->m_weakPtrFactory.createWeakPtr())); |
| 320 m_numFramesSinceLastRenderingModeSwitch = 0; | 320 m_numFramesSinceLastRenderingModeSwitch = 0; |
| 321 m_pendingRenderingModeSwitch = true; | 321 m_pendingRenderingModeSwitch = true; |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 | 325 |
| 326 if (m_pendingRenderingModeSwitch && !buffer()->isAccelerated()) { | 326 if (m_pendingRenderingModeSwitch && !buffer()->isAccelerated()) { |
|
xidachen
2016/09/13 16:53:03
This one as well?
| |
| 327 m_pendingRenderingModeSwitch = false; | 327 m_pendingRenderingModeSwitch = false; |
| 328 } | 328 } |
| 329 | 329 |
| 330 m_context->incrementFrameCount(); | 330 m_context->incrementFrameCount(); |
| 331 } | 331 } |
| 332 | 332 |
| 333 void HTMLCanvasElement::didDisableAcceleration() | 333 void HTMLCanvasElement::didDisableAcceleration() |
| 334 { | 334 { |
| 335 // We must force a paint invalidation on the canvas even if it's | 335 // We must force a paint invalidation on the canvas even if it's |
| 336 // content did not change because it layer was destroyed. | 336 // content did not change because it layer was destroyed. |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 { | 596 { |
| 597 ImageData* imageData; | 597 ImageData* imageData; |
| 598 if (is3D()) { | 598 if (is3D()) { |
| 599 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL(). | 599 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL(). |
| 600 imageData = m_context->paintRenderingResultsToImageData(sourceBuffer); | 600 imageData = m_context->paintRenderingResultsToImageData(sourceBuffer); |
| 601 if (imageData) | 601 if (imageData) |
| 602 return imageData; | 602 return imageData; |
| 603 | 603 |
| 604 m_context->paintRenderingResultsToCanvas(sourceBuffer); | 604 m_context->paintRenderingResultsToCanvas(sourceBuffer); |
| 605 imageData = ImageData::create(m_size); | 605 imageData = ImageData::create(m_size); |
| 606 sk_sp<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAccelerat ion, reason); | 606 if (hasImageBuffer()) { |
| 607 if (snapshot) { | 607 sk_sp<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAccel eration, reason); |
| 608 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8 888_SkColorType, kUnpremul_SkAlphaType); | 608 if (snapshot) { |
| 609 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo .minRowBytes(), 0, 0); | 609 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRG BA_8888_SkColorType, kUnpremul_SkAlphaType); |
| 610 snapshot->readPixels(imageInfo, imageData->data()->data(), image Info.minRowBytes(), 0, 0); | |
| 611 } | |
| 610 } | 612 } |
| 611 return imageData; | 613 return imageData; |
| 612 } | 614 } |
| 613 | 615 |
| 614 imageData = ImageData::create(m_size); | 616 imageData = ImageData::create(m_size); |
| 615 | 617 |
| 616 if (!m_context) | 618 if (!m_context) |
| 617 return imageData; | 619 return imageData; |
| 618 | 620 |
| 619 DCHECK(m_context->is2d()); | 621 DCHECK(m_context->is2d()); |
| 620 sk_sp<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAcceleration, reason); | 622 if (hasImageBuffer()) { |
| 621 if (snapshot) { | 623 sk_sp<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAccelerat ion, reason); |
| 622 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_ SkColorType, kUnpremul_SkAlphaType); | 624 if (snapshot) { |
| 623 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo.min RowBytes(), 0, 0); | 625 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8 888_SkColorType, kUnpremul_SkAlphaType); |
| 626 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo .minRowBytes(), 0, 0); | |
| 627 } | |
| 624 } | 628 } |
| 625 | 629 |
| 626 return imageData; | 630 return imageData; |
| 627 } | 631 } |
| 628 | 632 |
| 629 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double & quality, SourceDrawingBuffer sourceBuffer) const | 633 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double & quality, SourceDrawingBuffer sourceBuffer) const |
| 630 { | 634 { |
| 631 if (!isPaintable()) | 635 if (!isPaintable()) |
| 632 return String("data:,"); | 636 return String("data:,"); |
| 633 | 637 |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1252 | 1256 |
| 1253 bool HTMLCanvasElement::createSurfaceLayer() | 1257 bool HTMLCanvasElement::createSurfaceLayer() |
| 1254 { | 1258 { |
| 1255 DCHECK(!m_surfaceLayerBridge); | 1259 DCHECK(!m_surfaceLayerBridge); |
| 1256 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl()); | 1260 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl()); |
| 1257 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient))); | 1261 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient))); |
| 1258 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( )); | 1262 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( )); |
| 1259 } | 1263 } |
| 1260 | 1264 |
| 1261 } // namespace blink | 1265 } // namespace blink |
| OLD | NEW |