| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 if (nothing_visible) { | 373 if (nothing_visible) { |
| 372 // There's nothing visible to invalidate so just schedule the callback to | 374 // There's nothing visible to invalidate so just schedule the callback to |
| 373 // execute in the next round of the message loop. | 375 // execute in the next round of the message loop. |
| 374 ScheduleOffscreenCallback(FlushCallbackData(callback)); | 376 ScheduleOffscreenCallback(FlushCallbackData(callback)); |
| 375 } else { | 377 } else { |
| 376 unpainted_flush_callback_.Set(callback); | 378 unpainted_flush_callback_.Set(callback); |
| 377 } | 379 } |
| 378 return PP_OK_COMPLETIONPENDING; | 380 return PP_OK_COMPLETIONPENDING; |
| 379 } | 381 } |
| 380 | 382 |
| 383 bool PPB_Graphics2D_Impl::SetScale(float scale) { |
| 384 if (scale > 0.0f) { |
| 385 scale_ = scale; |
| 386 return true; |
| 387 } |
| 388 |
| 389 return false; |
| 390 } |
| 391 |
| 392 float PPB_Graphics2D_Impl::GetScale() { |
| 393 return scale_; |
| 394 } |
| 395 |
| 381 bool PPB_Graphics2D_Impl::ReadImageData(PP_Resource image, | 396 bool PPB_Graphics2D_Impl::ReadImageData(PP_Resource image, |
| 382 const PP_Point* top_left) { | 397 const PP_Point* top_left) { |
| 383 // Get and validate the image object to paint into. | 398 // Get and validate the image object to paint into. |
| 384 EnterResourceNoLock<PPB_ImageData_API> enter(image, true); | 399 EnterResourceNoLock<PPB_ImageData_API> enter(image, true); |
| 385 if (enter.failed()) | 400 if (enter.failed()) |
| 386 return false; | 401 return false; |
| 387 PPB_ImageData_Impl* image_resource = | 402 PPB_ImageData_Impl* image_resource = |
| 388 static_cast<PPB_ImageData_Impl*>(enter.object()); | 403 static_cast<PPB_ImageData_Impl*>(enter.object()); |
| 389 if (!PPB_ImageData_Impl::IsImageDataFormatSupported( | 404 if (!PPB_ImageData_Impl::IsImageDataFormatSupported( |
| 390 image_resource->format())) | 405 image_resource->format())) |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 backing_bitmap.copyTo(&image, SkBitmap::kARGB_8888_Config); | 570 backing_bitmap.copyTo(&image, SkBitmap::kARGB_8888_Config); |
| 556 else | 571 else |
| 557 image = backing_bitmap; | 572 image = backing_bitmap; |
| 558 | 573 |
| 559 SkPaint paint; | 574 SkPaint paint; |
| 560 if (is_always_opaque_) { | 575 if (is_always_opaque_) { |
| 561 // When we know the device is opaque, we can disable blending for slightly | 576 // When we know the device is opaque, we can disable blending for slightly |
| 562 // more optimized painting. | 577 // more optimized painting. |
| 563 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 578 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 564 } | 579 } |
| 565 canvas->drawBitmap(image, | 580 |
| 566 SkIntToScalar(plugin_rect.x()), | 581 SkPoint origin; |
| 567 SkIntToScalar(plugin_rect.y()), | 582 origin.set(SkIntToScalar(plugin_rect.x()), SkIntToScalar(plugin_rect.y())); |
| 568 &paint); | 583 if (scale_ != 1.0f && scale_ > 0.0f) { |
| 584 float inverse_scale = 1.0f / scale_; |
| 585 origin.scale(inverse_scale); |
| 586 canvas->scale(scale_, scale_); |
| 587 } |
| 588 canvas->drawBitmap(image, origin.x(), origin.y(), &paint); |
| 569 canvas->restore(); | 589 canvas->restore(); |
| 570 #endif | 590 #endif |
| 571 } | 591 } |
| 572 | 592 |
| 573 void PPB_Graphics2D_Impl::ViewWillInitiatePaint() { | 593 void PPB_Graphics2D_Impl::ViewWillInitiatePaint() { |
| 574 // Move any "unpainted" callback to the painted state. See | 594 // Move any "unpainted" callback to the painted state. See |
| 575 // |unpainted_flush_callback_| in the header for more. | 595 // |unpainted_flush_callback_| in the header for more. |
| 576 if (!unpainted_flush_callback_.is_null()) { | 596 if (!unpainted_flush_callback_.is_null()) { |
| 577 DCHECK(painted_flush_callback_.is_null()); | 597 DCHECK(painted_flush_callback_.is_null()); |
| 578 std::swap(painted_flush_callback_, unpainted_flush_callback_); | 598 std::swap(painted_flush_callback_, unpainted_flush_callback_); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 } | 700 } |
| 681 | 701 |
| 682 bool PPB_Graphics2D_Impl::HasPendingFlush() const { | 702 bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
| 683 return !unpainted_flush_callback_.is_null() || | 703 return !unpainted_flush_callback_.is_null() || |
| 684 !painted_flush_callback_.is_null() || | 704 !painted_flush_callback_.is_null() || |
| 685 offscreen_flush_pending_; | 705 offscreen_flush_pending_; |
| 686 } | 706 } |
| 687 | 707 |
| 688 } // namespace ppapi | 708 } // namespace ppapi |
| 689 } // namespace webkit | 709 } // namespace webkit |
| OLD | NEW |