Index: content/renderer/pepper/pepper_graphics_2d_host.cc |
diff --git a/content/renderer/pepper/pepper_graphics_2d_host.cc b/content/renderer/pepper/pepper_graphics_2d_host.cc |
index f1d719748d3cf578a0009ada12d35f16f0dacf6b..31cdc6a872d577def0f9de4cff7dde8927346a74 100644 |
--- a/content/renderer/pepper/pepper_graphics_2d_host.cc |
+++ b/content/renderer/pepper/pepper_graphics_2d_host.cc |
@@ -8,6 +8,8 @@ |
#include "base/debug/trace_event.h" |
#include "base/logging.h" |
#include "base/message_loop/message_loop.h" |
+#include "cc/resources/texture_mailbox.h" |
+#include "content/public/renderer/render_thread.h" |
#include "content/public/renderer/renderer_ppapi_host.h" |
#include "content/renderer/pepper/common.h" |
#include "content/renderer/pepper/gfx_conversion.h" |
@@ -187,8 +189,8 @@ PepperGraphics2DHost::PepperGraphics2DHost(RendererPpapiHost* host, |
is_always_opaque_(false), |
scale_(1.0f), |
weak_ptr_factory_(this), |
- is_running_in_process_(host->IsRunningInProcess()) { |
-} |
+ is_running_in_process_(host->IsRunningInProcess()), |
+ texture_mailbox_modified_(true) {} |
PepperGraphics2DHost::~PepperGraphics2DHost() { |
// Unbind from the instance when destroyed if we're still bound. |
@@ -312,6 +314,8 @@ bool PepperGraphics2DHost::BindToInstance( |
new_instance->InvalidateRect(gfx::Rect()); |
} |
+ texture_mailbox_modified_ = true; |
+ |
bound_instance_ = new_instance; |
return true; |
} |
@@ -551,6 +555,37 @@ int32_t PepperGraphics2DHost::OnHostMsgReadImageData( |
return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED; |
} |
+void ReleaseCallback(scoped_ptr<base::SharedMemory> memory, |
+ unsigned sync_point, |
+ bool lost_resource) {} |
+ |
+bool PepperGraphics2DHost::PrepareTextureMailbox(cc::TextureMailbox* mailbox) { |
+ if (!texture_mailbox_modified_) |
+ return false; |
+ // TODO(jbauman): Send image_data_ through mailbox to avoid copy. |
+ gfx::Size pixel_image_size(image_data_->width(), image_data_->height()); |
+ int buffer_size = pixel_image_size.GetArea() * 4; |
+ scoped_ptr<base::SharedMemory> memory = |
+ RenderThread::Get()->HostAllocateSharedMemoryBuffer(buffer_size); |
+ if (!memory || !memory->Map(buffer_size)) |
+ return false; |
+ void* src = image_data_->Map(); |
+ memcpy(memory->memory(), src, buffer_size); |
+ image_data_->Unmap(); |
+ |
+ base::SharedMemory* mem = memory.get(); |
+ *mailbox = |
+ cc::TextureMailbox(mem, |
+ pixel_image_size, |
+ base::Bind(&ReleaseCallback, base::Passed(&memory))); |
+ texture_mailbox_modified_ = false; |
+ return true; |
+} |
+ |
+void PepperGraphics2DHost::AttachedToNewLayer() { |
+ texture_mailbox_modified_ = true; |
+} |
+ |
int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) { |
bool done_replace_contents = false; |
bool no_update_visible = true; |
@@ -616,6 +651,7 @@ int32_t PepperGraphics2DHost::Flush(PP_Resource* old_image_data) { |
} else { |
bound_instance_->InvalidateRect(op_rect); |
} |
+ texture_mailbox_modified_ = true; |
} |
} |
queued_operations_.clear(); |