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

Side by Side Diff: webkit/plugins/ppapi/ppb_graphics_2d_impl.cc

Issue 10869031: mac: Use ScopedCGContextSaveGState in a few more places (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "skia/ext/platform_canvas.h" 13 #include "skia/ext/platform_canvas.h"
14 #include "ppapi/c/pp_errors.h" 14 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/c/pp_rect.h" 15 #include "ppapi/c/pp_rect.h"
16 #include "ppapi/c/pp_resource.h" 16 #include "ppapi/c/pp_resource.h"
17 #include "ppapi/c/ppb_graphics_2d.h" 17 #include "ppapi/c/ppb_graphics_2d.h"
18 #include "ppapi/thunk/enter.h" 18 #include "ppapi/thunk/enter.h"
19 #include "ppapi/thunk/thunk.h" 19 #include "ppapi/thunk/thunk.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 20 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "ui/gfx/blit.h" 21 #include "ui/gfx/blit.h"
22 #include "ui/gfx/point.h" 22 #include "ui/gfx/point.h"
23 #include "ui/gfx/rect.h" 23 #include "ui/gfx/rect.h"
24 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
24 #include "webkit/plugins/ppapi/common.h" 25 #include "webkit/plugins/ppapi/common.h"
25 #include "webkit/plugins/ppapi/gfx_conversion.h" 26 #include "webkit/plugins/ppapi/gfx_conversion.h"
26 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 27 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
27 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" 28 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
28 #include "webkit/plugins/ppapi/resource_helper.h" 29 #include "webkit/plugins/ppapi/resource_helper.h"
29 30
30 #if defined(OS_MACOSX) 31 #if defined(OS_MACOSX)
31 #include "base/mac/mac_util.h" 32 #include "base/mac/mac_util.h"
32 #include "base/mac/scoped_cftyperef.h" 33 #include "base/mac/scoped_cftyperef.h"
33 #endif 34 #endif
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 backing_bitmap.rowBytes() * backing_bitmap.height(), NULL)); 515 backing_bitmap.rowBytes() * backing_bitmap.height(), NULL));
515 base::mac::ScopedCFTypeRef<CGImageRef> image( 516 base::mac::ScopedCFTypeRef<CGImageRef> image(
516 CGImageCreate( 517 CGImageCreate(
517 backing_bitmap.width(), backing_bitmap.height(), 518 backing_bitmap.width(), backing_bitmap.height(),
518 8, 32, backing_bitmap.rowBytes(), 519 8, 32, backing_bitmap.rowBytes(),
519 base::mac::GetSystemColorSpace(), 520 base::mac::GetSystemColorSpace(),
520 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, 521 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
521 data_provider, NULL, false, kCGRenderingIntentDefault)); 522 data_provider, NULL, false, kCGRenderingIntentDefault));
522 523
523 // Flip the transform 524 // Flip the transform
524 CGContextSaveGState(canvas); 525 gfx::ScopedCGContextSaveGState save_gstate(canvas)
525 float window_height = static_cast<float>(CGBitmapContextGetHeight(canvas)); 526 float window_height = static_cast<float>(CGBitmapContextGetHeight(canvas));
526 CGContextTranslateCTM(canvas, 0, window_height); 527 CGContextTranslateCTM(canvas, 0, window_height);
527 CGContextScaleCTM(canvas, 1.0, -1.0); 528 CGContextScaleCTM(canvas, 1.0, -1.0);
528 529
529 // To avoid painting outside the plugin boundaries and clip instead of 530 // To avoid painting outside the plugin boundaries and clip instead of
530 // scaling, CGContextDrawImage() must draw the full image using |bitmap_rect| 531 // scaling, CGContextDrawImage() must draw the full image using |bitmap_rect|
531 // but the context must be clipped to the plugin using |bounds|. 532 // but the context must be clipped to the plugin using |bounds|.
532 533
533 CGRect bitmap_rect; 534 CGRect bitmap_rect;
534 bitmap_rect.origin.x = plugin_rect.origin().x(); 535 bitmap_rect.origin.x = plugin_rect.origin().x();
(...skipping 12 matching lines...) Expand all
547 CGContextClipToRect(canvas, bounds); 548 CGContextClipToRect(canvas, bounds);
548 549
549 // TODO(jhorwich) Figure out if this code is even active anymore, and if so 550 // TODO(jhorwich) Figure out if this code is even active anymore, and if so
550 // how to properly handle scaling. 551 // how to properly handle scaling.
551 DCHECK_EQ(1.0f, scale_); 552 DCHECK_EQ(1.0f, scale_);
552 553
553 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG 554 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG
554 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped. 555 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped.
555 556
556 CGContextDrawImage(canvas, bitmap_rect, image); 557 CGContextDrawImage(canvas, bitmap_rect, image);
557 CGContextRestoreGState(canvas);
558 #else 558 #else
559 SkRect sk_plugin_rect = SkRect::MakeXYWH( 559 SkRect sk_plugin_rect = SkRect::MakeXYWH(
560 SkIntToScalar(plugin_rect.origin().x()), 560 SkIntToScalar(plugin_rect.origin().x()),
561 SkIntToScalar(plugin_rect.origin().y()), 561 SkIntToScalar(plugin_rect.origin().y()),
562 SkIntToScalar(plugin_rect.width()), 562 SkIntToScalar(plugin_rect.width()),
563 SkIntToScalar(plugin_rect.height())); 563 SkIntToScalar(plugin_rect.height()));
564 canvas->save(); 564 canvas->save();
565 canvas->clipRect(sk_plugin_rect); 565 canvas->clipRect(sk_plugin_rect);
566 566
567 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 567 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 } 751 }
752 752
753 bool PPB_Graphics2D_Impl::HasPendingFlush() const { 753 bool PPB_Graphics2D_Impl::HasPendingFlush() const {
754 return !unpainted_flush_callback_.is_null() || 754 return !unpainted_flush_callback_.is_null() ||
755 !painted_flush_callback_.is_null() || 755 !painted_flush_callback_.is_null() ||
756 offscreen_flush_pending_; 756 offscreen_flush_pending_;
757 } 757 }
758 758
759 } // namespace ppapi 759 } // namespace ppapi
760 } // namespace webkit 760 } // 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