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

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

Issue 11081007: Remove implicit flooring Scale() method from Point and Size. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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/glue/webcursor_aurax11.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 "base/time.h" 13 #include "base/time.h"
14 #include "skia/ext/platform_canvas.h" 14 #include "skia/ext/platform_canvas.h"
15 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
16 #include "ppapi/c/pp_rect.h" 16 #include "ppapi/c/pp_rect.h"
17 #include "ppapi/c/pp_resource.h" 17 #include "ppapi/c/pp_resource.h"
18 #include "ppapi/c/ppb_graphics_2d.h" 18 #include "ppapi/c/ppb_graphics_2d.h"
19 #include "ppapi/thunk/enter.h" 19 #include "ppapi/thunk/enter.h"
20 #include "ppapi/thunk/thunk.h" 20 #include "ppapi/thunk/thunk.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/gfx/blit.h" 22 #include "ui/gfx/blit.h"
23 #include "ui/gfx/point.h" 23 #include "ui/gfx/point.h"
24 #include "ui/gfx/point_conversions.h"
24 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
26 #include "ui/gfx/rect_conversions.h"
27 #include "ui/gfx/size_conversions.h"
25 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 28 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
26 #include "ui/gfx/skia_util.h" 29 #include "ui/gfx/skia_util.h"
27 #include "webkit/plugins/ppapi/common.h" 30 #include "webkit/plugins/ppapi/common.h"
28 #include "webkit/plugins/ppapi/gfx_conversion.h" 31 #include "webkit/plugins/ppapi/gfx_conversion.h"
29 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 32 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
30 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" 33 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
31 #include "webkit/plugins/ppapi/resource_helper.h" 34 #include "webkit/plugins/ppapi/resource_helper.h"
32 35
33 #if defined(OS_MACOSX) 36 #if defined(OS_MACOSX)
34 #include "base/mac/mac_util.h" 37 #include "base/mac/mac_util.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 static_cast<int64>(rect->size.height) > 73 static_cast<int64>(rect->size.height) >
71 static_cast<int64>(image_height)) 74 static_cast<int64>(image_height))
72 return false; 75 return false;
73 76
74 *dest = gfx::Rect(rect->point.x, rect->point.y, 77 *dest = gfx::Rect(rect->point.x, rect->point.y,
75 rect->size.width, rect->size.height); 78 rect->size.width, rect->size.height);
76 } 79 }
77 return true; 80 return true;
78 } 81 }
79 82
80 // Scale the rectangle, taking care to round coordinates outward so a
81 // rectangle scaled down then scaled back up by the inverse scale would
82 // fully contain the entire area affected by the original rectangle.
83 gfx::Rect ScaleRectBounds(const gfx::Rect& rect, float scale) {
84 int left = static_cast<int>(floorf(rect.x() * scale));
85 int top = static_cast<int>(floorf(rect.y() * scale));
86 int right = static_cast<int>(ceilf((rect.x() + rect.width()) * scale));
87 int bottom = static_cast<int>(ceilf((rect.y() + rect.height()) * scale));
88 return gfx::Rect(left, top, right - left, bottom - top);
89 }
90
91 // Converts BGRA <-> RGBA. 83 // Converts BGRA <-> RGBA.
92 void ConvertBetweenBGRAandRGBA(const uint32_t* input, 84 void ConvertBetweenBGRAandRGBA(const uint32_t* input,
93 int pixel_length, 85 int pixel_length,
94 uint32_t* output) { 86 uint32_t* output) {
95 for (int i = 0; i < pixel_length; i++) { 87 for (int i = 0; i < pixel_length; i++) {
96 const unsigned char* pixel_in = 88 const unsigned char* pixel_in =
97 reinterpret_cast<const unsigned char*>(&input[i]); 89 reinterpret_cast<const unsigned char*>(&input[i]);
98 unsigned char* pixel_out = reinterpret_cast<unsigned char*>(&output[i]); 90 unsigned char* pixel_out = reinterpret_cast<unsigned char*>(&output[i]);
99 pixel_out[0] = pixel_in[2]; 91 pixel_out[0] = pixel_in[2];
100 pixel_out[1] = pixel_in[1]; 92 pixel_out[1] = pixel_in[1];
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG 558 // TODO(brettw) bug 56673: do a direct memcpy instead of going through CG
567 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped. 559 // if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped.
568 560
569 CGContextDrawImage(canvas, bitmap_rect, image); 561 CGContextDrawImage(canvas, bitmap_rect, image);
570 #else 562 #else
571 gfx::Rect invalidate_rect = plugin_rect.Intersect(paint_rect); 563 gfx::Rect invalidate_rect = plugin_rect.Intersect(paint_rect);
572 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); 564 SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect);
573 SkAutoCanvasRestore auto_restore(canvas, true); 565 SkAutoCanvasRestore auto_restore(canvas, true);
574 canvas->clipRect(sk_invalidate_rect); 566 canvas->clipRect(sk_invalidate_rect);
575 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); 567 gfx::Size pixel_image_size(image_data_->width(), image_data_->height());
576 gfx::Size image_size = pixel_image_size.Scale(scale_); 568 gfx::Size image_size = gfx::ToFlooredSize(pixel_image_size.Scale(scale_));
577 569
578 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 570 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
579 if (!plugin_instance) 571 if (!plugin_instance)
580 return; 572 return;
581 if (plugin_instance->IsFullPagePlugin()) { 573 if (plugin_instance->IsFullPagePlugin()) {
582 // When we're resizing a window with a full-frame plugin, the plugin may 574 // When we're resizing a window with a full-frame plugin, the plugin may
583 // not yet have bound a new device, which will leave parts of the 575 // not yet have bound a new device, which will leave parts of the
584 // background exposed if the window is getting larger. We want this to 576 // background exposed if the window is getting larger. We want this to
585 // show white (typically less jarring) rather than black or uninitialized. 577 // show white (typically less jarring) rather than black or uninitialized.
586 // We don't do this for non-full-frame plugins since we specifically want 578 // We don't do this for non-full-frame plugins since we specifically want
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 637 }
646 638
647 // static 639 // static
648 bool PPB_Graphics2D_Impl::ConvertToLogicalPixels(float scale, 640 bool PPB_Graphics2D_Impl::ConvertToLogicalPixels(float scale,
649 gfx::Rect* op_rect, 641 gfx::Rect* op_rect,
650 gfx::Point* delta) { 642 gfx::Point* delta) {
651 if (scale == 1.0f || scale <= 0.0f) 643 if (scale == 1.0f || scale <= 0.0f)
652 return true; 644 return true;
653 645
654 gfx::Rect original_rect = *op_rect; 646 gfx::Rect original_rect = *op_rect;
655 *op_rect = ScaleRectBounds(*op_rect, scale); 647 // Take the enclosing rectangle after scaling so a rectangle scaled down then
648 // scaled back up by the inverse scale would fully contain the entire area
649 // affected by the original rectangle.
650 *op_rect = gfx::ToEnclosingRect(op_rect->Scale(scale));
656 if (delta) { 651 if (delta) {
657 gfx::Point original_delta = *delta; 652 gfx::Point original_delta = *delta;
658 float inverse_scale = 1.0f / scale; 653 float inverse_scale = 1.0f / scale;
659 *delta = delta->Scale(scale); 654 *delta = gfx::ToFlooredPoint(delta->Scale(scale));
660 if (original_rect != ScaleRectBounds(*op_rect, inverse_scale) || 655 if (original_rect != gfx::ToEnclosingRect(op_rect->Scale(inverse_scale)) ||
661 original_delta != delta->Scale(inverse_scale)) { 656 original_delta != gfx::ToFlooredPoint(delta->Scale(inverse_scale))) {
662 return false; 657 return false;
663 } 658 }
664 } 659 }
665 660
666 return true; 661 return true;
667 } 662 }
668 663
669 void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image, 664 void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image,
670 int x, int y, 665 int x, int y,
671 const gfx::Rect& src_rect, 666 const gfx::Rect& src_rect,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 } 755 }
761 756
762 bool PPB_Graphics2D_Impl::HasPendingFlush() const { 757 bool PPB_Graphics2D_Impl::HasPendingFlush() const {
763 return !unpainted_flush_callback_.is_null() || 758 return !unpainted_flush_callback_.is_null() ||
764 !painted_flush_callback_.is_null() || 759 !painted_flush_callback_.is_null() ||
765 offscreen_flush_pending_; 760 offscreen_flush_pending_;
766 } 761 }
767 762
768 } // namespace ppapi 763 } // namespace ppapi
769 } // namespace webkit 764 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/glue/webcursor_aurax11.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698