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

Side by Side Diff: webkit/glue/plugins/pepper_graphics_2d.cc

Issue 4365001: Use optimized scrolling for pepper plugins. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 1 month 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/glue/plugins/pepper_graphics_2d.h" 5 #include "webkit/glue/plugins/pepper_graphics_2d.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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 int32_t Graphics2D::Flush(const PP_CompletionCallback& callback) { 327 int32_t Graphics2D::Flush(const PP_CompletionCallback& callback) {
328 // Don't allow more than one pending flush at a time. 328 // Don't allow more than one pending flush at a time.
329 if (HasPendingFlush()) 329 if (HasPendingFlush())
330 return PP_ERROR_INPROGRESS; 330 return PP_ERROR_INPROGRESS;
331 331
332 // TODO(brettw) check that the current thread is not the main one and 332 // TODO(brettw) check that the current thread is not the main one and
333 // implement blocking flushes in this case. 333 // implement blocking flushes in this case.
334 if (!callback.func) 334 if (!callback.func)
335 return PP_ERROR_BADARGUMENT; 335 return PP_ERROR_BADARGUMENT;
336 336
337 gfx::Rect changed_rect; 337 bool nothing_visible = true;
338 for (size_t i = 0; i < queued_operations_.size(); i++) { 338 for (size_t i = 0; i < queued_operations_.size(); i++) {
339 QueuedOperation& operation = queued_operations_[i]; 339 QueuedOperation& operation = queued_operations_[i];
340 gfx::Rect op_rect; 340 gfx::Rect op_rect;
341 switch (operation.type) { 341 switch (operation.type) {
342 case QueuedOperation::PAINT: 342 case QueuedOperation::PAINT:
343 ExecutePaintImageData(operation.paint_image, 343 ExecutePaintImageData(operation.paint_image,
344 operation.paint_x, operation.paint_y, 344 operation.paint_x, operation.paint_y,
345 operation.paint_src_rect, 345 operation.paint_src_rect,
346 &op_rect); 346 &op_rect);
347 break; 347 break;
348 case QueuedOperation::SCROLL: 348 case QueuedOperation::SCROLL:
349 ExecuteScroll(operation.scroll_clip_rect, 349 ExecuteScroll(operation.scroll_clip_rect,
350 operation.scroll_dx, operation.scroll_dy, 350 operation.scroll_dx, operation.scroll_dy,
351 &op_rect); 351 &op_rect);
352 break; 352 break;
353 case QueuedOperation::REPLACE: 353 case QueuedOperation::REPLACE:
354 ExecuteReplaceContents(operation.replace_image, &op_rect); 354 ExecuteReplaceContents(operation.replace_image, &op_rect);
355 break; 355 break;
356 } 356 }
357 changed_rect = changed_rect.Union(op_rect); 357
358 // We need the rect to be in terms of the current clip rect of the plugin
359 // since that's what will actually be painted. If we issue an invalidate
360 // for a clipped-out region, WebKit will do nothing and we won't get any
361 // ViewInitiatedPaint/ViewFlushedPaint calls, leaving our callback stranded.
362 gfx::Rect visible_changed_rect;
363 if (bound_instance_ && !op_rect.IsEmpty())
364 visible_changed_rect = bound_instance_->clip().Intersect(op_rect);
365
366 if (bound_instance_ && !visible_changed_rect.IsEmpty()) {
367 if (operation.type == QueuedOperation::SCROLL) {
368 bound_instance_->ScrollRect(operation.scroll_dx, operation.scroll_dy,
369 visible_changed_rect);
370 } else {
371 bound_instance_->InvalidateRect(visible_changed_rect);
372 }
373 nothing_visible = false;
374 }
358 } 375 }
359 queued_operations_.clear(); 376 queued_operations_.clear();
360 flushed_any_data_ = true; 377 flushed_any_data_ = true;
361 378
362 // We need the rect to be in terms of the current clip rect of the plugin 379 if (nothing_visible) {
363 // since that's what will actually be painted. If we issue an invalidate
364 // for a clipped-out region, WebKit will do nothing and we won't get any
365 // ViewInitiatedPaint/ViewFlushedPaint calls, leaving our callback stranded.
366 gfx::Rect visible_changed_rect;
367 if (bound_instance_ && !changed_rect.IsEmpty())
368 visible_changed_rect = bound_instance_->clip().Intersect(changed_rect);
369
370 if (bound_instance_ && !visible_changed_rect.IsEmpty()) {
371 unpainted_flush_callback_.Set(callback);
372 bound_instance_->InvalidateRect(visible_changed_rect);
373 } else {
374 // There's nothing visible to invalidate so just schedule the callback to 380 // There's nothing visible to invalidate so just schedule the callback to
375 // execute in the next round of the message loop. 381 // execute in the next round of the message loop.
376 ScheduleOffscreenCallback(FlushCallbackData(callback)); 382 ScheduleOffscreenCallback(FlushCallbackData(callback));
383 } else {
384 unpainted_flush_callback_.Set(callback);
377 } 385 }
378 return PP_ERROR_WOULDBLOCK; 386 return PP_ERROR_WOULDBLOCK;
379 } 387 }
380 388
381 bool Graphics2D::ReadImageData(PP_Resource image, 389 bool Graphics2D::ReadImageData(PP_Resource image,
382 const PP_Point* top_left) { 390 const PP_Point* top_left) {
383 // Get and validate the image object to paint into. 391 // Get and validate the image object to paint into.
384 scoped_refptr<ImageData> image_resource(Resource::GetAs<ImageData>(image)); 392 scoped_refptr<ImageData> image_resource(Resource::GetAs<ImageData>(image));
385 if (!image_resource) 393 if (!image_resource)
386 return false; 394 return false;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 data.Execute(PP_OK); 627 data.Execute(PP_OK);
620 } 628 }
621 629
622 bool Graphics2D::HasPendingFlush() const { 630 bool Graphics2D::HasPendingFlush() const {
623 return !unpainted_flush_callback_.is_null() || 631 return !unpainted_flush_callback_.is_null() ||
624 !painted_flush_callback_.is_null() || 632 !painted_flush_callback_.is_null() ||
625 offscreen_flush_pending_; 633 offscreen_flush_pending_;
626 } 634 }
627 635
628 } // namespace pepper 636 } // namespace pepper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698