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

Unified Diff: webkit/plugins/ppapi/ppb_graphics_2d_impl.cc

Issue 10704198: Scale to DIPs in ppb_graphics2d_impl for proper invalidation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Separate bounds scale from delta scale Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/plugins/ppapi/ppb_graphics_2d_impl.h ('k') | webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
index 79821bb55a0b06764cdc9dafe0eb6aced70006ef..7b37ccf433b77760634b759cb00bd11878f130e2 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
@@ -350,6 +350,30 @@ int32_t PPB_Graphics2D_Impl::Flush(scoped_refptr<TrackedCallback> callback) {
// calls, leaving our callback stranded. So we still need to check whether
// the repainted area is visible to determine how to deal with the callback.
if (bound_instance_ && !op_rect.IsEmpty()) {
+ // Convert op_rect from context coordinates to logical pixels, taking care
+ // to include partially-covered logical pixels (aka DIPs). If the
+ // operation is a scroll, we also find out if we need to fall back to
+ // InvalidateRect due to the possibility that the scroll cannot accurately
+ // be described in logical pixels due to rounding errors.
+ bool scroll = false;
+ if (operation.type == QueuedOperation::SCROLL) {
+ if (scale_ == 1.0f) {
+ scroll = true;
Wez 2012/07/20 00:01:41 Is the float multiplication overhead sufficient to
Josh Horwich 2012/07/20 02:30:22 Done. This motivated me to refactor this section
+ } else if (scale_ > 0.0f) {
+ gfx::Rect original_rect = op_rect;
+ gfx::Point original_delta(operation.scroll_dx, operation.scroll_dy);
+ gfx::Point delta_scaled = original_delta.Scale(scale_);
+ float inverse_scale = 1.0f / scale_;
+ op_rect = ScaleRectBounds(op_rect, scale_);
+ operation.scroll_dx = delta_scaled.x();
+ operation.scroll_dy = delta_scaled.y();
Wez 2012/07/20 00:01:41 nit: Rather than copy the point back into the oper
Josh Horwich 2012/07/20 02:30:22 Done.
+ if (original_rect == ScaleRectBounds(op_rect, inverse_scale) &&
+ original_delta == delta_scaled.Scale(inverse_scale))
Wez 2012/07/20 00:01:41 nit: Put {} around the body of multi-line-conditio
Josh Horwich 2012/07/20 02:30:22 Done.
+ scroll = true;
+ }
+ } else {
+ op_rect = ScaleRectBounds(op_rect, scale_);
+ }
// Set |nothing_visible| to false if the change overlaps the visible area.
gfx::Rect visible_changed_rect =
@@ -360,7 +384,7 @@ int32_t PPB_Graphics2D_Impl::Flush(scoped_refptr<TrackedCallback> callback) {
// Notify the plugin of the entire change (op_rect), even if it is
// partially or completely off-screen.
- if (operation.type == QueuedOperation::SCROLL) {
+ if (scroll) {
bound_instance_->ScrollRect(operation.scroll_dx, operation.scroll_dy,
op_rect);
} else {
@@ -524,6 +548,10 @@ void PPB_Graphics2D_Impl::Paint(WebKit::WebCanvas* canvas,
CGContextClipToRect(canvas, bounds);
+ // TODO(jhorwich) Figure out if this code is even active anymore, and if so
+ // how to properly handle scaling.
+ DCHECK_EQ(1.0f, scale_);
+
// TODO(brettw) bug 56673: do a direct memcpy instead of going through CG
// if the is_always_opaque_ flag is set. Must ensure bitmap is still clipped.
@@ -610,6 +638,23 @@ void PPB_Graphics2D_Impl::ViewFlushedPaint() {
painted_flush_callback_.Execute(PP_OK);
}
+// static
+gfx::Rect PPB_Graphics2D_Impl::ScaleRectBounds(const gfx::Rect& rect,
+ float scale) {
+ // Scale the rectangle, taking care to round coordinates outward so a
+ // rectangle scaled down then scaled back up by the inverse scale would
+ // fully contain the entire area affected by the original rectangle.
Wez 2012/07/20 00:01:41 nit: Move this comment to the header, since it's a
Josh Horwich 2012/07/20 02:30:22 Done.
+ if (scale != 1.0f && scale > 0.0f) {
+ int left = static_cast<int>(floorf(rect.x() * scale));
+ int top = static_cast<int>(floorf(rect.y() * scale));
+ int right = static_cast<int>(ceilf((rect.x() + rect.width()) * scale));
+ int bottom = static_cast<int>(ceilf((rect.y() + rect.height()) * scale));
+ return gfx::Rect(left, top, right - left, bottom - top);
+ }
+
+ return rect;
+}
+
void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image,
int x, int y,
const gfx::Rect& src_rect,
« no previous file with comments | « webkit/plugins/ppapi/ppb_graphics_2d_impl.h ('k') | webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698