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

Side by Side Diff: webkit/plugins/ppapi/ppb_graphics_2d_impl.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 | « webkit/plugins/ppapi/ppapi_plugin_instance.cc ('k') | no next file » | 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 "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" 5 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // The |backing_bitmap| must be clipped to the |plugin_rect| to avoid painting 501 // The |backing_bitmap| must be clipped to the |plugin_rect| to avoid painting
502 // outside the plugin area. This can happen if the plugin has been resized since 502 // outside the plugin area. This can happen if the plugin has been resized since
503 // PaintImageData verified the image is within the plugin size. 503 // PaintImageData verified the image is within the plugin size.
504 void PPB_Graphics2D_Impl::Paint(WebKit::WebCanvas* canvas, 504 void PPB_Graphics2D_Impl::Paint(WebKit::WebCanvas* canvas,
505 const gfx::Rect& plugin_rect, 505 const gfx::Rect& plugin_rect,
506 const gfx::Rect& paint_rect) { 506 const gfx::Rect& paint_rect) {
507 TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::Paint"); 507 TRACE_EVENT0("pepper", "PPB_Graphics2D_Impl::Paint");
508 ImageDataAutoMapper auto_mapper(image_data_); 508 ImageDataAutoMapper auto_mapper(image_data_);
509 const SkBitmap& backing_bitmap = *image_data_->GetMappedBitmap(); 509 const SkBitmap& backing_bitmap = *image_data_->GetMappedBitmap();
510 510
511 #if defined(OS_MACOSX) && !defined(USE_SKIA)
512 SkAutoLockPixels lock(backing_bitmap);
513
514 base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider(
515 CGDataProviderCreateWithData(
516 NULL, backing_bitmap.getAddr32(0, 0),
517 backing_bitmap.rowBytes() * backing_bitmap.height(), NULL));
518 base::mac::ScopedCFTypeRef<CGImageRef> image(
519 CGImageCreate(
520 backing_bitmap.width(), backing_bitmap.height(),
521 8, 32, backing_bitmap.rowBytes(),
522 base::mac::GetSystemColorSpace(),
523 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
524 data_provider, NULL, false, kCGRenderingIntentDefault));
525
526 // Flip the transform
527 gfx::ScopedCGContextSaveGState save_gstate(canvas)
528 float window_height = static_cast<float>(CGBitmapContextGetHeight(canvas));
529 CGContextTranslateCTM(canvas, 0, window_height);
530 CGContextScaleCTM(canvas, 1.0, -1.0);
531
532 // To avoid painting outside the plugin boundaries and clip instead of
533 // scaling, CGContextDrawImage() must draw the full image using |bitmap_rect|
534 // but the context must be clipped to the plugin using |bounds|.
535
536 CGRect bitmap_rect;
537 bitmap_rect.origin.x = plugin_rect.origin().x();
538 bitmap_rect.origin.y = window_height - plugin_rect.origin().y() -
539 backing_bitmap.height();
540 bitmap_rect.size.width = backing_bitmap.width();
541 bitmap_rect.size.height = backing_bitmap.height();
542
543 CGRect bounds;
544 bounds.origin.x = plugin_rect.origin().x();
545 bounds.origin.y = window_height - plugin_rect.origin().y() -
546 plugin_rect.height();
547 bounds.size.width = plugin_rect.width();
548 bounds.size.height = plugin_rect.height();
549 // TODO(yzshen): We should take |paint_rect| into consideration as well.
550 CGContextClipToRect(canvas, bounds);
551
552 // TODO(jhorwich) Figure out if this code is even active anymore, and if so
553 // how to properly handle scaling.
554 DCHECK_EQ(1.0f, scale_);
555
556 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG
557 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped.
558
559 CGContextDrawImage(canvas, bitmap_rect, image);
560 #else
561 gfx::Rect invalidate_rect = gfx::IntersectRects(plugin_rect, paint_rect); 511 gfx::Rect invalidate_rect = gfx::IntersectRects(plugin_rect, paint_rect);
562 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); 512 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect);
563 SkAutoCanvasRestore auto_restore(canvas, true); 513 SkAutoCanvasRestore auto_restore(canvas, true);
564 canvas->clipRect(sk_invalidate_rect); 514 canvas->clipRect(sk_invalidate_rect);
565 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); 515 gfx::Size pixel_image_size(image_data_->width(), image_data_->height());
566 gfx::Size image_size = gfx::ToFlooredSize( 516 gfx::Size image_size = gfx::ToFlooredSize(
567 gfx::ScaleSize(pixel_image_size, scale_)); 517 gfx::ScaleSize(pixel_image_size, scale_));
568 518
569 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 519 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
570 if (!plugin_instance) 520 if (!plugin_instance)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 SkPoint origin; 555 SkPoint origin;
606 origin.set(SkIntToScalar(plugin_rect.x()), SkIntToScalar(plugin_rect.y())); 556 origin.set(SkIntToScalar(plugin_rect.x()), SkIntToScalar(plugin_rect.y()));
607 557
608 SkPoint pixel_origin = origin; 558 SkPoint pixel_origin = origin;
609 if (scale_ != 1.0f && scale_ > 0.0f) { 559 if (scale_ != 1.0f && scale_ > 0.0f) {
610 float inverse_scale = 1.0f / scale_; 560 float inverse_scale = 1.0f / scale_;
611 pixel_origin.scale(inverse_scale); 561 pixel_origin.scale(inverse_scale);
612 canvas->scale(scale_, scale_); 562 canvas->scale(scale_, scale_);
613 } 563 }
614 canvas->drawBitmap(image, pixel_origin.x(), pixel_origin.y(), &paint); 564 canvas->drawBitmap(image, pixel_origin.x(), pixel_origin.y(), &paint);
615 #endif
616 } 565 }
617 566
618 void PPB_Graphics2D_Impl::ViewWillInitiatePaint() { 567 void PPB_Graphics2D_Impl::ViewWillInitiatePaint() {
619 // Move any "unpainted" callback to the painted state. See 568 // Move any "unpainted" callback to the painted state. See
620 // |unpainted_flush_callback_| in the header for more. 569 // |unpainted_flush_callback_| in the header for more.
621 if (!unpainted_flush_callback_.is_null()) { 570 if (!unpainted_flush_callback_.is_null()) {
622 DCHECK(painted_flush_callback_.is_null()); 571 DCHECK(painted_flush_callback_.is_null());
623 std::swap(painted_flush_callback_, unpainted_flush_callback_); 572 std::swap(painted_flush_callback_, unpainted_flush_callback_);
624 } 573 }
625 } 574 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 } 707 }
759 708
760 bool PPB_Graphics2D_Impl::HasPendingFlush() const { 709 bool PPB_Graphics2D_Impl::HasPendingFlush() const {
761 return !unpainted_flush_callback_.is_null() || 710 return !unpainted_flush_callback_.is_null() ||
762 !painted_flush_callback_.is_null() || 711 !painted_flush_callback_.is_null() ||
763 offscreen_flush_pending_; 712 offscreen_flush_pending_;
764 } 713 }
765 714
766 } // namespace ppapi 715 } // namespace ppapi
767 } // namespace webkit 716 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698