OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 pixel_out[0] = pixel_in[2]; | 82 pixel_out[0] = pixel_in[2]; |
83 pixel_out[1] = pixel_in[1]; | 83 pixel_out[1] = pixel_in[1]; |
84 pixel_out[2] = pixel_in[0]; | 84 pixel_out[2] = pixel_in[0]; |
85 pixel_out[3] = pixel_in[3]; | 85 pixel_out[3] = pixel_in[3]; |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 // Converts ImageData from PP_IMAGEDATAFORMAT_BGRA_PREMUL to | 89 // Converts ImageData from PP_IMAGEDATAFORMAT_BGRA_PREMUL to |
90 // PP_IMAGEDATAFORMAT_RGBA_PREMUL, or reverse. It's assumed that the | 90 // PP_IMAGEDATAFORMAT_RGBA_PREMUL, or reverse. It's assumed that the |
91 // destination image is always mapped (so will have non-NULL data). | 91 // destination image is always mapped (so will have non-NULL data). |
92 void ConvertImageData(PPB_ImageData_Impl* src_image, const SkIRect& src_rect, | 92 void ConvertImageData(scoped_refptr<PPB_ImageData_Impl> src_image, |
93 PPB_ImageData_Impl* dest_image, const SkRect& dest_rect) { | 93 const SkIRect& src_rect, |
| 94 scoped_refptr<PPB_ImageData_Impl> dest_image, |
| 95 const SkRect& dest_rect) { |
94 ImageDataAutoMapper auto_mapper(src_image); | 96 ImageDataAutoMapper auto_mapper(src_image); |
95 | 97 |
96 DCHECK(src_image->format() != dest_image->format()); | 98 DCHECK(src_image->format() != dest_image->format()); |
97 DCHECK(PPB_ImageData_Impl::IsImageDataFormatSupported(src_image->format())); | 99 DCHECK(PPB_ImageData_Impl::IsImageDataFormatSupported(src_image->format())); |
98 DCHECK(PPB_ImageData_Impl::IsImageDataFormatSupported(dest_image->format())); | 100 DCHECK(PPB_ImageData_Impl::IsImageDataFormatSupported(dest_image->format())); |
99 | 101 |
100 const SkBitmap* src_bitmap = src_image->GetMappedBitmap(); | 102 const SkBitmap* src_bitmap = src_image->GetMappedBitmap(); |
101 const SkBitmap* dest_bitmap = dest_image->GetMappedBitmap(); | 103 const SkBitmap* dest_bitmap = dest_image->GetMappedBitmap(); |
102 if (src_rect.width() == src_image->width() && | 104 if (src_rect.width() == src_image->width() && |
103 dest_rect.width() == dest_image->width()) { | 105 dest_rect.width() == dest_image->width()) { |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 } | 552 } |
551 } | 553 } |
552 | 554 |
553 void PPB_Graphics2D_Impl::ViewFlushedPaint() { | 555 void PPB_Graphics2D_Impl::ViewFlushedPaint() { |
554 // Notify any "painted" callback. See |unpainted_flush_callback_| in the | 556 // Notify any "painted" callback. See |unpainted_flush_callback_| in the |
555 // header for more. | 557 // header for more. |
556 if (!painted_flush_callback_.is_null()) | 558 if (!painted_flush_callback_.is_null()) |
557 painted_flush_callback_.Execute(PP_OK); | 559 painted_flush_callback_.Execute(PP_OK); |
558 } | 560 } |
559 | 561 |
560 void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image, | 562 void PPB_Graphics2D_Impl::ExecutePaintImageData( |
561 int x, int y, | 563 scoped_refptr<PPB_ImageData_Impl> image, int x, int y, |
562 const gfx::Rect& src_rect, | 564 const gfx::Rect& src_rect, gfx::Rect* invalidated_rect) { |
563 gfx::Rect* invalidated_rect) { | |
564 // Ensure the source image is mapped to read from it. | 565 // Ensure the source image is mapped to read from it. |
565 ImageDataAutoMapper auto_mapper(image); | 566 ImageDataAutoMapper auto_mapper(image); |
566 if (!auto_mapper.is_valid()) | 567 if (!auto_mapper.is_valid()) |
567 return; | 568 return; |
568 | 569 |
569 // Portion within the source image to cut out. | 570 // Portion within the source image to cut out. |
570 SkIRect src_irect = { src_rect.x(), src_rect.y(), | 571 SkIRect src_irect = { src_rect.x(), src_rect.y(), |
571 src_rect.right(), src_rect.bottom() }; | 572 src_rect.right(), src_rect.bottom() }; |
572 | 573 |
573 // Location within the backing store to copy to. | 574 // Location within the backing store to copy to. |
574 *invalidated_rect = src_rect; | 575 *invalidated_rect = src_rect; |
575 invalidated_rect->Offset(x, y); | 576 invalidated_rect->Offset(x, y); |
576 SkRect dest_rect = { SkIntToScalar(invalidated_rect->x()), | 577 SkRect dest_rect = { SkIntToScalar(invalidated_rect->x()), |
577 SkIntToScalar(invalidated_rect->y()), | 578 SkIntToScalar(invalidated_rect->y()), |
578 SkIntToScalar(invalidated_rect->right()), | 579 SkIntToScalar(invalidated_rect->right()), |
579 SkIntToScalar(invalidated_rect->bottom()) }; | 580 SkIntToScalar(invalidated_rect->bottom()) }; |
580 | 581 |
581 if (image->format() != image_data_->format()) { | 582 if (image->format() != image_data_->format()) { |
582 // Convert the image data if the format does not match. | 583 // Convert the image data if the format does not match. |
583 ConvertImageData(image, src_irect, image_data_, dest_rect); | 584 ConvertImageData(image, src_irect, image_data_.get(), dest_rect); |
584 } else { | 585 } else { |
585 // We're guaranteed to have a mapped canvas since we mapped it in Init(). | 586 // We're guaranteed to have a mapped canvas since we mapped it in Init(). |
586 skia::PlatformCanvas* backing_canvas = image_data_->GetPlatformCanvas(); | 587 skia::PlatformCanvas* backing_canvas = image_data_->GetPlatformCanvas(); |
587 | 588 |
588 // We want to replace the contents of the bitmap rather than blend. | 589 // We want to replace the contents of the bitmap rather than blend. |
589 SkPaint paint; | 590 SkPaint paint; |
590 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 591 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
591 backing_canvas->drawBitmapRect(*image->GetMappedBitmap(), | 592 backing_canvas->drawBitmapRect(*image->GetMappedBitmap(), |
592 &src_irect, dest_rect, &paint); | 593 &src_irect, dest_rect, &paint); |
593 } | 594 } |
594 } | 595 } |
595 | 596 |
596 void PPB_Graphics2D_Impl::ExecuteScroll(const gfx::Rect& clip, | 597 void PPB_Graphics2D_Impl::ExecuteScroll(const gfx::Rect& clip, |
597 int dx, int dy, | 598 int dx, int dy, |
598 gfx::Rect* invalidated_rect) { | 599 gfx::Rect* invalidated_rect) { |
599 gfx::ScrollCanvas(image_data_->GetPlatformCanvas(), | 600 gfx::ScrollCanvas(image_data_->GetPlatformCanvas(), |
600 clip, gfx::Point(dx, dy)); | 601 clip, gfx::Point(dx, dy)); |
601 *invalidated_rect = clip; | 602 *invalidated_rect = clip; |
602 } | 603 } |
603 | 604 |
604 void PPB_Graphics2D_Impl::ExecuteReplaceContents(PPB_ImageData_Impl* image, | 605 void PPB_Graphics2D_Impl::ExecuteReplaceContents( |
605 gfx::Rect* invalidated_rect) { | 606 scoped_refptr<PPB_ImageData_Impl> image, gfx::Rect* invalidated_rect) { |
606 if (image->format() != image_data_->format()) { | 607 if (image->format() != image_data_->format()) { |
607 DCHECK(image->width() == image_data_->width() && | 608 DCHECK(image->width() == image_data_->width() && |
608 image->height() == image_data_->height()); | 609 image->height() == image_data_->height()); |
609 // Convert the image data if the format does not match. | 610 // Convert the image data if the format does not match. |
610 SkIRect src_irect = { 0, 0, image->width(), image->height() }; | 611 SkIRect src_irect = { 0, 0, image->width(), image->height() }; |
611 SkRect dest_rect = { SkIntToScalar(0), | 612 SkRect dest_rect = { SkIntToScalar(0), |
612 SkIntToScalar(0), | 613 SkIntToScalar(0), |
613 SkIntToScalar(image_data_->width()), | 614 SkIntToScalar(image_data_->width()), |
614 SkIntToScalar(image_data_->height()) }; | 615 SkIntToScalar(image_data_->height()) }; |
615 ConvertImageData(image, src_irect, image_data_, dest_rect); | 616 ConvertImageData(image, src_irect, image_data_.get(), dest_rect); |
616 } else { | 617 } else { |
617 // The passed-in image may not be mapped in our process, and we need to | 618 // The passed-in image may not be mapped in our process, and we need to |
618 // guarantee that the current backing store is always mapped. | 619 // guarantee that the current backing store is always mapped. |
619 if (!image->Map()) | 620 if (!image->Map()) |
620 return; | 621 return; |
621 image_data_->Unmap(); | 622 image_data_->Unmap(); |
622 image_data_->Swap(image); | 623 image_data_->Swap(image); |
623 } | 624 } |
624 *invalidated_rect = gfx::Rect(0, 0, | 625 *invalidated_rect = gfx::Rect(0, 0, |
625 image_data_->width(), image_data_->height()); | 626 image_data_->width(), image_data_->height()); |
(...skipping 21 matching lines...) Expand all Loading... |
647 } | 648 } |
648 | 649 |
649 bool PPB_Graphics2D_Impl::HasPendingFlush() const { | 650 bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
650 return !unpainted_flush_callback_.is_null() || | 651 return !unpainted_flush_callback_.is_null() || |
651 !painted_flush_callback_.is_null() || | 652 !painted_flush_callback_.is_null() || |
652 offscreen_flush_pending_; | 653 offscreen_flush_pending_; |
653 } | 654 } |
654 | 655 |
655 } // namespace ppapi | 656 } // namespace ppapi |
656 } // namespace webkit | 657 } // namespace webkit |
OLD | NEW |