Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: content/renderer/pepper/pepper_graphics_2d_host.cc

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 SkIRect src_irect = {x, y, x + image_resource->width(), 269 SkIRect src_irect = {x, y, x + image_resource->width(),
270 y + image_resource->height()}; 270 y + image_resource->height()};
271 SkRect dest_rect = {SkIntToScalar(0), SkIntToScalar(0), 271 SkRect dest_rect = {SkIntToScalar(0), SkIntToScalar(0),
272 SkIntToScalar(image_resource->width()), 272 SkIntToScalar(image_resource->width()),
273 SkIntToScalar(image_resource->height())}; 273 SkIntToScalar(image_resource->height())};
274 274
275 if (image_resource->format() != image_data_->format()) { 275 if (image_resource->format() != image_data_->format()) {
276 // Convert the image data if the format does not match. 276 // Convert the image data if the format does not match.
277 ConvertImageData(image_data_.get(), src_irect, image_resource, dest_rect); 277 ConvertImageData(image_data_.get(), src_irect, image_resource, dest_rect);
278 } else { 278 } else {
279 SkCanvas* dest_canvas = image_resource->GetCanvas(); 279 CdlCanvas* dest_canvas = image_resource->GetCanvas();
280 280
281 // We want to replace the contents of the bitmap rather than blend. 281 // We want to replace the contents of the bitmap rather than blend.
282 SkPaint paint; 282 SkPaint paint;
283 paint.setBlendMode(SkBlendMode::kSrc); 283 paint.setBlendMode(SkBlendMode::kSrc);
284 dest_canvas->drawBitmapRect( 284 GetSkCanvas(dest_canvas)
285 image_data_->GetMappedBitmap(), src_irect, dest_rect, &paint); 285 ->drawBitmapRect(image_data_->GetMappedBitmap(), src_irect, dest_rect,
286 &paint);
286 } 287 }
287 return true; 288 return true;
288 } 289 }
289 290
290 bool PepperGraphics2DHost::BindToInstance( 291 bool PepperGraphics2DHost::BindToInstance(
291 PepperPluginInstanceImpl* new_instance) { 292 PepperPluginInstanceImpl* new_instance) {
292 if (new_instance && new_instance->pp_instance() != pp_instance()) 293 if (new_instance && new_instance->pp_instance() != pp_instance())
293 return false; // Can't bind other instance's contexts. 294 return false; // Can't bind other instance's contexts.
294 if (bound_instance_ == new_instance) 295 if (bound_instance_ == new_instance)
295 return true; // Rebinding the same device, nothing to do. 296 return true; // Rebinding the same device, nothing to do.
(...skipping 24 matching lines...) Expand all
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 CdlAutoCanvasRestore 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 CdlAutoCanvasRestore 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, SkRegion::kDifference_Op); 350 canvas->clipRect(image_data_rect, SkRegion::kDifference_Op);
350 351
351 SkPaint paint; 352 CdlPaint paint;
352 paint.setBlendMode(SkBlendMode::kSrc); 353 paint.setBlendMode(SkBlendMode::kSrc);
353 paint.setColor(SK_ColorWHITE); 354 paint.setColor(SK_ColorWHITE);
354 canvas->drawRect(sk_invalidate_rect, paint); 355 canvas->drawRect(sk_invalidate_rect, paint);
355 } 356 }
356 357
357 SkPaint paint; 358 CdlPaint paint;
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 paint.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_);
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 SkRect dest_rect = {SkIntToScalar(invalidated_rect->x()), 729 SkRect dest_rect = {SkIntToScalar(invalidated_rect->x()),
729 SkIntToScalar(invalidated_rect->y()), 730 SkIntToScalar(invalidated_rect->y()),
730 SkIntToScalar(invalidated_rect->right()), 731 SkIntToScalar(invalidated_rect->right()),
731 SkIntToScalar(invalidated_rect->bottom())}; 732 SkIntToScalar(invalidated_rect->bottom())};
732 733
733 if (image->format() != image_data_->format()) { 734 if (image->format() != image_data_->format()) {
734 // Convert the image data if the format does not match. 735 // Convert the image data if the format does not match.
735 ConvertImageData(image, src_irect, image_data_.get(), dest_rect); 736 ConvertImageData(image, src_irect, image_data_.get(), dest_rect);
736 } else { 737 } else {
737 // We're guaranteed to have a mapped canvas since we mapped it in Init(). 738 // We're guaranteed to have a mapped canvas since we mapped it in Init().
738 SkCanvas* backing_canvas = image_data_->GetCanvas(); 739 CdlCanvas* backing_canvas = image_data_->GetCanvas();
739 740
740 // We want to replace the contents of the bitmap rather than blend. 741 // We want to replace the contents of the bitmap rather than blend.
741 SkPaint paint; 742 SkPaint paint;
742 paint.setBlendMode(SkBlendMode::kSrc); 743 paint.setBlendMode(SkBlendMode::kSrc);
743 backing_canvas->drawBitmapRect( 744 GetSkCanvas(backing_canvas)
744 image->GetMappedBitmap(), src_irect, dest_rect, &paint); 745 ->drawBitmapRect(image->GetMappedBitmap(), src_irect, dest_rect,
746 &paint);
745 } 747 }
746 } 748 }
747 749
748 void PepperGraphics2DHost::ExecuteScroll(const gfx::Rect& clip, 750 void PepperGraphics2DHost::ExecuteScroll(const gfx::Rect& clip,
749 int dx, 751 int dx,
750 int dy, 752 int dy,
751 gfx::Rect* invalidated_rect) { 753 gfx::Rect* invalidated_rect) {
752 gfx::ScrollCanvas(image_data_->GetCanvas(), clip, gfx::Vector2d(dx, dy)); 754 gfx::ScrollCanvas(image_data_->GetCanvas(), clip, gfx::Vector2d(dx, dy));
753 *invalidated_rect = clip; 755 *invalidated_rect = clip;
754 } 756 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 gfx::Point inverse_scaled_point = 831 gfx::Point inverse_scaled_point =
830 gfx::ScaleToFlooredPoint(*delta, inverse_scale); 832 gfx::ScaleToFlooredPoint(*delta, inverse_scale);
831 if (original_delta != inverse_scaled_point) 833 if (original_delta != inverse_scaled_point)
832 return false; 834 return false;
833 } 835 }
834 836
835 return true; 837 return true;
836 } 838 }
837 839
838 } // namespace content 840 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc/webrtc_video_capturer_adapter.cc ('k') | content/renderer/pepper/pepper_plugin_instance_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698