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_flags.h" |
17 #include "cc/resources/shared_bitmap.h" | 18 #include "cc/resources/shared_bitmap.h" |
18 #include "cc/resources/texture_mailbox.h" | 19 #include "cc/resources/texture_mailbox.h" |
19 #include "content/child/child_shared_bitmap_manager.h" | 20 #include "content/child/child_shared_bitmap_manager.h" |
20 #include "content/public/renderer/render_thread.h" | 21 #include "content/public/renderer/render_thread.h" |
21 #include "content/public/renderer/renderer_ppapi_host.h" | 22 #include "content/public/renderer/renderer_ppapi_host.h" |
22 #include "content/renderer/pepper/gfx_conversion.h" | 23 #include "content/renderer/pepper/gfx_conversion.h" |
23 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 24 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
24 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" | 25 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" |
25 #include "content/renderer/pepper/ppb_image_data_impl.h" | 26 #include "content/renderer/pepper/ppb_image_data_impl.h" |
26 #include "content/renderer/render_thread_impl.h" | 27 #include "content/renderer/render_thread_impl.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 void PepperGraphics2DHost::Paint(blink::WebCanvas* canvas, | 321 void PepperGraphics2DHost::Paint(blink::WebCanvas* canvas, |
321 const gfx::Rect& plugin_rect, | 322 const gfx::Rect& plugin_rect, |
322 const gfx::Rect& paint_rect) { | 323 const gfx::Rect& paint_rect) { |
323 TRACE_EVENT0("pepper", "PepperGraphics2DHost::Paint"); | 324 TRACE_EVENT0("pepper", "PepperGraphics2DHost::Paint"); |
324 ImageDataAutoMapper auto_mapper(image_data_.get()); | 325 ImageDataAutoMapper auto_mapper(image_data_.get()); |
325 SkBitmap backing_bitmap = image_data_->GetMappedBitmap(); | 326 SkBitmap backing_bitmap = image_data_->GetMappedBitmap(); |
326 | 327 |
327 gfx::Rect invalidate_rect = plugin_rect; | 328 gfx::Rect invalidate_rect = plugin_rect; |
328 invalidate_rect.Intersect(paint_rect); | 329 invalidate_rect.Intersect(paint_rect); |
329 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); | 330 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); |
330 SkAutoCanvasRestore auto_restore(canvas, true); | 331 cc::PaintCanvasAutoRestore auto_restore(canvas, true); |
331 canvas->clipRect(sk_invalidate_rect); | 332 canvas->clipRect(sk_invalidate_rect); |
332 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); | 333 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); |
333 gfx::Size image_size = gfx::ScaleToFlooredSize(pixel_image_size, scale_); | 334 gfx::Size image_size = gfx::ScaleToFlooredSize(pixel_image_size, scale_); |
334 | 335 |
335 PepperPluginInstance* plugin_instance = | 336 PepperPluginInstance* plugin_instance = |
336 renderer_ppapi_host_->GetPluginInstance(pp_instance()); | 337 renderer_ppapi_host_->GetPluginInstance(pp_instance()); |
337 if (!plugin_instance) | 338 if (!plugin_instance) |
338 return; | 339 return; |
339 if (plugin_instance->IsFullPagePlugin()) { | 340 if (plugin_instance->IsFullPagePlugin()) { |
340 // When we're resizing a window with a full-frame plugin, the plugin may | 341 // 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 | 342 // 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 | 343 // background exposed if the window is getting larger. We want this to |
343 // show white (typically less jarring) rather than black or uninitialized. | 344 // 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 | 345 // We don't do this for non-full-frame plugins since we specifically want |
345 // the page background to show through. | 346 // the page background to show through. |
346 SkAutoCanvasRestore auto_restore(canvas, true); | 347 cc::PaintCanvasAutoRestore auto_restore(canvas, true); |
347 SkRect image_data_rect = | 348 SkRect image_data_rect = |
348 gfx::RectToSkRect(gfx::Rect(plugin_rect.origin(), image_size)); | 349 gfx::RectToSkRect(gfx::Rect(plugin_rect.origin(), image_size)); |
349 canvas->clipRect(image_data_rect, SkClipOp::kDifference); | 350 canvas->clipRect(image_data_rect, SkClipOp::kDifference); |
350 | 351 |
351 SkPaint paint; | 352 cc::PaintFlags flags; |
352 paint.setBlendMode(SkBlendMode::kSrc); | 353 flags.setBlendMode(SkBlendMode::kSrc); |
353 paint.setColor(SK_ColorWHITE); | 354 flags.setColor(SK_ColorWHITE); |
354 canvas->drawRect(sk_invalidate_rect, paint); | 355 canvas->drawRect(sk_invalidate_rect, flags); |
355 } | 356 } |
356 | 357 |
357 SkPaint paint; | 358 cc::PaintFlags flags; |
358 if (is_always_opaque_) { | 359 if (is_always_opaque_) { |
359 // When we know the device is opaque, we can disable blending for slightly | 360 // When we know the device is opaque, we can disable blending for slightly |
360 // more optimized painting. | 361 // more optimized painting. |
361 paint.setBlendMode(SkBlendMode::kSrc); | 362 flags.setBlendMode(SkBlendMode::kSrc); |
362 } | 363 } |
363 | 364 |
364 SkPoint pixel_origin(PointToSkPoint(plugin_rect.origin())); | 365 SkPoint pixel_origin(PointToSkPoint(plugin_rect.origin())); |
365 if (scale_ != 1.0f && scale_ > 0.0f) { | 366 if (scale_ != 1.0f && scale_ > 0.0f) { |
366 canvas->scale(scale_, scale_); | 367 canvas->scale(scale_, scale_); |
367 pixel_origin.scale(1.0f / scale_); | 368 pixel_origin.scale(1.0f / scale_); |
368 } | 369 } |
369 canvas->drawBitmap(backing_bitmap, pixel_origin.x(), pixel_origin.y(), | 370 canvas->drawBitmap(backing_bitmap, pixel_origin.x(), pixel_origin.y(), |
370 &paint); | 371 &flags); |
371 } | 372 } |
372 | 373 |
373 void PepperGraphics2DHost::ViewInitiatedPaint() { | 374 void PepperGraphics2DHost::ViewInitiatedPaint() { |
374 TRACE_EVENT0("pepper", "PepperGraphics2DHost::ViewInitiatedPaint"); | 375 TRACE_EVENT0("pepper", "PepperGraphics2DHost::ViewInitiatedPaint"); |
375 if (need_flush_ack_) { | 376 if (need_flush_ack_) { |
376 SendFlushAck(); | 377 SendFlushAck(); |
377 need_flush_ack_ = false; | 378 need_flush_ack_ = false; |
378 } | 379 } |
379 } | 380 } |
380 | 381 |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 gfx::Point inverse_scaled_point = | 830 gfx::Point inverse_scaled_point = |
830 gfx::ScaleToFlooredPoint(*delta, inverse_scale); | 831 gfx::ScaleToFlooredPoint(*delta, inverse_scale); |
831 if (original_delta != inverse_scaled_point) | 832 if (original_delta != inverse_scaled_point) |
832 return false; | 833 return false; |
833 } | 834 } |
834 | 835 |
835 return true; | 836 return true; |
836 } | 837 } |
837 | 838 |
838 } // namespace content | 839 } // namespace content |
OLD | NEW |