| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 // Valid when type == REPLACE. | 153 // Valid when type == REPLACE. |
| 154 scoped_refptr<PPB_ImageData_Impl> replace_image; | 154 scoped_refptr<PPB_ImageData_Impl> replace_image; |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 PPB_Graphics2D_Impl::PPB_Graphics2D_Impl(PP_Instance instance) | 157 PPB_Graphics2D_Impl::PPB_Graphics2D_Impl(PP_Instance instance) |
| 158 : Resource(::ppapi::OBJECT_IS_IMPL, instance), | 158 : Resource(::ppapi::OBJECT_IS_IMPL, instance), |
| 159 bound_instance_(NULL), | 159 bound_instance_(NULL), |
| 160 offscreen_flush_pending_(false), | 160 offscreen_flush_pending_(false), |
| 161 is_always_opaque_(false), | 161 is_always_opaque_(false), |
| 162 scale_(1.0f), |
| 162 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 163 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 163 } | 164 } |
| 164 | 165 |
| 165 PPB_Graphics2D_Impl::~PPB_Graphics2D_Impl() { | 166 PPB_Graphics2D_Impl::~PPB_Graphics2D_Impl() { |
| 166 // LastPluginRefWasDeleted should have aborted all pending callbacks. | 167 // LastPluginRefWasDeleted should have aborted all pending callbacks. |
| 167 DCHECK(painted_flush_callback_.is_null()); | 168 DCHECK(painted_flush_callback_.is_null()); |
| 168 DCHECK(unpainted_flush_callback_.is_null()); | 169 DCHECK(unpainted_flush_callback_.is_null()); |
| 169 } | 170 } |
| 170 | 171 |
| 171 // static | 172 // static |
| (...skipping 12 matching lines...) Expand all Loading... |
| 184 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) { |
| 185 // The underlying PPB_ImageData_Impl will validate the dimensions. | 186 // The underlying PPB_ImageData_Impl will validate the dimensions. |
| 186 image_data_ = new PPB_ImageData_Impl(pp_instance()); | 187 image_data_ = new PPB_ImageData_Impl(pp_instance()); |
| 187 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), | 188 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), |
| 188 width, height, true) || | 189 width, height, true) || |
| 189 !image_data_->Map()) { | 190 !image_data_->Map()) { |
| 190 image_data_ = NULL; | 191 image_data_ = NULL; |
| 191 return false; | 192 return false; |
| 192 } | 193 } |
| 193 is_always_opaque_ = is_always_opaque; | 194 is_always_opaque_ = is_always_opaque; |
| 195 scale_ = 1.0f; |
| 194 return true; | 196 return true; |
| 195 } | 197 } |
| 196 | 198 |
| 197 ::ppapi::thunk::PPB_Graphics2D_API* | 199 ::ppapi::thunk::PPB_Graphics2D_API* |
| 198 PPB_Graphics2D_Impl::AsPPB_Graphics2D_API() { | 200 PPB_Graphics2D_Impl::AsPPB_Graphics2D_API() { |
| 199 return this; | 201 return this; |
| 200 } | 202 } |
| 201 | 203 |
| 202 void PPB_Graphics2D_Impl::LastPluginRefWasDeleted() { | 204 void PPB_Graphics2D_Impl::LastPluginRefWasDeleted() { |
| 203 Resource::LastPluginRefWasDeleted(); | 205 Resource::LastPluginRefWasDeleted(); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 // execute in the next round of the message loop. | 378 // execute in the next round of the message loop. |
| 377 ScheduleOffscreenCallback(FlushCallbackData( | 379 ScheduleOffscreenCallback(FlushCallbackData( |
| 378 scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback)))); | 380 scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback)))); |
| 379 } else { | 381 } else { |
| 380 unpainted_flush_callback_.Set( | 382 unpainted_flush_callback_.Set( |
| 381 scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback))); | 383 scoped_refptr<TrackedCallback>(new TrackedCallback(this, callback))); |
| 382 } | 384 } |
| 383 return PP_OK_COMPLETIONPENDING; | 385 return PP_OK_COMPLETIONPENDING; |
| 384 } | 386 } |
| 385 | 387 |
| 388 bool PPB_Graphics2D_Impl::SetScale(float scale) { |
| 389 if (scale > 0.0f) { |
| 390 scale_ = scale; |
| 391 return true; |
| 392 } |
| 393 |
| 394 return false; |
| 395 } |
| 396 |
| 386 bool PPB_Graphics2D_Impl::ReadImageData(PP_Resource image, | 397 bool PPB_Graphics2D_Impl::ReadImageData(PP_Resource image, |
| 387 const PP_Point* top_left) { | 398 const PP_Point* top_left) { |
| 388 // Get and validate the image object to paint into. | 399 // Get and validate the image object to paint into. |
| 389 EnterResourceNoLock<PPB_ImageData_API> enter(image, true); | 400 EnterResourceNoLock<PPB_ImageData_API> enter(image, true); |
| 390 if (enter.failed()) | 401 if (enter.failed()) |
| 391 return false; | 402 return false; |
| 392 PPB_ImageData_Impl* image_resource = | 403 PPB_ImageData_Impl* image_resource = |
| 393 static_cast<PPB_ImageData_Impl*>(enter.object()); | 404 static_cast<PPB_ImageData_Impl*>(enter.object()); |
| 394 if (!PPB_ImageData_Impl::IsImageDataFormatSupported( | 405 if (!PPB_ImageData_Impl::IsImageDataFormatSupported( |
| 395 image_resource->format())) | 406 image_resource->format())) |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 backing_bitmap.copyTo(&image, SkBitmap::kARGB_8888_Config); | 571 backing_bitmap.copyTo(&image, SkBitmap::kARGB_8888_Config); |
| 561 else | 572 else |
| 562 image = backing_bitmap; | 573 image = backing_bitmap; |
| 563 | 574 |
| 564 SkPaint paint; | 575 SkPaint paint; |
| 565 if (is_always_opaque_) { | 576 if (is_always_opaque_) { |
| 566 // When we know the device is opaque, we can disable blending for slightly | 577 // When we know the device is opaque, we can disable blending for slightly |
| 567 // more optimized painting. | 578 // more optimized painting. |
| 568 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 579 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 569 } | 580 } |
| 570 canvas->drawBitmap(image, | 581 |
| 571 SkIntToScalar(plugin_rect.x()), | 582 SkPoint origin; |
| 572 SkIntToScalar(plugin_rect.y()), | 583 origin.set(SkIntToScalar(plugin_rect.x()), SkIntToScalar(plugin_rect.y())); |
| 573 &paint); | 584 if (scale_ != 1.0f && scale_ > 0.0f) { |
| 585 float inverse_scale = 1.0f / scale_; |
| 586 origin.scale(inverse_scale); |
| 587 canvas->scale(scale_, scale_); |
| 588 } |
| 589 canvas->drawBitmap(image, origin.x(), origin.y(), &paint); |
| 574 canvas->restore(); | 590 canvas->restore(); |
| 575 #endif | 591 #endif |
| 576 } | 592 } |
| 577 | 593 |
| 578 void PPB_Graphics2D_Impl::ViewWillInitiatePaint() { | 594 void PPB_Graphics2D_Impl::ViewWillInitiatePaint() { |
| 579 // Move any "unpainted" callback to the painted state. See | 595 // Move any "unpainted" callback to the painted state. See |
| 580 // |unpainted_flush_callback_| in the header for more. | 596 // |unpainted_flush_callback_| in the header for more. |
| 581 if (!unpainted_flush_callback_.is_null()) { | 597 if (!unpainted_flush_callback_.is_null()) { |
| 582 DCHECK(painted_flush_callback_.is_null()); | 598 DCHECK(painted_flush_callback_.is_null()); |
| 583 std::swap(painted_flush_callback_, unpainted_flush_callback_); | 599 std::swap(painted_flush_callback_, unpainted_flush_callback_); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 } | 701 } |
| 686 | 702 |
| 687 bool PPB_Graphics2D_Impl::HasPendingFlush() const { | 703 bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
| 688 return !unpainted_flush_callback_.is_null() || | 704 return !unpainted_flush_callback_.is_null() || |
| 689 !painted_flush_callback_.is_null() || | 705 !painted_flush_callback_.is_null() || |
| 690 offscreen_flush_pending_; | 706 offscreen_flush_pending_; |
| 691 } | 707 } |
| 692 | 708 |
| 693 } // namespace ppapi | 709 } // namespace ppapi |
| 694 } // namespace webkit | 710 } // namespace webkit |
| OLD | NEW |