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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 DidDraw(); | 288 DidDraw(); |
289 } | 289 } |
290 | 290 |
291 SetNeedsCompositingUpdate(); | 291 SetNeedsCompositingUpdate(); |
292 | 292 |
293 return context_.Get(); | 293 return context_.Get(); |
294 } | 294 } |
295 | 295 |
296 bool HTMLCanvasElement::ShouldBeDirectComposited() const { | 296 bool HTMLCanvasElement::ShouldBeDirectComposited() const { |
297 return (context_ && context_->IsComposited()) || | 297 return (context_ && context_->IsComposited()) || |
298 (HasImageBuffer() && Buffer()->IsExpensiveToPaint()) || | 298 (HasImageBuffer() && GetImageBuffer()->IsExpensiveToPaint()) || |
299 (!!surface_layer_bridge_); | 299 (!!surface_layer_bridge_); |
300 } | 300 } |
301 | 301 |
302 bool HTMLCanvasElement::IsPaintable() const { | 302 bool HTMLCanvasElement::IsPaintable() const { |
303 return (context_ && context_->IsPaintable()) || | 303 return (context_ && context_->IsPaintable()) || |
304 ImageBuffer::CanCreateImageBuffer(Size()); | 304 ImageBuffer::CanCreateImageBuffer(Size()); |
305 } | 305 } |
306 | 306 |
307 bool HTMLCanvasElement::IsAccelerated() const { | 307 bool HTMLCanvasElement::IsAccelerated() const { |
308 return context_ && context_->IsAccelerated(); | 308 return context_ && context_->IsAccelerated(); |
309 } | 309 } |
310 | 310 |
311 void HTMLCanvasElement::DidDraw(const FloatRect& rect) { | 311 void HTMLCanvasElement::DidDraw(const FloatRect& rect) { |
312 if (rect.IsEmpty()) | 312 if (rect.IsEmpty()) |
313 return; | 313 return; |
314 image_buffer_is_clear_ = false; | 314 image_buffer_is_clear_ = false; |
315 ClearCopiedImage(); | 315 ClearCopiedImage(); |
316 if (GetLayoutObject()) | 316 if (GetLayoutObject()) |
317 GetLayoutObject()->SetMayNeedPaintInvalidation(); | 317 GetLayoutObject()->SetMayNeedPaintInvalidation(); |
318 if (Is2d() && context_->ShouldAntialias() && GetPage() && | 318 if (Is2d() && context_->ShouldAntialias() && GetPage() && |
319 GetPage()->DeviceScaleFactorDeprecated() > 1.0f) { | 319 GetPage()->DeviceScaleFactorDeprecated() > 1.0f) { |
320 FloatRect inflated_rect = rect; | 320 FloatRect inflated_rect = rect; |
321 inflated_rect.Inflate(1); | 321 inflated_rect.Inflate(1); |
322 dirty_rect_.Unite(inflated_rect); | 322 dirty_rect_.Unite(inflated_rect); |
323 } else { | 323 } else { |
324 dirty_rect_.Unite(rect); | 324 dirty_rect_.Unite(rect); |
325 } | 325 } |
326 if (Is2d() && HasImageBuffer()) | 326 if (Is2d() && HasImageBuffer()) |
327 Buffer()->DidDraw(rect); | 327 GetImageBuffer()->DidDraw(rect); |
328 } | 328 } |
329 | 329 |
330 void HTMLCanvasElement::DidDraw() { | 330 void HTMLCanvasElement::DidDraw() { |
331 DidDraw(FloatRect(0, 0, Size().Width(), Size().Height())); | 331 DidDraw(FloatRect(0, 0, Size().Width(), Size().Height())); |
332 } | 332 } |
333 | 333 |
334 void HTMLCanvasElement::FinalizeFrame() { | 334 void HTMLCanvasElement::FinalizeFrame() { |
335 if (HasImageBuffer()) | 335 if (HasImageBuffer()) |
336 image_buffer_->FinalizeFrame(); | 336 image_buffer_->FinalizeFrame(); |
337 | 337 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 // FIXME: is this invalidation using the correct compositing state? | 425 // FIXME: is this invalidation using the correct compositing state? |
426 DisableCompositingQueryAsserts disabler; | 426 DisableCompositingQueryAsserts disabler; |
427 ro->InvalidatePaintRectangle(mapped_dirty_rect); | 427 ro->InvalidatePaintRectangle(mapped_dirty_rect); |
428 } | 428 } |
429 dirty_rect_ = FloatRect(); | 429 dirty_rect_ = FloatRect(); |
430 | 430 |
431 num_frames_since_last_rendering_mode_switch_++; | 431 num_frames_since_last_rendering_mode_switch_++; |
432 if (RuntimeEnabledFeatures:: | 432 if (RuntimeEnabledFeatures:: |
433 enableCanvas2dDynamicRenderingModeSwitchingEnabled() && | 433 enableCanvas2dDynamicRenderingModeSwitchingEnabled() && |
434 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { | 434 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { |
435 if (Is2d() && HasImageBuffer() && Buffer()->IsAccelerated() && | 435 if (Is2d() && HasImageBuffer() && GetImageBuffer()->IsAccelerated() && |
436 num_frames_since_last_rendering_mode_switch_ >= | 436 num_frames_since_last_rendering_mode_switch_ >= |
437 ExpensiveCanvasHeuristicParameters::kMinFramesBeforeSwitch && | 437 ExpensiveCanvasHeuristicParameters::kMinFramesBeforeSwitch && |
438 !pending_rendering_mode_switch_) { | 438 !pending_rendering_mode_switch_) { |
439 if (!context_->IsAccelerationOptimalForCanvasContent()) { | 439 if (!context_->IsAccelerationOptimalForCanvasContent()) { |
440 // The switch must be done asynchronously in order to avoid switching | 440 // The switch must be done asynchronously in order to avoid switching |
441 // during the paint invalidation step. | 441 // during the paint invalidation step. |
442 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostTask( | 442 Platform::Current()->CurrentThread()->GetWebTaskRunner()->PostTask( |
443 BLINK_FROM_HERE, | 443 BLINK_FROM_HERE, |
444 WTF::Bind( | 444 WTF::Bind( |
445 [](WeakPtr<ImageBuffer> buffer) { | 445 [](WeakPtr<ImageBuffer> buffer) { |
446 if (buffer) { | 446 if (buffer) { |
447 buffer->DisableAcceleration(); | 447 buffer->DisableAcceleration(); |
448 } | 448 } |
449 }, | 449 }, |
450 image_buffer_->weak_ptr_factory_.CreateWeakPtr())); | 450 image_buffer_->weak_ptr_factory_.CreateWeakPtr())); |
451 num_frames_since_last_rendering_mode_switch_ = 0; | 451 num_frames_since_last_rendering_mode_switch_ = 0; |
452 pending_rendering_mode_switch_ = true; | 452 pending_rendering_mode_switch_ = true; |
453 } | 453 } |
454 } | 454 } |
455 } | 455 } |
456 | 456 |
457 if (pending_rendering_mode_switch_ && Buffer() && | 457 if (pending_rendering_mode_switch_ && GetImageBuffer() && |
458 !Buffer()->IsAccelerated()) { | 458 !GetImageBuffer()->IsAccelerated()) { |
459 pending_rendering_mode_switch_ = false; | 459 pending_rendering_mode_switch_ = false; |
460 } | 460 } |
461 | 461 |
462 DCHECK(dirty_rect_.IsEmpty()); | 462 DCHECK(dirty_rect_.IsEmpty()); |
463 } | 463 } |
464 | 464 |
465 void HTMLCanvasElement::Reset() { | 465 void HTMLCanvasElement::Reset() { |
466 if (ignore_reset_) | 466 if (ignore_reset_) |
467 return; | 467 return; |
468 | 468 |
(...skipping 12 matching lines...) Expand all Loading... | |
481 | 481 |
482 if (Is2d()) | 482 if (Is2d()) |
483 context_->Reset(); | 483 context_->Reset(); |
484 | 484 |
485 IntSize old_size = Size(); | 485 IntSize old_size = Size(); |
486 IntSize new_size(w, h); | 486 IntSize new_size(w, h); |
487 | 487 |
488 // If the size of an existing buffer matches, we can just clear it instead of | 488 // If the size of an existing buffer matches, we can just clear it instead of |
489 // reallocating. This optimization is only done for 2D canvases for now. | 489 // reallocating. This optimization is only done for 2D canvases for now. |
490 if (had_image_buffer && old_size == new_size && Is2d() && | 490 if (had_image_buffer && old_size == new_size && Is2d() && |
491 !Buffer()->IsRecording()) { | 491 !GetImageBuffer()->IsRecording()) { |
492 if (!image_buffer_is_clear_) { | 492 if (!image_buffer_is_clear_) { |
493 image_buffer_is_clear_ = true; | 493 image_buffer_is_clear_ = true; |
494 context_->clearRect(0, 0, width(), height()); | 494 context_->clearRect(0, 0, width(), height()); |
495 } | 495 } |
496 return; | 496 return; |
497 } | 497 } |
498 | 498 |
499 SetSurfaceSize(new_size); | 499 SetSurfaceSize(new_size); |
500 | 500 |
501 if (Is3d() && old_size != Size()) | 501 if (Is3d() && old_size != Size()) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 if (context_->Paint(context, PixelSnappedIntRect(r))) | 594 if (context_->Paint(context, PixelSnappedIntRect(r))) |
595 return; | 595 return; |
596 | 596 |
597 context_->PaintRenderingResultsToCanvas(kFrontBuffer); | 597 context_->PaintRenderingResultsToCanvas(kFrontBuffer); |
598 if (HasImageBuffer()) { | 598 if (HasImageBuffer()) { |
599 if (!context.ContextDisabled()) { | 599 if (!context.ContextDisabled()) { |
600 SkBlendMode composite_operator = | 600 SkBlendMode composite_operator = |
601 !context_ || context_->CreationAttributes().alpha() | 601 !context_ || context_->CreationAttributes().alpha() |
602 ? SkBlendMode::kSrcOver | 602 ? SkBlendMode::kSrcOver |
603 : SkBlendMode::kSrc; | 603 : SkBlendMode::kSrc; |
604 Buffer()->Draw(context, PixelSnappedIntRect(r), 0, composite_operator); | 604 GetImageBuffer()->Draw(context, PixelSnappedIntRect(r), 0, |
605 composite_operator); | |
605 } | 606 } |
606 } else { | 607 } else { |
607 // When alpha is false, we should draw to opaque black. | 608 // When alpha is false, we should draw to opaque black. |
608 if (!context_->CreationAttributes().alpha()) | 609 if (!context_->CreationAttributes().alpha()) |
609 context.FillRect(FloatRect(r), Color(0, 0, 0)); | 610 context.FillRect(FloatRect(r), Color(0, 0, 0)); |
610 } | 611 } |
611 | 612 |
612 if (Is3d() && PaintsIntoCanvasBuffer()) | 613 if (Is3d() && PaintsIntoCanvasBuffer()) |
613 context_->MarkLayerComposited(); | 614 context_->MarkLayerComposited(); |
614 } | 615 } |
(...skipping 20 matching lines...) Expand all Loading... | |
635 } | 636 } |
636 } | 637 } |
637 | 638 |
638 const AtomicString HTMLCanvasElement::ImageSourceURL() const { | 639 const AtomicString HTMLCanvasElement::ImageSourceURL() const { |
639 return AtomicString( | 640 return AtomicString( |
640 ToDataURLInternal(ImageEncoderUtils::kDefaultMimeType, 0, kFrontBuffer)); | 641 ToDataURLInternal(ImageEncoderUtils::kDefaultMimeType, 0, kFrontBuffer)); |
641 } | 642 } |
642 | 643 |
643 void HTMLCanvasElement::PrepareSurfaceForPaintingIfNeeded() const { | 644 void HTMLCanvasElement::PrepareSurfaceForPaintingIfNeeded() const { |
644 DCHECK(Is2d()); // This function is called by the 2d context | 645 DCHECK(Is2d()); // This function is called by the 2d context |
645 if (Buffer()) | 646 if (GetImageBuffer()) |
646 image_buffer_->PrepareSurfaceForPaintingIfNeeded(); | 647 image_buffer_->PrepareSurfaceForPaintingIfNeeded(); |
647 } | 648 } |
648 | 649 |
649 ImageData* HTMLCanvasElement::ToImageData(SourceDrawingBuffer source_buffer, | 650 ImageData* HTMLCanvasElement::ToImageData(SourceDrawingBuffer source_buffer, |
650 SnapshotReason reason) const { | 651 SnapshotReason reason) const { |
651 ImageData* image_data; | 652 ImageData* image_data; |
652 if (Is3d()) { | 653 if (Is3d()) { |
653 // Get non-premultiplied data because of inaccurate premultiplied alpha | 654 // Get non-premultiplied data because of inaccurate premultiplied alpha |
654 // conversion of buffer()->toDataURL(). | 655 // conversion of buffer()->toDataURL(). |
655 image_data = context_->PaintRenderingResultsToImageData(source_buffer); | 656 image_data = context_->PaintRenderingResultsToImageData(source_buffer); |
656 if (image_data) | 657 if (image_data) |
657 return image_data; | 658 return image_data; |
658 | 659 |
659 context_->PaintRenderingResultsToCanvas(source_buffer); | 660 context_->PaintRenderingResultsToCanvas(source_buffer); |
660 image_data = ImageData::Create(size_); | 661 image_data = ImageData::Create(size_); |
661 if (image_data && HasImageBuffer()) { | 662 if (image_data && HasImageBuffer()) { |
662 sk_sp<SkImage> snapshot = | 663 sk_sp<SkImage> snapshot = |
663 Buffer()->NewSkImageSnapshot(kPreferNoAcceleration, reason); | 664 GetImageBuffer()->NewSkImageSnapshot(kPreferNoAcceleration, reason); |
664 if (snapshot) { | 665 if (snapshot) { |
665 SkImageInfo image_info = SkImageInfo::Make( | 666 SkImageInfo image_info = SkImageInfo::Make( |
666 width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType); | 667 width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType); |
667 snapshot->readPixels(image_info, image_data->data()->Data(), | 668 snapshot->readPixels(image_info, image_data->data()->Data(), |
668 image_info.minRowBytes(), 0, 0); | 669 image_info.minRowBytes(), 0, 0); |
669 } | 670 } |
670 } | 671 } |
671 return image_data; | 672 return image_data; |
672 } | 673 } |
673 | 674 |
674 image_data = ImageData::Create(size_); | 675 image_data = ImageData::Create(size_); |
675 | 676 |
676 if ((!context_ || !image_data) && !PlaceholderFrame()) | 677 if ((!context_ || !image_data) && !PlaceholderFrame()) |
677 return image_data; | 678 return image_data; |
678 | 679 |
679 DCHECK(Is2d() || PlaceholderFrame()); | 680 DCHECK(Is2d() || PlaceholderFrame()); |
680 sk_sp<SkImage> snapshot; | 681 sk_sp<SkImage> snapshot; |
681 if (HasImageBuffer()) { | 682 if (HasImageBuffer()) { |
682 snapshot = Buffer()->NewSkImageSnapshot(kPreferNoAcceleration, reason); | 683 snapshot = |
684 GetImageBuffer()->NewSkImageSnapshot(kPreferNoAcceleration, reason); | |
683 } else if (PlaceholderFrame()) { | 685 } else if (PlaceholderFrame()) { |
684 DCHECK(PlaceholderFrame()->OriginClean()); | 686 DCHECK(PlaceholderFrame()->OriginClean()); |
685 snapshot = PlaceholderFrame()->ImageForCurrentFrame(); | 687 snapshot = PlaceholderFrame()->ImageForCurrentFrame(); |
686 } | 688 } |
687 | 689 |
688 if (snapshot) { | 690 if (snapshot) { |
689 SkImageInfo image_info = SkImageInfo::Make( | 691 SkImageInfo image_info = SkImageInfo::Make( |
690 width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType); | 692 width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType); |
691 snapshot->readPixels(image_info, image_data->data()->Data(), | 693 snapshot->readPixels(image_info, image_data->data()->Data(), |
692 image_info.minRowBytes(), 0, 0); | 694 image_info.minRowBytes(), 0, 0); |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1088 std::numeric_limits<intptr_t>::max()); | 1090 std::numeric_limits<intptr_t>::max()); |
1089 | 1091 |
1090 // Subtracting two intptr_t that are known to be positive will never | 1092 // Subtracting two intptr_t that are known to be positive will never |
1091 // underflow. | 1093 // underflow. |
1092 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | 1094 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
1093 externally_allocated_memory - externally_allocated_memory_); | 1095 externally_allocated_memory - externally_allocated_memory_); |
1094 externally_allocated_memory_ = externally_allocated_memory; | 1096 externally_allocated_memory_ = externally_allocated_memory; |
1095 } | 1097 } |
1096 | 1098 |
1097 PaintCanvas* HTMLCanvasElement::DrawingCanvas() const { | 1099 PaintCanvas* HTMLCanvasElement::DrawingCanvas() const { |
1098 return Buffer() ? image_buffer_->Canvas() : nullptr; | 1100 return GetImageBuffer() ? image_buffer_->Canvas() : nullptr; |
1099 } | 1101 } |
1100 | 1102 |
1101 void HTMLCanvasElement::DisableDeferral(DisableDeferralReason reason) const { | 1103 void HTMLCanvasElement::DisableDeferral(DisableDeferralReason reason) const { |
1102 if (Buffer()) | 1104 if (GetImageBuffer()) |
1103 image_buffer_->DisableDeferral(reason); | 1105 image_buffer_->DisableDeferral(reason); |
1104 } | 1106 } |
1105 | 1107 |
1106 PaintCanvas* HTMLCanvasElement::ExistingDrawingCanvas() const { | 1108 PaintCanvas* HTMLCanvasElement::ExistingDrawingCanvas() const { |
1107 if (!HasImageBuffer()) | 1109 if (!HasImageBuffer()) |
1108 return nullptr; | 1110 return nullptr; |
1109 | 1111 |
1110 return image_buffer_->Canvas(); | 1112 return image_buffer_->Canvas(); |
1111 } | 1113 } |
1112 | 1114 |
1113 ImageBuffer* HTMLCanvasElement::Buffer() const { | 1115 ImageBuffer* HTMLCanvasElement::GetImageBuffer() const { |
Justin Novosad
2017/05/01 15:18:57
Nit (existed before this CL): This function does n
fserb
2017/05/02 18:49:30
done
| |
1114 DCHECK(context_); | 1116 DCHECK(context_); |
1115 DCHECK(context_->GetContextType() != | 1117 DCHECK(context_->GetContextType() != |
1116 CanvasRenderingContext::kContextImageBitmap); | 1118 CanvasRenderingContext::kContextImageBitmap); |
1117 if (!HasImageBuffer() && !did_fail_to_create_image_buffer_) | 1119 if (!HasImageBuffer() && !did_fail_to_create_image_buffer_) |
1118 const_cast<HTMLCanvasElement*>(this)->CreateImageBuffer(); | 1120 const_cast<HTMLCanvasElement*>(this)->CreateImageBuffer(); |
1119 return image_buffer_.get(); | 1121 return image_buffer_.get(); |
1120 } | 1122 } |
1121 | 1123 |
1122 void HTMLCanvasElement::CreateImageBufferUsingSurfaceForTesting( | 1124 void HTMLCanvasElement::CreateImageBufferUsingSurfaceForTesting( |
1123 std::unique_ptr<ImageBufferSurface> surface) { | 1125 std::unique_ptr<ImageBufferSurface> surface) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1156 // Special case: transferFromImageBitmap is not yet called. | 1158 // Special case: transferFromImageBitmap is not yet called. |
1157 sk_sp<SkSurface> surface = | 1159 sk_sp<SkSurface> surface = |
1158 SkSurface::MakeRasterN32Premul(width(), height()); | 1160 SkSurface::MakeRasterN32Premul(width(), height()); |
1159 return StaticBitmapImage::Create(surface->makeImageSnapshot()); | 1161 return StaticBitmapImage::Create(surface->makeImageSnapshot()); |
1160 } | 1162 } |
1161 | 1163 |
1162 bool need_to_update = !copied_image_; | 1164 bool need_to_update = !copied_image_; |
1163 // The concept of SourceDrawingBuffer is valid on only WebGL. | 1165 // The concept of SourceDrawingBuffer is valid on only WebGL. |
1164 if (context_->Is3d()) | 1166 if (context_->Is3d()) |
1165 need_to_update |= context_->PaintRenderingResultsToCanvas(source_buffer); | 1167 need_to_update |= context_->PaintRenderingResultsToCanvas(source_buffer); |
1166 if (need_to_update && Buffer()) { | 1168 if (need_to_update && GetImageBuffer()) { |
1167 copied_image_ = Buffer()->NewImageSnapshot(hint, snapshot_reason); | 1169 copied_image_ = GetImageBuffer()->NewImageSnapshot(hint, snapshot_reason); |
1168 UpdateExternallyAllocatedMemory(); | 1170 UpdateExternallyAllocatedMemory(); |
1169 } | 1171 } |
1170 return copied_image_; | 1172 return copied_image_; |
1171 } | 1173 } |
1172 | 1174 |
1173 void HTMLCanvasElement::DiscardImageBuffer() { | 1175 void HTMLCanvasElement::DiscardImageBuffer() { |
1174 image_buffer_.reset(); | 1176 image_buffer_.reset(); |
1175 dirty_rect_ = FloatRect(); | 1177 dirty_rect_ = FloatRect(); |
1176 UpdateExternallyAllocatedMemory(); | 1178 UpdateExternallyAllocatedMemory(); |
1177 } | 1179 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1215 | 1217 |
1216 void HTMLCanvasElement::DidMoveToNewDocument(Document& old_document) { | 1218 void HTMLCanvasElement::DidMoveToNewDocument(Document& old_document) { |
1217 ContextLifecycleObserver::SetContext(&GetDocument()); | 1219 ContextLifecycleObserver::SetContext(&GetDocument()); |
1218 PageVisibilityObserver::SetContext(GetDocument().GetPage()); | 1220 PageVisibilityObserver::SetContext(GetDocument().GetPage()); |
1219 HTMLElement::DidMoveToNewDocument(old_document); | 1221 HTMLElement::DidMoveToNewDocument(old_document); |
1220 } | 1222 } |
1221 | 1223 |
1222 void HTMLCanvasElement::WillDrawImageTo2DContext(CanvasImageSource* source) { | 1224 void HTMLCanvasElement::WillDrawImageTo2DContext(CanvasImageSource* source) { |
1223 if (ExpensiveCanvasHeuristicParameters::kEnableAccelerationToAvoidReadbacks && | 1225 if (ExpensiveCanvasHeuristicParameters::kEnableAccelerationToAvoidReadbacks && |
1224 SharedGpuContext::AllowSoftwareToAcceleratedCanvasUpgrade() && | 1226 SharedGpuContext::AllowSoftwareToAcceleratedCanvasUpgrade() && |
1225 source->IsAccelerated() && !Buffer()->IsAccelerated() && | 1227 source->IsAccelerated() && !GetImageBuffer()->IsAccelerated() && |
1226 ShouldAccelerate(kIgnoreResourceLimitCriteria)) { | 1228 ShouldAccelerate(kIgnoreResourceLimitCriteria)) { |
1227 OpacityMode opacity_mode = | 1229 OpacityMode opacity_mode = |
1228 context_->CreationAttributes().alpha() ? kNonOpaque : kOpaque; | 1230 context_->CreationAttributes().alpha() ? kNonOpaque : kOpaque; |
1229 int msaa_sample_count = 0; | 1231 int msaa_sample_count = 0; |
1230 std::unique_ptr<ImageBufferSurface> surface = | 1232 std::unique_ptr<ImageBufferSurface> surface = |
1231 CreateAcceleratedImageBufferSurface(opacity_mode, &msaa_sample_count); | 1233 CreateAcceleratedImageBufferSurface(opacity_mode, &msaa_sample_count); |
1232 if (surface) { | 1234 if (surface) { |
1233 Buffer()->SetSurface(std::move(surface)); | 1235 GetImageBuffer()->SetSurface(std::move(surface)); |
1234 SetNeedsCompositingUpdate(); | 1236 SetNeedsCompositingUpdate(); |
1235 } | 1237 } |
1236 } | 1238 } |
1237 } | 1239 } |
1238 | 1240 |
1239 PassRefPtr<Image> HTMLCanvasElement::GetSourceImageForCanvas( | 1241 PassRefPtr<Image> HTMLCanvasElement::GetSourceImageForCanvas( |
1240 SourceImageStatus* status, | 1242 SourceImageStatus* status, |
1241 AccelerationHint hint, | 1243 AccelerationHint hint, |
1242 SnapshotReason reason, | 1244 SnapshotReason reason, |
1243 const FloatSize&) const { | 1245 const FloatSize&) const { |
(...skipping 26 matching lines...) Expand all Loading... | |
1270 | 1272 |
1271 sk_sp<SkImage> sk_image; | 1273 sk_sp<SkImage> sk_image; |
1272 // TODO(ccameron): Canvas should produce sRGB images. | 1274 // TODO(ccameron): Canvas should produce sRGB images. |
1273 // https://crbug.com/672299 | 1275 // https://crbug.com/672299 |
1274 if (Is3d()) { | 1276 if (Is3d()) { |
1275 // Because WebGL sources always require making a copy of the back buffer, we | 1277 // Because WebGL sources always require making a copy of the back buffer, we |
1276 // use paintRenderingResultsToCanvas instead of getImage in order to keep a | 1278 // use paintRenderingResultsToCanvas instead of getImage in order to keep a |
1277 // cached copy of the backing in the canvas's ImageBuffer. | 1279 // cached copy of the backing in the canvas's ImageBuffer. |
1278 RenderingContext()->PaintRenderingResultsToCanvas(kBackBuffer); | 1280 RenderingContext()->PaintRenderingResultsToCanvas(kBackBuffer); |
1279 if (HasImageBuffer()) { | 1281 if (HasImageBuffer()) { |
1280 sk_image = Buffer()->NewSkImageSnapshot(hint, reason); | 1282 sk_image = GetImageBuffer()->NewSkImageSnapshot(hint, reason); |
1281 } else { | 1283 } else { |
1282 sk_image = CreateTransparentSkImage(Size()); | 1284 sk_image = CreateTransparentSkImage(Size()); |
1283 } | 1285 } |
1284 } else { | 1286 } else { |
1285 if (ExpensiveCanvasHeuristicParameters:: | 1287 if (ExpensiveCanvasHeuristicParameters:: |
1286 kDisableAccelerationToAvoidReadbacks && | 1288 kDisableAccelerationToAvoidReadbacks && |
1287 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled() && | 1289 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled() && |
1288 hint == kPreferNoAcceleration && HasImageBuffer() && | 1290 hint == kPreferNoAcceleration && HasImageBuffer() && |
1289 Buffer()->IsAccelerated()) { | 1291 GetImageBuffer()->IsAccelerated()) { |
1290 Buffer()->DisableAcceleration(); | 1292 GetImageBuffer()->DisableAcceleration(); |
1291 } | 1293 } |
1292 RefPtr<Image> image = RenderingContext()->GetImage(hint, reason); | 1294 RefPtr<Image> image = RenderingContext()->GetImage(hint, reason); |
1293 if (image) { | 1295 if (image) { |
1294 sk_image = image->ImageForCurrentFrame(); | 1296 sk_image = image->ImageForCurrentFrame(); |
1295 } else { | 1297 } else { |
1296 sk_image = CreateTransparentSkImage(Size()); | 1298 sk_image = CreateTransparentSkImage(Size()); |
1297 } | 1299 } |
1298 } | 1300 } |
1299 | 1301 |
1300 if (sk_image) { | 1302 if (sk_image) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1459 // Creates a placeholder layer first before Surface is created. | 1461 // Creates a placeholder layer first before Surface is created. |
1460 surface_layer_bridge_->CreateSolidColorLayer(); | 1462 surface_layer_bridge_->CreateSolidColorLayer(); |
1461 } | 1463 } |
1462 } | 1464 } |
1463 | 1465 |
1464 void HTMLCanvasElement::OnWebLayerReplaced() { | 1466 void HTMLCanvasElement::OnWebLayerReplaced() { |
1465 SetNeedsCompositingUpdate(); | 1467 SetNeedsCompositingUpdate(); |
1466 } | 1468 } |
1467 | 1469 |
1468 } // namespace blink | 1470 } // namespace blink |
OLD | NEW |