| 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 "content/renderer/pepper/pepper_graphics_2d_host.h" | 5 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "build/build_config.h" |
| 13 #include "cc/resources/shared_bitmap.h" | 16 #include "cc/resources/shared_bitmap.h" |
| 14 #include "cc/resources/texture_mailbox.h" | 17 #include "cc/resources/texture_mailbox.h" |
| 15 #include "content/child/child_shared_bitmap_manager.h" | 18 #include "content/child/child_shared_bitmap_manager.h" |
| 16 #include "content/public/renderer/render_thread.h" | 19 #include "content/public/renderer/render_thread.h" |
| 17 #include "content/public/renderer/renderer_ppapi_host.h" | 20 #include "content/public/renderer/renderer_ppapi_host.h" |
| 18 #include "content/renderer/pepper/gfx_conversion.h" | 21 #include "content/renderer/pepper/gfx_conversion.h" |
| 19 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 22 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 20 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" | 23 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" |
| 21 #include "content/renderer/pepper/ppb_image_data_impl.h" | 24 #include "content/renderer/pepper/ppb_image_data_impl.h" |
| 22 #include "content/renderer/render_thread_impl.h" | 25 #include "content/renderer/render_thread_impl.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 44 #include "base/mac/scoped_cftyperef.h" | 47 #include "base/mac/scoped_cftyperef.h" |
| 45 #endif | 48 #endif |
| 46 | 49 |
| 47 using ppapi::thunk::EnterResourceNoLock; | 50 using ppapi::thunk::EnterResourceNoLock; |
| 48 using ppapi::thunk::PPB_ImageData_API; | 51 using ppapi::thunk::PPB_ImageData_API; |
| 49 | 52 |
| 50 namespace content { | 53 namespace content { |
| 51 | 54 |
| 52 namespace { | 55 namespace { |
| 53 | 56 |
| 54 const int64 kOffscreenCallbackDelayMs = 1000 / 30; // 30 fps | 57 const int64_t kOffscreenCallbackDelayMs = 1000 / 30; // 30 fps |
| 55 | 58 |
| 56 // Converts a rect inside an image of the given dimensions. The rect may be | 59 // Converts a rect inside an image of the given dimensions. The rect may be |
| 57 // NULL to indicate it should be the entire image. If the rect is outside of | 60 // NULL to indicate it should be the entire image. If the rect is outside of |
| 58 // the image, this will do nothing and return false. | 61 // the image, this will do nothing and return false. |
| 59 bool ValidateAndConvertRect(const PP_Rect* rect, | 62 bool ValidateAndConvertRect(const PP_Rect* rect, |
| 60 int image_width, | 63 int image_width, |
| 61 int image_height, | 64 int image_height, |
| 62 gfx::Rect* dest) { | 65 gfx::Rect* dest) { |
| 63 if (!rect) { | 66 if (!rect) { |
| 64 // Use the entire image area. | 67 // Use the entire image area. |
| 65 *dest = gfx::Rect(0, 0, image_width, image_height); | 68 *dest = gfx::Rect(0, 0, image_width, image_height); |
| 66 } else { | 69 } else { |
| 67 // Validate the passed-in area. | 70 // Validate the passed-in area. |
| 68 if (rect->point.x < 0 || rect->point.y < 0 || rect->size.width <= 0 || | 71 if (rect->point.x < 0 || rect->point.y < 0 || rect->size.width <= 0 || |
| 69 rect->size.height <= 0) | 72 rect->size.height <= 0) |
| 70 return false; | 73 return false; |
| 71 | 74 |
| 72 // Check the max bounds, being careful of overflow. | 75 // Check the max bounds, being careful of overflow. |
| 73 if (static_cast<int64>(rect->point.x) + | 76 if (static_cast<int64_t>(rect->point.x) + |
| 74 static_cast<int64>(rect->size.width) > | 77 static_cast<int64_t>(rect->size.width) > |
| 75 static_cast<int64>(image_width)) | 78 static_cast<int64_t>(image_width)) |
| 76 return false; | 79 return false; |
| 77 if (static_cast<int64>(rect->point.y) + | 80 if (static_cast<int64_t>(rect->point.y) + |
| 78 static_cast<int64>(rect->size.height) > | 81 static_cast<int64_t>(rect->size.height) > |
| 79 static_cast<int64>(image_height)) | 82 static_cast<int64_t>(image_height)) |
| 80 return false; | 83 return false; |
| 81 | 84 |
| 82 *dest = gfx::Rect( | 85 *dest = gfx::Rect( |
| 83 rect->point.x, rect->point.y, rect->size.width, rect->size.height); | 86 rect->point.x, rect->point.y, rect->size.width, rect->size.height); |
| 84 } | 87 } |
| 85 return true; | 88 return true; |
| 86 } | 89 } |
| 87 | 90 |
| 88 // Converts BGRA <-> RGBA. | 91 // Converts BGRA <-> RGBA. |
| 89 void ConvertBetweenBGRAandRGBA(const uint32_t* input, | 92 void ConvertBetweenBGRAandRGBA(const uint32_t* input, |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 if (enter.failed()) | 251 if (enter.failed()) |
| 249 return false; | 252 return false; |
| 250 PPB_ImageData_Impl* image_resource = | 253 PPB_ImageData_Impl* image_resource = |
| 251 static_cast<PPB_ImageData_Impl*>(enter.object()); | 254 static_cast<PPB_ImageData_Impl*>(enter.object()); |
| 252 if (!PPB_ImageData_Impl::IsImageDataFormatSupported(image_resource->format())) | 255 if (!PPB_ImageData_Impl::IsImageDataFormatSupported(image_resource->format())) |
| 253 return false; // Must be in the right format. | 256 return false; // Must be in the right format. |
| 254 | 257 |
| 255 // Validate the bitmap position. | 258 // Validate the bitmap position. |
| 256 int x = top_left->x; | 259 int x = top_left->x; |
| 257 if (x < 0 || | 260 if (x < 0 || |
| 258 static_cast<int64>(x) + static_cast<int64>(image_resource->width()) > | 261 static_cast<int64_t>(x) + static_cast<int64_t>(image_resource->width()) > |
| 259 image_data_->width()) | 262 image_data_->width()) |
| 260 return false; | 263 return false; |
| 261 int y = top_left->y; | 264 int y = top_left->y; |
| 262 if (y < 0 || | 265 if (y < 0 || |
| 263 static_cast<int64>(y) + static_cast<int64>(image_resource->height()) > | 266 static_cast<int64_t>(y) + static_cast<int64_t>(image_resource->height()) > |
| 264 image_data_->height()) | 267 image_data_->height()) |
| 265 return false; | 268 return false; |
| 266 | 269 |
| 267 ImageDataAutoMapper auto_mapper(image_resource); | 270 ImageDataAutoMapper auto_mapper(image_resource); |
| 268 if (!auto_mapper.is_valid()) | 271 if (!auto_mapper.is_valid()) |
| 269 return false; | 272 return false; |
| 270 | 273 |
| 271 SkIRect src_irect = {x, y, x + image_resource->width(), | 274 SkIRect src_irect = {x, y, x + image_resource->width(), |
| 272 y + image_resource->height()}; | 275 y + image_resource->height()}; |
| 273 SkRect dest_rect = {SkIntToScalar(0), SkIntToScalar(0), | 276 SkRect dest_rect = {SkIntToScalar(0), SkIntToScalar(0), |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 QueuedOperation operation(QueuedOperation::PAINT); | 426 QueuedOperation operation(QueuedOperation::PAINT); |
| 424 operation.paint_image = image_resource; | 427 operation.paint_image = image_resource; |
| 425 if (!ValidateAndConvertRect(src_rect_specified ? &src_rect : NULL, | 428 if (!ValidateAndConvertRect(src_rect_specified ? &src_rect : NULL, |
| 426 image_resource->width(), | 429 image_resource->width(), |
| 427 image_resource->height(), | 430 image_resource->height(), |
| 428 &operation.paint_src_rect)) | 431 &operation.paint_src_rect)) |
| 429 return PP_ERROR_BADARGUMENT; | 432 return PP_ERROR_BADARGUMENT; |
| 430 | 433 |
| 431 // Validate the bitmap position using the previously-validated rect, there | 434 // Validate the bitmap position using the previously-validated rect, there |
| 432 // should be no painted area outside of the image. | 435 // should be no painted area outside of the image. |
| 433 int64 x64 = static_cast<int64>(top_left.x); | 436 int64_t x64 = static_cast<int64_t>(top_left.x); |
| 434 int64 y64 = static_cast<int64>(top_left.y); | 437 int64_t y64 = static_cast<int64_t>(top_left.y); |
| 435 if (x64 + static_cast<int64>(operation.paint_src_rect.x()) < 0 || | 438 if (x64 + static_cast<int64_t>(operation.paint_src_rect.x()) < 0 || |
| 436 x64 + static_cast<int64>(operation.paint_src_rect.right()) > | 439 x64 + static_cast<int64_t>(operation.paint_src_rect.right()) > |
| 437 image_data_->width()) | 440 image_data_->width()) |
| 438 return PP_ERROR_BADARGUMENT; | 441 return PP_ERROR_BADARGUMENT; |
| 439 if (y64 + static_cast<int64>(operation.paint_src_rect.y()) < 0 || | 442 if (y64 + static_cast<int64_t>(operation.paint_src_rect.y()) < 0 || |
| 440 y64 + static_cast<int64>(operation.paint_src_rect.bottom()) > | 443 y64 + static_cast<int64_t>(operation.paint_src_rect.bottom()) > |
| 441 image_data_->height()) | 444 image_data_->height()) |
| 442 return PP_ERROR_BADARGUMENT; | 445 return PP_ERROR_BADARGUMENT; |
| 443 operation.paint_x = top_left.x; | 446 operation.paint_x = top_left.x; |
| 444 operation.paint_y = top_left.y; | 447 operation.paint_y = top_left.y; |
| 445 | 448 |
| 446 queued_operations_.push_back(operation); | 449 queued_operations_.push_back(operation); |
| 447 return PP_OK; | 450 return PP_OK; |
| 448 } | 451 } |
| 449 | 452 |
| 450 int32_t PepperGraphics2DHost::OnHostMsgScroll( | 453 int32_t PepperGraphics2DHost::OnHostMsgScroll( |
| 451 ppapi::host::HostMessageContext* context, | 454 ppapi::host::HostMessageContext* context, |
| 452 bool clip_specified, | 455 bool clip_specified, |
| 453 const PP_Rect& clip, | 456 const PP_Rect& clip, |
| 454 const PP_Point& amount) { | 457 const PP_Point& amount) { |
| 455 QueuedOperation operation(QueuedOperation::SCROLL); | 458 QueuedOperation operation(QueuedOperation::SCROLL); |
| 456 if (!ValidateAndConvertRect(clip_specified ? &clip : NULL, | 459 if (!ValidateAndConvertRect(clip_specified ? &clip : NULL, |
| 457 image_data_->width(), | 460 image_data_->width(), |
| 458 image_data_->height(), | 461 image_data_->height(), |
| 459 &operation.scroll_clip_rect)) | 462 &operation.scroll_clip_rect)) |
| 460 return PP_ERROR_BADARGUMENT; | 463 return PP_ERROR_BADARGUMENT; |
| 461 | 464 |
| 462 // If we're being asked to scroll by more than the clip rect size, just | 465 // If we're being asked to scroll by more than the clip rect size, just |
| 463 // ignore this scroll command and say it worked. | 466 // ignore this scroll command and say it worked. |
| 464 int32 dx = amount.x; | 467 int32_t dx = amount.x; |
| 465 int32 dy = amount.y; | 468 int32_t dy = amount.y; |
| 466 if (dx <= -image_data_->width() || dx >= image_data_->width() || | 469 if (dx <= -image_data_->width() || dx >= image_data_->width() || |
| 467 dy <= -image_data_->height() || dy >= image_data_->height()) | 470 dy <= -image_data_->height() || dy >= image_data_->height()) |
| 468 return PP_ERROR_BADARGUMENT; | 471 return PP_ERROR_BADARGUMENT; |
| 469 | 472 |
| 470 operation.scroll_dx = dx; | 473 operation.scroll_dx = dx; |
| 471 operation.scroll_dy = dy; | 474 operation.scroll_dy = dy; |
| 472 | 475 |
| 473 queued_operations_.push_back(operation); | 476 queued_operations_.push_back(operation); |
| 474 return PP_OK; | 477 return PP_OK; |
| 475 } | 478 } |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 gfx::Point inverse_scaled_point = | 812 gfx::Point inverse_scaled_point = |
| 810 gfx::ScaleToFlooredPoint(*delta, inverse_scale); | 813 gfx::ScaleToFlooredPoint(*delta, inverse_scale); |
| 811 if (original_delta != inverse_scaled_point) | 814 if (original_delta != inverse_scaled_point) |
| 812 return false; | 815 return false; |
| 813 } | 816 } |
| 814 | 817 |
| 815 return true; | 818 return true; |
| 816 } | 819 } |
| 817 | 820 |
| 818 } // namespace content | 821 } // namespace content |
| OLD | NEW |