OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 new PPB_Graphics2D_Impl(instance)); | 177 new PPB_Graphics2D_Impl(instance)); |
178 if (!graphics_2d->Init(size.width, size.height, | 178 if (!graphics_2d->Init(size.width, size.height, |
179 PPBoolToBool(is_always_opaque))) { | 179 PPBoolToBool(is_always_opaque))) { |
180 return 0; | 180 return 0; |
181 } | 181 } |
182 return graphics_2d->GetReference(); | 182 return graphics_2d->GetReference(); |
183 } | 183 } |
184 | 184 |
185 bool PPB_Graphics2D_Impl::Init(int width, int height, bool is_always_opaque) { | 185 bool PPB_Graphics2D_Impl::Init(int width, int height, bool is_always_opaque) { |
186 // The underlying PPB_ImageData_Impl will validate the dimensions. | 186 // The underlying PPB_ImageData_Impl will validate the dimensions. |
187 image_data_ = new PPB_ImageData_Impl(pp_instance()); | 187 image_data_ = new PPB_ImageData_Impl(pp_instance(), |
| 188 PPB_ImageData_Impl::PLATFORM); |
188 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), | 189 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), |
189 width, height, true) || | 190 width, height, true) || |
190 !image_data_->Map()) { | 191 !image_data_->Map()) { |
191 image_data_ = NULL; | 192 image_data_ = NULL; |
192 return false; | 193 return false; |
193 } | 194 } |
194 is_always_opaque_ = is_always_opaque; | 195 is_always_opaque_ = is_always_opaque; |
195 scale_ = 1.0f; | 196 scale_ = 1.0f; |
196 return true; | 197 return true; |
197 } | 198 } |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 y + image_resource->height() }; | 427 y + image_resource->height() }; |
427 SkRect dest_rect = { SkIntToScalar(0), | 428 SkRect dest_rect = { SkIntToScalar(0), |
428 SkIntToScalar(0), | 429 SkIntToScalar(0), |
429 SkIntToScalar(image_resource->width()), | 430 SkIntToScalar(image_resource->width()), |
430 SkIntToScalar(image_resource->height()) }; | 431 SkIntToScalar(image_resource->height()) }; |
431 | 432 |
432 if (image_resource->format() != image_data_->format()) { | 433 if (image_resource->format() != image_data_->format()) { |
433 // Convert the image data if the format does not match. | 434 // Convert the image data if the format does not match. |
434 ConvertImageData(image_data_, src_irect, image_resource, dest_rect); | 435 ConvertImageData(image_data_, src_irect, image_resource, dest_rect); |
435 } else { | 436 } else { |
436 skia::PlatformCanvas* dest_canvas = image_resource->GetPlatformCanvas(); | 437 SkCanvas* dest_canvas = image_resource->GetCanvas(); |
437 | 438 |
438 // We want to replace the contents of the bitmap rather than blend. | 439 // We want to replace the contents of the bitmap rather than blend. |
439 SkPaint paint; | 440 SkPaint paint; |
440 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 441 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
441 dest_canvas->drawBitmapRect(*image_data_->GetMappedBitmap(), | 442 dest_canvas->drawBitmapRect(*image_data_->GetMappedBitmap(), |
442 &src_irect, dest_rect, &paint); | 443 &src_irect, dest_rect, &paint); |
443 } | 444 } |
444 return true; | 445 return true; |
445 } | 446 } |
446 | 447 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 SkRect dest_rect = { SkIntToScalar(invalidated_rect->x()), | 630 SkRect dest_rect = { SkIntToScalar(invalidated_rect->x()), |
630 SkIntToScalar(invalidated_rect->y()), | 631 SkIntToScalar(invalidated_rect->y()), |
631 SkIntToScalar(invalidated_rect->right()), | 632 SkIntToScalar(invalidated_rect->right()), |
632 SkIntToScalar(invalidated_rect->bottom()) }; | 633 SkIntToScalar(invalidated_rect->bottom()) }; |
633 | 634 |
634 if (image->format() != image_data_->format()) { | 635 if (image->format() != image_data_->format()) { |
635 // Convert the image data if the format does not match. | 636 // Convert the image data if the format does not match. |
636 ConvertImageData(image, src_irect, image_data_, dest_rect); | 637 ConvertImageData(image, src_irect, image_data_, dest_rect); |
637 } else { | 638 } else { |
638 // We're guaranteed to have a mapped canvas since we mapped it in Init(). | 639 // We're guaranteed to have a mapped canvas since we mapped it in Init(). |
639 skia::PlatformCanvas* backing_canvas = image_data_->GetPlatformCanvas(); | 640 SkCanvas* backing_canvas = image_data_->GetCanvas(); |
640 | 641 |
641 // We want to replace the contents of the bitmap rather than blend. | 642 // We want to replace the contents of the bitmap rather than blend. |
642 SkPaint paint; | 643 SkPaint paint; |
643 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 644 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
644 backing_canvas->drawBitmapRect(*image->GetMappedBitmap(), | 645 backing_canvas->drawBitmapRect(*image->GetMappedBitmap(), |
645 &src_irect, dest_rect, &paint); | 646 &src_irect, dest_rect, &paint); |
646 } | 647 } |
647 } | 648 } |
648 | 649 |
649 void PPB_Graphics2D_Impl::ExecuteScroll(const gfx::Rect& clip, | 650 void PPB_Graphics2D_Impl::ExecuteScroll(const gfx::Rect& clip, |
650 int dx, int dy, | 651 int dx, int dy, |
651 gfx::Rect* invalidated_rect) { | 652 gfx::Rect* invalidated_rect) { |
652 gfx::ScrollCanvas(image_data_->GetPlatformCanvas(), | 653 gfx::ScrollCanvas(image_data_->GetCanvas(), |
653 clip, gfx::Point(dx, dy)); | 654 clip, gfx::Point(dx, dy)); |
654 *invalidated_rect = clip; | 655 *invalidated_rect = clip; |
655 } | 656 } |
656 | 657 |
657 void PPB_Graphics2D_Impl::ExecuteReplaceContents(PPB_ImageData_Impl* image, | 658 void PPB_Graphics2D_Impl::ExecuteReplaceContents(PPB_ImageData_Impl* image, |
658 gfx::Rect* invalidated_rect) { | 659 gfx::Rect* invalidated_rect) { |
659 if (image->format() != image_data_->format()) { | 660 if (image->format() != image_data_->format()) { |
660 DCHECK(image->width() == image_data_->width() && | 661 DCHECK(image->width() == image_data_->width() && |
661 image->height() == image_data_->height()); | 662 image->height() == image_data_->height()); |
662 // Convert the image data if the format does not match. | 663 // Convert the image data if the format does not match. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 } | 701 } |
701 | 702 |
702 bool PPB_Graphics2D_Impl::HasPendingFlush() const { | 703 bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
703 return !unpainted_flush_callback_.is_null() || | 704 return !unpainted_flush_callback_.is_null() || |
704 !painted_flush_callback_.is_null() || | 705 !painted_flush_callback_.is_null() || |
705 offscreen_flush_pending_; | 706 offscreen_flush_pending_; |
706 } | 707 } |
707 | 708 |
708 } // namespace ppapi | 709 } // namespace ppapi |
709 } // namespace webkit | 710 } // namespace webkit |
OLD | NEW |