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> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "cc/paint/paint_canvas.h" | |
18 #include "cc/paint/paint_flags.h" | |
17 #include "cc/resources/shared_bitmap.h" | 19 #include "cc/resources/shared_bitmap.h" |
18 #include "cc/resources/texture_mailbox.h" | 20 #include "cc/resources/texture_mailbox.h" |
19 #include "content/child/child_shared_bitmap_manager.h" | 21 #include "content/child/child_shared_bitmap_manager.h" |
20 #include "content/public/renderer/render_thread.h" | 22 #include "content/public/renderer/render_thread.h" |
21 #include "content/public/renderer/renderer_ppapi_host.h" | 23 #include "content/public/renderer/renderer_ppapi_host.h" |
22 #include "content/renderer/pepper/gfx_conversion.h" | 24 #include "content/renderer/pepper/gfx_conversion.h" |
23 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 25 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
24 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" | 26 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" |
25 #include "content/renderer/pepper/ppb_image_data_impl.h" | 27 #include "content/renderer/pepper/ppb_image_data_impl.h" |
26 #include "content/renderer/render_thread_impl.h" | 28 #include "content/renderer/render_thread_impl.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 SkIRect src_irect = {x, y, x + image_resource->width(), | 271 SkIRect src_irect = {x, y, x + image_resource->width(), |
270 y + image_resource->height()}; | 272 y + image_resource->height()}; |
271 SkRect dest_rect = {SkIntToScalar(0), SkIntToScalar(0), | 273 SkRect dest_rect = {SkIntToScalar(0), SkIntToScalar(0), |
272 SkIntToScalar(image_resource->width()), | 274 SkIntToScalar(image_resource->width()), |
273 SkIntToScalar(image_resource->height())}; | 275 SkIntToScalar(image_resource->height())}; |
274 | 276 |
275 if (image_resource->format() != image_data_->format()) { | 277 if (image_resource->format() != image_data_->format()) { |
276 // Convert the image data if the format does not match. | 278 // Convert the image data if the format does not match. |
277 ConvertImageData(image_data_.get(), src_irect, image_resource, dest_rect); | 279 ConvertImageData(image_data_.get(), src_irect, image_resource, dest_rect); |
278 } else { | 280 } else { |
279 SkCanvas* dest_canvas = image_resource->GetCanvas(); | 281 cc::PaintCanvas* dest_canvas = image_resource->GetCanvas(); |
280 | 282 |
281 // We want to replace the contents of the bitmap rather than blend. | 283 // We want to replace the contents of the bitmap rather than blend. |
282 SkPaint paint; | 284 cc::PaintFlags paint; |
283 paint.setBlendMode(SkBlendMode::kSrc); | 285 paint.setBlendMode(SkBlendMode::kSrc); |
284 dest_canvas->drawBitmapRect( | 286 cc::GetSkCanvas(dest_canvas) |
285 image_data_->GetMappedBitmap(), src_irect, dest_rect, &paint); | 287 ->drawBitmapRect(image_data_->GetMappedBitmap(), src_irect, dest_rect, |
288 &paint); | |
286 } | 289 } |
287 return true; | 290 return true; |
288 } | 291 } |
289 | 292 |
290 bool PepperGraphics2DHost::BindToInstance( | 293 bool PepperGraphics2DHost::BindToInstance( |
291 PepperPluginInstanceImpl* new_instance) { | 294 PepperPluginInstanceImpl* new_instance) { |
292 if (new_instance && new_instance->pp_instance() != pp_instance()) | 295 if (new_instance && new_instance->pp_instance() != pp_instance()) |
293 return false; // Can't bind other instance's contexts. | 296 return false; // Can't bind other instance's contexts. |
294 if (bound_instance_ == new_instance) | 297 if (bound_instance_ == new_instance) |
295 return true; // Rebinding the same device, nothing to do. | 298 return true; // Rebinding the same device, nothing to do. |
(...skipping 24 matching lines...) Expand all Loading... | |
320 void PepperGraphics2DHost::Paint(blink::WebCanvas* canvas, | 323 void PepperGraphics2DHost::Paint(blink::WebCanvas* canvas, |
321 const gfx::Rect& plugin_rect, | 324 const gfx::Rect& plugin_rect, |
322 const gfx::Rect& paint_rect) { | 325 const gfx::Rect& paint_rect) { |
323 TRACE_EVENT0("pepper", "PepperGraphics2DHost::Paint"); | 326 TRACE_EVENT0("pepper", "PepperGraphics2DHost::Paint"); |
324 ImageDataAutoMapper auto_mapper(image_data_.get()); | 327 ImageDataAutoMapper auto_mapper(image_data_.get()); |
325 SkBitmap backing_bitmap = image_data_->GetMappedBitmap(); | 328 SkBitmap backing_bitmap = image_data_->GetMappedBitmap(); |
326 | 329 |
327 gfx::Rect invalidate_rect = plugin_rect; | 330 gfx::Rect invalidate_rect = plugin_rect; |
328 invalidate_rect.Intersect(paint_rect); | 331 invalidate_rect.Intersect(paint_rect); |
329 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); | 332 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); |
330 SkAutoCanvasRestore auto_restore(canvas, true); | 333 cc::PaintCanvasAutoRestore auto_restore(canvas, true); |
331 canvas->clipRect(sk_invalidate_rect); | 334 canvas->clipRect(sk_invalidate_rect); |
332 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); | 335 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); |
333 gfx::Size image_size = gfx::ScaleToFlooredSize(pixel_image_size, scale_); | 336 gfx::Size image_size = gfx::ScaleToFlooredSize(pixel_image_size, scale_); |
334 | 337 |
335 PepperPluginInstance* plugin_instance = | 338 PepperPluginInstance* plugin_instance = |
336 renderer_ppapi_host_->GetPluginInstance(pp_instance()); | 339 renderer_ppapi_host_->GetPluginInstance(pp_instance()); |
337 if (!plugin_instance) | 340 if (!plugin_instance) |
338 return; | 341 return; |
339 if (plugin_instance->IsFullPagePlugin()) { | 342 if (plugin_instance->IsFullPagePlugin()) { |
340 // When we're resizing a window with a full-frame plugin, the plugin may | 343 // When we're resizing a window with a full-frame plugin, the plugin may |
341 // not yet have bound a new device, which will leave parts of the | 344 // not yet have bound a new device, which will leave parts of the |
342 // background exposed if the window is getting larger. We want this to | 345 // background exposed if the window is getting larger. We want this to |
343 // show white (typically less jarring) rather than black or uninitialized. | 346 // show white (typically less jarring) rather than black or uninitialized. |
344 // We don't do this for non-full-frame plugins since we specifically want | 347 // We don't do this for non-full-frame plugins since we specifically want |
345 // the page background to show through. | 348 // the page background to show through. |
346 SkAutoCanvasRestore auto_restore(canvas, true); | 349 cc::PaintCanvasAutoRestore auto_restore(canvas, true); |
347 SkRect image_data_rect = | 350 SkRect image_data_rect = |
348 gfx::RectToSkRect(gfx::Rect(plugin_rect.origin(), image_size)); | 351 gfx::RectToSkRect(gfx::Rect(plugin_rect.origin(), image_size)); |
349 canvas->clipRect(image_data_rect, SkClipOp::kDifference); | 352 canvas->clipRect(image_data_rect, SkClipOp::kDifference); |
350 | 353 |
351 SkPaint paint; | 354 cc::PaintFlags paint; |
352 paint.setBlendMode(SkBlendMode::kSrc); | 355 paint.setBlendMode(SkBlendMode::kSrc); |
353 paint.setColor(SK_ColorWHITE); | 356 paint.setColor(SK_ColorWHITE); |
354 canvas->drawRect(sk_invalidate_rect, paint); | 357 canvas->drawRect(sk_invalidate_rect, paint); |
355 } | 358 } |
356 | 359 |
357 SkPaint paint; | 360 cc::PaintFlags paint; |
358 if (is_always_opaque_) { | 361 if (is_always_opaque_) { |
359 // When we know the device is opaque, we can disable blending for slightly | 362 // When we know the device is opaque, we can disable blending for slightly |
360 // more optimized painting. | 363 // more optimized painting. |
361 paint.setBlendMode(SkBlendMode::kSrc); | 364 paint.setBlendMode(SkBlendMode::kSrc); |
362 } | 365 } |
363 | 366 |
364 SkPoint pixel_origin(PointToSkPoint(plugin_rect.origin())); | 367 SkPoint pixel_origin(PointToSkPoint(plugin_rect.origin())); |
365 if (scale_ != 1.0f && scale_ > 0.0f) { | 368 if (scale_ != 1.0f && scale_ > 0.0f) { |
366 canvas->scale(scale_, scale_); | 369 canvas->scale(scale_, scale_); |
367 pixel_origin.scale(1.0f / scale_); | 370 pixel_origin.scale(1.0f / scale_); |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 SkRect dest_rect = {SkIntToScalar(invalidated_rect->x()), | 731 SkRect dest_rect = {SkIntToScalar(invalidated_rect->x()), |
729 SkIntToScalar(invalidated_rect->y()), | 732 SkIntToScalar(invalidated_rect->y()), |
730 SkIntToScalar(invalidated_rect->right()), | 733 SkIntToScalar(invalidated_rect->right()), |
731 SkIntToScalar(invalidated_rect->bottom())}; | 734 SkIntToScalar(invalidated_rect->bottom())}; |
732 | 735 |
733 if (image->format() != image_data_->format()) { | 736 if (image->format() != image_data_->format()) { |
734 // Convert the image data if the format does not match. | 737 // Convert the image data if the format does not match. |
735 ConvertImageData(image, src_irect, image_data_.get(), dest_rect); | 738 ConvertImageData(image, src_irect, image_data_.get(), dest_rect); |
736 } else { | 739 } else { |
737 // We're guaranteed to have a mapped canvas since we mapped it in Init(). | 740 // We're guaranteed to have a mapped canvas since we mapped it in Init(). |
738 SkCanvas* backing_canvas = image_data_->GetCanvas(); | 741 cc::PaintCanvas* backing_canvas = image_data_->GetCanvas(); |
danakj
2017/01/20 23:34:14
does image_data_ really return a cc::PaintCanvas?
enne (OOO)
2017/01/24 01:51:28
Thanks, missed this one as a part of reverting cha
| |
739 | 742 |
740 // We want to replace the contents of the bitmap rather than blend. | 743 // We want to replace the contents of the bitmap rather than blend. |
741 SkPaint paint; | 744 cc::PaintFlags paint; |
742 paint.setBlendMode(SkBlendMode::kSrc); | 745 paint.setBlendMode(SkBlendMode::kSrc); |
743 backing_canvas->drawBitmapRect( | 746 cc::GetSkCanvas(backing_canvas) |
744 image->GetMappedBitmap(), src_irect, dest_rect, &paint); | 747 ->drawBitmapRect(image->GetMappedBitmap(), src_irect, dest_rect, |
748 &paint); | |
745 } | 749 } |
746 } | 750 } |
747 | 751 |
748 void PepperGraphics2DHost::ExecuteScroll(const gfx::Rect& clip, | 752 void PepperGraphics2DHost::ExecuteScroll(const gfx::Rect& clip, |
749 int dx, | 753 int dx, |
750 int dy, | 754 int dy, |
751 gfx::Rect* invalidated_rect) { | 755 gfx::Rect* invalidated_rect) { |
752 gfx::ScrollCanvas(image_data_->GetCanvas(), clip, gfx::Vector2d(dx, dy)); | 756 gfx::ScrollCanvas(image_data_->GetCanvas(), clip, gfx::Vector2d(dx, dy)); |
753 *invalidated_rect = clip; | 757 *invalidated_rect = clip; |
754 } | 758 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
829 gfx::Point inverse_scaled_point = | 833 gfx::Point inverse_scaled_point = |
830 gfx::ScaleToFlooredPoint(*delta, inverse_scale); | 834 gfx::ScaleToFlooredPoint(*delta, inverse_scale); |
831 if (original_delta != inverse_scaled_point) | 835 if (original_delta != inverse_scaled_point) |
832 return false; | 836 return false; |
833 } | 837 } |
834 | 838 |
835 return true; | 839 return true; |
836 } | 840 } |
837 | 841 |
838 } // namespace content | 842 } // namespace content |
OLD | NEW |