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

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

Issue 12437007: Pepper cleanup: USE_SKIA is always true. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 months 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
« no previous file with comments | « no previous file | webkit/plugins/ppapi/ppapi_plugin_instance.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // The |backing_bitmap| must be clipped to the |plugin_rect| to avoid painting 318 // The |backing_bitmap| must be clipped to the |plugin_rect| to avoid painting
319 // outside the plugin area. This can happen if the plugin has been resized since 319 // outside the plugin area. This can happen if the plugin has been resized since
320 // PaintImageData verified the image is within the plugin size. 320 // PaintImageData verified the image is within the plugin size.
321 void PepperGraphics2DHost::Paint(WebKit::WebCanvas* canvas, 321 void PepperGraphics2DHost::Paint(WebKit::WebCanvas* canvas,
322 const gfx::Rect& plugin_rect, 322 const gfx::Rect& plugin_rect,
323 const gfx::Rect& paint_rect) { 323 const gfx::Rect& paint_rect) {
324 TRACE_EVENT0("pepper", "PepperGraphics2DHost::Paint"); 324 TRACE_EVENT0("pepper", "PepperGraphics2DHost::Paint");
325 ImageDataAutoMapper auto_mapper(image_data_); 325 ImageDataAutoMapper auto_mapper(image_data_);
326 const SkBitmap& backing_bitmap = *image_data_->GetMappedBitmap(); 326 const SkBitmap& backing_bitmap = *image_data_->GetMappedBitmap();
327 327
328 #if defined(OS_MACOSX) && !defined(USE_SKIA)
329 SkAutoLockPixels lock(backing_bitmap);
330
331 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider(
332 CGDataProviderCreateWithData(
333 NULL, backing_bitmap.getAddr32(0, 0),
334 backing_bitmap.rowBytes() * backing_bitmap.height(), NULL));
335 base::mac::ScopedCFTypeRef<CGImageRef> image(
336 CGImageCreate(
337 backing_bitmap.width(), backing_bitmap.height(),
338 8, 32, backing_bitmap.rowBytes(),
339 base::mac::GetSystemColorSpace(),
340 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
341 data_provider, NULL, false, kCGRenderingIntentDefault));
342
343 // Flip the transform
344 gfx::ScopedCGContextSaveGState save_gstate(canvas)
345 float window_height = static_cast<float>(CGBitmapContextGetHeight(canvas));
346 CGContextTranslateCTM(canvas, 0, window_height);
347 CGContextScaleCTM(canvas, 1.0, -1.0);
348
349 // To avoid painting outside the plugin boundaries and clip instead of
350 // scaling, CGContextDrawImage() must draw the full image using |bitmap_rect|
351 // but the context must be clipped to the plugin using |bounds|.
352
353 CGRect bitmap_rect;
354 bitmap_rect.origin.x = plugin_rect.origin().x();
355 bitmap_rect.origin.y = window_height - plugin_rect.origin().y() -
356 backing_bitmap.height();
357 bitmap_rect.size.width = backing_bitmap.width();
358 bitmap_rect.size.height = backing_bitmap.height();
359
360 CGRect bounds;
361 bounds.origin.x = plugin_rect.origin().x();
362 bounds.origin.y = window_height - plugin_rect.origin().y() -
363 plugin_rect.height();
364 bounds.size.width = plugin_rect.width();
365 bounds.size.height = plugin_rect.height();
366 // TODO(yzshen): We should take |paint_rect| into consideration as well.
367 CGContextClipToRect(canvas, bounds);
368
369 // TODO(jhorwich) Figure out if this code is even active anymore, and if so
370 // how to properly handle scaling.
371 DCHECK_EQ(1.0f, scale_);
372
373 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG
374 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped.
375
376 CGContextDrawImage(canvas, bitmap_rect, image);
377 #else
378 gfx::Rect invalidate_rect = plugin_rect; 328 gfx::Rect invalidate_rect = plugin_rect;
379 invalidate_rect.Intersect(paint_rect); 329 invalidate_rect.Intersect(paint_rect);
380 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); 330 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect);
381 SkAutoCanvasRestore auto_restore(canvas, true); 331 SkAutoCanvasRestore auto_restore(canvas, true);
382 canvas->clipRect(sk_invalidate_rect); 332 canvas->clipRect(sk_invalidate_rect);
383 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); 333 gfx::Size pixel_image_size(image_data_->width(), image_data_->height());
384 gfx::Size image_size = gfx::ToFlooredSize( 334 gfx::Size image_size = gfx::ToFlooredSize(
385 gfx::ScaleSize(pixel_image_size, scale_)); 335 gfx::ScaleSize(pixel_image_size, scale_));
386 336
387 webkit::ppapi::PluginInstance* plugin_instance = 337 webkit::ppapi::PluginInstance* plugin_instance =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 SkPoint origin; 374 SkPoint origin;
425 origin.set(SkIntToScalar(plugin_rect.x()), SkIntToScalar(plugin_rect.y())); 375 origin.set(SkIntToScalar(plugin_rect.x()), SkIntToScalar(plugin_rect.y()));
426 376
427 SkPoint pixel_origin = origin; 377 SkPoint pixel_origin = origin;
428 if (scale_ != 1.0f && scale_ > 0.0f) { 378 if (scale_ != 1.0f && scale_ > 0.0f) {
429 float inverse_scale = 1.0f / scale_; 379 float inverse_scale = 1.0f / scale_;
430 pixel_origin.scale(inverse_scale); 380 pixel_origin.scale(inverse_scale);
431 canvas->scale(scale_, scale_); 381 canvas->scale(scale_, scale_);
432 } 382 }
433 canvas->drawBitmap(image, pixel_origin.x(), pixel_origin.y(), &paint); 383 canvas->drawBitmap(image, pixel_origin.x(), pixel_origin.y(), &paint);
434 #endif
435 } 384 }
436 385
437 void PepperGraphics2DHost::ViewWillInitiatePaint() { 386 void PepperGraphics2DHost::ViewWillInitiatePaint() {
438 } 387 }
439 388
440 void PepperGraphics2DHost::ViewInitiatedPaint() { 389 void PepperGraphics2DHost::ViewInitiatedPaint() {
441 } 390 }
442 391
443 void PepperGraphics2DHost::ViewFlushedPaint() { 392 void PepperGraphics2DHost::ViewFlushedPaint() {
444 TRACE_EVENT0("pepper", "PepperGraphics2DHost::ViewFlushedPaint"); 393 TRACE_EVENT0("pepper", "PepperGraphics2DHost::ViewFlushedPaint");
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 gfx::Point inverse_scaled_point = 760 gfx::Point inverse_scaled_point =
812 gfx::ToFlooredPoint(gfx::ScalePoint(*delta, inverse_scale)); 761 gfx::ToFlooredPoint(gfx::ScalePoint(*delta, inverse_scale));
813 if (original_delta != inverse_scaled_point) 762 if (original_delta != inverse_scaled_point)
814 return false; 763 return false;
815 } 764 }
816 765
817 return true; 766 return true;
818 } 767 }
819 768
820 } // namespace content 769 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | webkit/plugins/ppapi/ppapi_plugin_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698