Commit 4d6eee4b authored by jbauman's avatar jbauman Committed by Commit bot

Cache cc::SharedBitmaps used by PepperGraphics2DHost to upload

Caching these saves time recreating and remapping them.

Review URL: https://codereview.chromium.org/600953003

Cr-Commit-Position: refs/heads/master@{#296778}
parent d505f246
...@@ -307,6 +307,7 @@ bool PepperGraphics2DHost::BindToInstance( ...@@ -307,6 +307,7 @@ bool PepperGraphics2DHost::BindToInstance(
new_instance->InvalidateRect(gfx::Rect()); new_instance->InvalidateRect(gfx::Rect());
} }
cached_bitmap_.reset();
texture_mailbox_modified_ = true; texture_mailbox_modified_ = true;
bound_instance_ = new_instance; bound_instance_ = new_instance;
...@@ -408,6 +409,10 @@ gfx::Size PepperGraphics2DHost::Size() const { ...@@ -408,6 +409,10 @@ gfx::Size PepperGraphics2DHost::Size() const {
return gfx::Size(image_data_->width(), image_data_->height()); return gfx::Size(image_data_->width(), image_data_->height());
} }
void PepperGraphics2DHost::ClearCache() {
cached_bitmap_.reset();
}
int32_t PepperGraphics2DHost::OnHostMsgPaintImageData( int32_t PepperGraphics2DHost::OnHostMsgPaintImageData(
ppapi::host::HostMessageContext* context, ppapi::host::HostMessageContext* context,
const ppapi::HostResource& image_data, const ppapi::HostResource& image_data,
...@@ -547,9 +552,17 @@ int32_t PepperGraphics2DHost::OnHostMsgReadImageData( ...@@ -547,9 +552,17 @@ int32_t PepperGraphics2DHost::OnHostMsgReadImageData(
return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED; return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED;
} }
void ReleaseCallback(scoped_ptr<cc::SharedBitmap> bitmap, void PepperGraphics2DHost::ReleaseCallback(scoped_ptr<cc::SharedBitmap> bitmap,
uint32 sync_point, const gfx::Size& bitmap_size,
bool lost_resource) {} uint32 sync_point,
bool lost_resource) {
cached_bitmap_.reset();
// Only keep around a cached bitmap if the plugin is currently drawing (has
// need_flush_ack_ set).
if (need_flush_ack_ && bound_instance_)
cached_bitmap_ = bitmap.Pass();
cached_bitmap_size_ = bitmap_size;
}
bool PepperGraphics2DHost::PrepareTextureMailbox( bool PepperGraphics2DHost::PrepareTextureMailbox(
cc::TextureMailbox* mailbox, cc::TextureMailbox* mailbox,
...@@ -558,10 +571,18 @@ bool PepperGraphics2DHost::PrepareTextureMailbox( ...@@ -558,10 +571,18 @@ bool PepperGraphics2DHost::PrepareTextureMailbox(
return false; return false;
// TODO(jbauman): Send image_data_ through mailbox to avoid copy. // TODO(jbauman): Send image_data_ through mailbox to avoid copy.
gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); gfx::Size pixel_image_size(image_data_->width(), image_data_->height());
scoped_ptr<cc::SharedBitmap> shared_bitmap = scoped_ptr<cc::SharedBitmap> shared_bitmap;
RenderThreadImpl::current() if (cached_bitmap_) {
->shared_bitmap_manager() if (cached_bitmap_size_ == pixel_image_size)
->AllocateSharedBitmap(pixel_image_size); shared_bitmap = cached_bitmap_.Pass();
else
cached_bitmap_.reset();
}
if (!shared_bitmap) {
shared_bitmap = RenderThreadImpl::current()
->shared_bitmap_manager()
->AllocateSharedBitmap(pixel_image_size);
}
if (!shared_bitmap) if (!shared_bitmap)
return false; return false;
void* src = image_data_->Map(); void* src = image_data_->Map();
...@@ -572,7 +593,10 @@ bool PepperGraphics2DHost::PrepareTextureMailbox( ...@@ -572,7 +593,10 @@ bool PepperGraphics2DHost::PrepareTextureMailbox(
*mailbox = cc::TextureMailbox(shared_bitmap->memory(), pixel_image_size); *mailbox = cc::TextureMailbox(shared_bitmap->memory(), pixel_image_size);
*release_callback = cc::SingleReleaseCallback::Create( *release_callback = cc::SingleReleaseCallback::Create(
base::Bind(&ReleaseCallback, base::Passed(&shared_bitmap))); base::Bind(&PepperGraphics2DHost::ReleaseCallback,
this->AsWeakPtr(),
base::Passed(&shared_bitmap),
pixel_image_size));
texture_mailbox_modified_ = false; texture_mailbox_modified_ = false;
return true; return true;
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "ui/gfx/size.h" #include "ui/gfx/size.h"
namespace cc { namespace cc {
class SharedBitmap;
class SingleReleaseCallback; class SingleReleaseCallback;
class TextureMailbox; class TextureMailbox;
} }
...@@ -85,6 +86,8 @@ class CONTENT_EXPORT PepperGraphics2DHost ...@@ -85,6 +86,8 @@ class CONTENT_EXPORT PepperGraphics2DHost
PPB_ImageData_Impl* ImageData(); PPB_ImageData_Impl* ImageData();
gfx::Size Size() const; gfx::Size Size() const;
void ClearCache();
private: private:
PepperGraphics2DHost(RendererPpapiHost* host, PepperGraphics2DHost(RendererPpapiHost* host,
PP_Instance instance, PP_Instance instance,
...@@ -157,6 +160,11 @@ class CONTENT_EXPORT PepperGraphics2DHost ...@@ -157,6 +160,11 @@ class CONTENT_EXPORT PepperGraphics2DHost
gfx::Rect* op_rect, gfx::Rect* op_rect,
gfx::Point* delta); gfx::Point* delta);
void ReleaseCallback(scoped_ptr<cc::SharedBitmap> bitmap,
const gfx::Size& bitmap_size,
uint32 sync_point,
bool lost_resource);
RendererPpapiHost* renderer_ppapi_host_; RendererPpapiHost* renderer_ppapi_host_;
scoped_refptr<PPB_ImageData_Impl> image_data_; scoped_refptr<PPB_ImageData_Impl> image_data_;
...@@ -193,6 +201,11 @@ class CONTENT_EXPORT PepperGraphics2DHost ...@@ -193,6 +201,11 @@ class CONTENT_EXPORT PepperGraphics2DHost
bool texture_mailbox_modified_; bool texture_mailbox_modified_;
bool is_using_texture_layer_; bool is_using_texture_layer_;
// This is a bitmap that was recently released by the compositor and may be
// used to transfer bytes to the compositor again.
scoped_ptr<cc::SharedBitmap> cached_bitmap_;
gfx::Size cached_bitmap_size_;
friend class PepperGraphics2DHostTest; friend class PepperGraphics2DHostTest;
DISALLOW_COPY_AND_ASSIGN(PepperGraphics2DHost); DISALLOW_COPY_AND_ASSIGN(PepperGraphics2DHost);
}; };
......
...@@ -1701,6 +1701,12 @@ void PepperPluginInstanceImpl::SendDidChangeView() { ...@@ -1701,6 +1701,12 @@ void PepperPluginInstanceImpl::SendDidChangeView() {
UpdateLayerTransform(); UpdateLayerTransform();
if (bound_graphics_2d_platform_ &&
(!view_data_.is_page_visible ||
PP_ToGfxRect(view_data_.clip_rect).IsEmpty())) {
bound_graphics_2d_platform_->ClearCache();
}
// It's possible that Delete() has been called but the renderer hasn't // It's possible that Delete() has been called but the renderer hasn't
// released its reference to this object yet. // released its reference to this object yet.
if (instance_interface_) { if (instance_interface_) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment