OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
22 #include "webkit/plugins/ppapi/common.h" | 22 #include "webkit/plugins/ppapi/common.h" |
23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
24 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 24 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
25 | 25 |
26 #if defined(OS_MACOSX) | 26 #if defined(OS_MACOSX) |
27 #include "base/mac/mac_util.h" | 27 #include "base/mac/mac_util.h" |
28 #include "base/mac/scoped_cftyperef.h" | 28 #include "base/mac/scoped_cftyperef.h" |
29 #endif | 29 #endif |
30 | 30 |
31 #if defined(OS_MACOSX) && defined(USE_SKIA) | |
32 #include "skia/ext/skia_utils_mac.h" | |
33 #endif | |
34 | |
31 namespace webkit { | 35 namespace webkit { |
32 namespace ppapi { | 36 namespace ppapi { |
33 | 37 |
34 namespace { | 38 namespace { |
35 | 39 |
36 // Converts a rect inside an image of the given dimensions. The rect may be | 40 // Converts a rect inside an image of the given dimensions. The rect may be |
37 // NULL to indicate it should be the entire image. If the rect is outside of | 41 // NULL to indicate it should be the entire image. If the rect is outside of |
38 // the image, this will do nothing and return false. | 42 // the image, this will do nothing and return false. |
39 bool ValidateAndConvertRect(const PP_Rect* rect, | 43 bool ValidateAndConvertRect(const PP_Rect* rect, |
40 int image_width, int image_height, | 44 int image_width, int image_height, |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 NULL, backing_bitmap.getAddr32(0, 0), | 509 NULL, backing_bitmap.getAddr32(0, 0), |
506 backing_bitmap.rowBytes() * backing_bitmap.height(), NULL)); | 510 backing_bitmap.rowBytes() * backing_bitmap.height(), NULL)); |
507 base::mac::ScopedCFTypeRef<CGImageRef> image( | 511 base::mac::ScopedCFTypeRef<CGImageRef> image( |
508 CGImageCreate( | 512 CGImageCreate( |
509 backing_bitmap.width(), backing_bitmap.height(), | 513 backing_bitmap.width(), backing_bitmap.height(), |
510 8, 32, backing_bitmap.rowBytes(), | 514 8, 32, backing_bitmap.rowBytes(), |
511 base::mac::GetSystemColorSpace(), | 515 base::mac::GetSystemColorSpace(), |
512 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, | 516 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, |
513 data_provider, NULL, false, kCGRenderingIntentDefault)); | 517 data_provider, NULL, false, kCGRenderingIntentDefault)); |
514 | 518 |
519 #if defined(USE_SKIA) | |
520 gfx::SkiaBitLocker bitLocker(canvas); | |
521 CGContextRef cgContext = bitLocker.cgContext(); | |
stuartmorgan
2011/04/12 17:35:51
Same question here; why use CG?
_cary
2011/04/12 21:03:55
Done.
| |
522 #else | |
523 CGContextRef cgContext = canvas; | |
524 #endif | |
515 // Flip the transform | 525 // Flip the transform |
516 CGContextSaveGState(canvas); | 526 CGContextSaveGState(cgContext); |
517 float window_height = static_cast<float>(CGBitmapContextGetHeight(canvas)); | 527 float window_height = static_cast<float>(CGBitmapContextGetHeight(cgContext)); |
518 CGContextTranslateCTM(canvas, 0, window_height); | 528 CGContextTranslateCTM(cgContext, 0, window_height); |
519 CGContextScaleCTM(canvas, 1.0, -1.0); | 529 CGContextScaleCTM(cgContext, 1.0, -1.0); |
520 | 530 |
521 // To avoid painting outside the plugin boundaries and clip instead of | 531 // To avoid painting outside the plugin boundaries and clip instead of |
522 // scaling, CGContextDrawImage() must draw the full image using |bitmap_rect| | 532 // scaling, CGContextDrawImage() must draw the full image using |bitmap_rect| |
523 // but the context must be clipped to the plugin using |bounds|. | 533 // but the context must be clipped to the plugin using |bounds|. |
524 | 534 |
525 CGRect bitmap_rect; | 535 CGRect bitmap_rect; |
526 bitmap_rect.origin.x = plugin_rect.origin().x(); | 536 bitmap_rect.origin.x = plugin_rect.origin().x(); |
527 bitmap_rect.origin.y = window_height - plugin_rect.origin().y() - | 537 bitmap_rect.origin.y = window_height - plugin_rect.origin().y() - |
528 backing_bitmap.height(); | 538 backing_bitmap.height(); |
529 bitmap_rect.size.width = backing_bitmap.width(); | 539 bitmap_rect.size.width = backing_bitmap.width(); |
530 bitmap_rect.size.height = backing_bitmap.height(); | 540 bitmap_rect.size.height = backing_bitmap.height(); |
531 | 541 |
532 CGRect bounds; | 542 CGRect bounds; |
533 bounds.origin.x = plugin_rect.origin().x(); | 543 bounds.origin.x = plugin_rect.origin().x(); |
534 bounds.origin.y = window_height - plugin_rect.origin().y() - | 544 bounds.origin.y = window_height - plugin_rect.origin().y() - |
535 plugin_rect.height(); | 545 plugin_rect.height(); |
536 bounds.size.width = plugin_rect.width(); | 546 bounds.size.width = plugin_rect.width(); |
537 bounds.size.height = plugin_rect.height(); | 547 bounds.size.height = plugin_rect.height(); |
538 | 548 |
539 CGContextClipToRect(canvas, bounds); | 549 CGContextClipToRect(cgContext, bounds); |
540 | 550 |
541 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG | 551 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG |
542 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped. | 552 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped. |
543 | 553 |
544 CGContextDrawImage(canvas, bitmap_rect, image); | 554 CGContextDrawImage(cgContext, bitmap_rect, image); |
545 CGContextRestoreGState(canvas); | 555 CGContextRestoreGState(cgContext); |
546 #else | 556 #else |
547 SkPaint paint; | 557 SkPaint paint; |
548 if (is_always_opaque_) { | 558 if (is_always_opaque_) { |
549 // When we know the device is opaque, we can disable blending for slightly | 559 // When we know the device is opaque, we can disable blending for slightly |
550 // more optimized painting. | 560 // more optimized painting. |
551 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 561 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
552 } | 562 } |
553 | 563 |
554 canvas->save(); | 564 canvas->save(); |
555 SkRect clip_rect = SkRect::MakeXYWH(SkIntToScalar(plugin_rect.origin().x()), | 565 SkRect clip_rect = SkRect::MakeXYWH(SkIntToScalar(plugin_rect.origin().x()), |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 } | 687 } |
678 | 688 |
679 bool PPB_Graphics2D_Impl::HasPendingFlush() const { | 689 bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
680 return !unpainted_flush_callback_.is_null() || | 690 return !unpainted_flush_callback_.is_null() || |
681 !painted_flush_callback_.is_null() || | 691 !painted_flush_callback_.is_null() || |
682 offscreen_flush_pending_; | 692 offscreen_flush_pending_; |
683 } | 693 } |
684 | 694 |
685 } // namespace ppapi | 695 } // namespace ppapi |
686 } // namespace webkit | 696 } // namespace webkit |
OLD | NEW |