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

Side by Side Diff: content/renderer/pepper/pepper_graphics_2d_host.cc

Issue 600953003: Cache cc::SharedBitmaps used by PepperGraphics2DHost to upload (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
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 "content/renderer/pepper/pepper_graphics_2d_host.h" 5 #include "content/renderer/pepper/pepper_graphics_2d_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 // When the device is detached, we'll not get any more paint callbacks so 300 // When the device is detached, we'll not get any more paint callbacks so
301 // we need to clear the list, but we still want to issue any pending 301 // we need to clear the list, but we still want to issue any pending
302 // callbacks to the plugin. 302 // callbacks to the plugin.
303 if (need_flush_ack_) 303 if (need_flush_ack_)
304 ScheduleOffscreenFlushAck(); 304 ScheduleOffscreenFlushAck();
305 } else { 305 } else {
306 // Devices being replaced, redraw the plugin. 306 // Devices being replaced, redraw the plugin.
307 new_instance->InvalidateRect(gfx::Rect()); 307 new_instance->InvalidateRect(gfx::Rect());
308 } 308 }
309 309
310 cached_bitmap_.reset();
310 texture_mailbox_modified_ = true; 311 texture_mailbox_modified_ = true;
311 312
312 bound_instance_ = new_instance; 313 bound_instance_ = new_instance;
313 return true; 314 return true;
314 } 315 }
315 316
316 // The |backing_bitmap| must be clipped to the |plugin_rect| to avoid painting 317 // The |backing_bitmap| must be clipped to the |plugin_rect| to avoid painting
317 // outside the plugin area. This can happen if the plugin has been resized since 318 // outside the plugin area. This can happen if the plugin has been resized since
318 // PaintImageData verified the image is within the plugin size. 319 // PaintImageData verified the image is within the plugin size.
319 void PepperGraphics2DHost::Paint(blink::WebCanvas* canvas, 320 void PepperGraphics2DHost::Paint(blink::WebCanvas* canvas,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 PPB_ImageData_Impl* PepperGraphics2DHost::ImageData() { 402 PPB_ImageData_Impl* PepperGraphics2DHost::ImageData() {
402 return image_data_.get(); 403 return image_data_.get();
403 } 404 }
404 405
405 gfx::Size PepperGraphics2DHost::Size() const { 406 gfx::Size PepperGraphics2DHost::Size() const {
406 if (!image_data_.get()) 407 if (!image_data_.get())
407 return gfx::Size(); 408 return gfx::Size();
408 return gfx::Size(image_data_->width(), image_data_->height()); 409 return gfx::Size(image_data_->width(), image_data_->height());
409 } 410 }
410 411
412 void PepperGraphics2DHost::ClearCache() {
413 cached_bitmap_.reset();
414 }
415
411 int32_t PepperGraphics2DHost::OnHostMsgPaintImageData( 416 int32_t PepperGraphics2DHost::OnHostMsgPaintImageData(
412 ppapi::host::HostMessageContext* context, 417 ppapi::host::HostMessageContext* context,
413 const ppapi::HostResource& image_data, 418 const ppapi::HostResource& image_data,
414 const PP_Point& top_left, 419 const PP_Point& top_left,
415 bool src_rect_specified, 420 bool src_rect_specified,
416 const PP_Rect& src_rect) { 421 const PP_Rect& src_rect) {
417 EnterResourceNoLock<PPB_ImageData_API> enter(image_data.host_resource(), 422 EnterResourceNoLock<PPB_ImageData_API> enter(image_data.host_resource(),
418 true); 423 true);
419 if (enter.failed()) 424 if (enter.failed())
420 return PP_ERROR_BADRESOURCE; 425 return PP_ERROR_BADRESOURCE;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 } 545 }
541 546
542 int32_t PepperGraphics2DHost::OnHostMsgReadImageData( 547 int32_t PepperGraphics2DHost::OnHostMsgReadImageData(
543 ppapi::host::HostMessageContext* context, 548 ppapi::host::HostMessageContext* context,
544 PP_Resource image, 549 PP_Resource image,
545 const PP_Point& top_left) { 550 const PP_Point& top_left) {
546 context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck(); 551 context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck();
547 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED; 552 return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED;
548 } 553 }
549 554
550 void ReleaseCallback(scoped_ptr<cc::SharedBitmap> bitmap, 555 void PepperGraphics2DHost::ReleaseCallback(scoped_ptr<cc::SharedBitmap> bitmap,
551 uint32 sync_point, 556 const gfx::Size& bitmap_size,
552 bool lost_resource) {} 557 uint32 sync_point,
558 bool lost_resource) {
559 cached_bitmap_.reset();
560 // Only keep around a cached bitmap if the plugin is currently drawing (has
561 // need_flush_ack_ set).
562 if (need_flush_ack_ && bound_instance_)
563 cached_bitmap_ = bitmap.Pass();
564 cached_bitmap_size_ = bitmap_size;
565 }
553 566
554 bool PepperGraphics2DHost::PrepareTextureMailbox( 567 bool PepperGraphics2DHost::PrepareTextureMailbox(
555 cc::TextureMailbox* mailbox, 568 cc::TextureMailbox* mailbox,
556 scoped_ptr<cc::SingleReleaseCallback>* release_callback) { 569 scoped_ptr<cc::SingleReleaseCallback>* release_callback) {
557 if (!texture_mailbox_modified_) 570 if (!texture_mailbox_modified_)
558 return false; 571 return false;
559 // TODO(jbauman): Send image_data_ through mailbox to avoid copy. 572 // TODO(jbauman): Send image_data_ through mailbox to avoid copy.
560 gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); 573 gfx::Size pixel_image_size(image_data_->width(), image_data_->height());
561 scoped_ptr<cc::SharedBitmap> shared_bitmap = 574 scoped_ptr<cc::SharedBitmap> shared_bitmap;
562 RenderThreadImpl::current() 575 if (cached_bitmap_) {
563 ->shared_bitmap_manager() 576 if (cached_bitmap_size_ == pixel_image_size)
564 ->AllocateSharedBitmap(pixel_image_size); 577 shared_bitmap = cached_bitmap_.Pass();
578 else
579 cached_bitmap_.reset();
580 }
581 if (!shared_bitmap) {
582 shared_bitmap = RenderThreadImpl::current()
583 ->shared_bitmap_manager()
584 ->AllocateSharedBitmap(pixel_image_size);
585 }
565 if (!shared_bitmap) 586 if (!shared_bitmap)
566 return false; 587 return false;
567 void* src = image_data_->Map(); 588 void* src = image_data_->Map();
568 memcpy(shared_bitmap->pixels(), 589 memcpy(shared_bitmap->pixels(),
569 src, 590 src,
570 cc::SharedBitmap::CheckedSizeInBytes(pixel_image_size)); 591 cc::SharedBitmap::CheckedSizeInBytes(pixel_image_size));
571 image_data_->Unmap(); 592 image_data_->Unmap();
572 593
573 *mailbox = cc::TextureMailbox(shared_bitmap->memory(), pixel_image_size); 594 *mailbox = cc::TextureMailbox(shared_bitmap->memory(), pixel_image_size);
574 *release_callback = cc::SingleReleaseCallback::Create( 595 *release_callback = cc::SingleReleaseCallback::Create(
575 base::Bind(&ReleaseCallback, base::Passed(&shared_bitmap))); 596 base::Bind(&PepperGraphics2DHost::ReleaseCallback,
597 this->AsWeakPtr(),
598 base::Passed(&shared_bitmap),
599 pixel_image_size));
576 texture_mailbox_modified_ = false; 600 texture_mailbox_modified_ = false;
577 return true; 601 return true;
578 } 602 }
579 603
580 void PepperGraphics2DHost::AttachedToNewLayer() { 604 void PepperGraphics2DHost::AttachedToNewLayer() {
581 texture_mailbox_modified_ = true; 605 texture_mailbox_modified_ = true;
582 } 606 }
583 607
584 int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) { 608 int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) {
585 bool done_replace_contents = false; 609 bool done_replace_contents = false;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 gfx::Point inverse_scaled_point = 814 gfx::Point inverse_scaled_point =
791 gfx::ToFlooredPoint(gfx::ScalePoint(*delta, inverse_scale)); 815 gfx::ToFlooredPoint(gfx::ScalePoint(*delta, inverse_scale));
792 if (original_delta != inverse_scaled_point) 816 if (original_delta != inverse_scaled_point)
793 return false; 817 return false;
794 } 818 }
795 819
796 return true; 820 return true;
797 } 821 }
798 822
799 } // namespace content 823 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_graphics_2d_host.h ('k') | content/renderer/pepper/pepper_plugin_instance_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698