| Index: content/renderer/browser_plugin/browser_plugin_texture_provider.cc
|
| diff --git a/content/renderer/browser_plugin/browser_plugin_texture_provider.cc b/content/renderer/browser_plugin/browser_plugin_texture_provider.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ea22b374838efdd6a3c23c228f018bd24840f6ea
|
| --- /dev/null
|
| +++ b/content/renderer/browser_plugin/browser_plugin_texture_provider.cc
|
| @@ -0,0 +1,155 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/renderer/browser_plugin/browser_plugin_texture_provider.h"
|
| +
|
| +#include "base/message_loop.h"
|
| +#include "content/common/browser_plugin_messages.h"
|
| +#include "content/renderer/browser_plugin/browser_plugin_compositing_filter.h"
|
| +#include "content/renderer/browser_plugin/browser_plugin_manager.h"
|
| +#include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
|
| +#include "content/renderer/render_view_impl.h"
|
| +#include "content/renderer/render_thread_impl.h"
|
| +#include "content/renderer/gpu/compositor_thread.h"
|
| +
|
| +#include "ui/gfx/size.h"
|
| +
|
| +using WebKit::WebFloatRect;
|
| +
|
| +namespace content {
|
| +
|
| +// Called on main therad
|
| +BrowserPluginTextureProvider::BrowserPluginTextureProvider(
|
| + int instance_id,
|
| + int host_routing_id,
|
| + IPC::ChannelProxy* channel_proxy,
|
| + scoped_refptr<base::MessageLoopProxy> message_loop)
|
| + : client_(0),
|
| + filter_(0),
|
| + instance_id_(instance_id),
|
| + impl_loop_(message_loop),
|
| + channel_proxy_(channel_proxy),
|
| + host_routing_id_(host_routing_id),
|
| + texture_size_(0, 0),
|
| + pending_swap_buffers_(false),
|
| + pending_swap_buffers_surface_handle_(0),
|
| + pending_swap_buffers_route_id_(0),
|
| + pending_swap_buffers_gpu_host_id_(0) {
|
| +}
|
| +
|
| +void BrowserPluginTextureProvider::Initialize() {
|
| + SetUpFilter();
|
| +}
|
| +
|
| +BrowserPluginTextureProvider::~BrowserPluginTextureProvider() {
|
| +}
|
| +
|
| +// Called on the main thread; ends the lifetime on this thread
|
| +void BrowserPluginTextureProvider::Destroy() {
|
| + impl_loop_->PostTask(FROM_HERE, base::Bind(
|
| + &BrowserPluginTextureProvider::DestroyImpl,
|
| + base::Unretained(this)));
|
| +}
|
| +
|
| +// Called on impl thread
|
| +void BrowserPluginTextureProvider::DestroyImpl() {
|
| + DCHECK(IsOnCorrectThread());
|
| + RemoveFilter();
|
| + if (client_)
|
| + client_->stopUsingProvider();
|
| +
|
| + delete this;
|
| +}
|
| +
|
| +// Called on impl thread (we store our impl thread loop here)
|
| +void BrowserPluginTextureProvider::setTextureProviderClient(Client* client) {
|
| + DCHECK(IsOnCorrectThread());
|
| + client_ = client;
|
| + if (pending_swap_buffers_) {
|
| + OnBuffersSwapped(instance_id_,
|
| + pending_swap_buffers_surface_handle_,
|
| + pending_swap_buffers_route_id_,
|
| + pending_swap_buffers_gpu_host_id_);
|
| + pending_swap_buffers_ = false;
|
| + }
|
| +}
|
| +
|
| +// Called on impl thread
|
| +void BrowserPluginTextureProvider::OnMessageReceived(
|
| + const IPC::Message& message) {
|
| + IPC_BEGIN_MESSAGE_MAP(BrowserPluginTextureProvider, message)
|
| + IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped)
|
| + IPC_MESSAGE_HANDLER(BrowserPluginMsg_SurfaceResize, OnSurfaceResize)
|
| + IPC_END_MESSAGE_MAP()
|
| +}
|
| +
|
| +// Called on impl thread
|
| +void BrowserPluginTextureProvider::OnBuffersSwapped(int instance_id,
|
| + uint64 surface_handle,
|
| + int route_id,
|
| + int gpu_host_id) {
|
| + DCHECK(surface_handle != 0);
|
| + DCHECK(instance_id == instance_id_);
|
| + DCHECK(IsOnCorrectThread());
|
| +
|
| + if (!client_) {
|
| + pending_swap_buffers_ = true;
|
| + pending_swap_buffers_surface_handle_ = surface_handle;
|
| + pending_swap_buffers_route_id_ = route_id;
|
| + pending_swap_buffers_gpu_host_id_ = gpu_host_id;
|
| + return;
|
| + }
|
| +
|
| + client_->didReceiveFrame(surface_handle);
|
| + Send(new BrowserPluginHostMsg_BuffersSwappedACK(
|
| + host_routing_id_,
|
| + route_id,
|
| + gpu_host_id,
|
| + client_->insertSyncPoint()));
|
| +}
|
| +
|
| +// Called on impl thread
|
| +void BrowserPluginTextureProvider::OnSurfaceResize(
|
| + int instance_id,
|
| + const gfx::Size& size) {
|
| + DCHECK(instance_id == instance_id_);
|
| + DCHECK(IsOnCorrectThread());
|
| + // TODO: figure out what resizing behaviour is needed here.
|
| + texture_size_ = size;
|
| + if (client_)
|
| + client_->didUpdateTextureParams(true, true, WebFloatRect(0, 0, 1, 1));
|
| +}
|
| +
|
| +// Called on any thread
|
| +bool BrowserPluginTextureProvider::Send(IPC::Message* message) {
|
| + DCHECK(channel_proxy_);
|
| + return channel_proxy_->Send(message);
|
| +}
|
| +
|
| +// Called on impl thread to create a new filter and attach it to the
|
| +// ChannelProxy
|
| +void BrowserPluginTextureProvider::SetUpFilter() {
|
| + DCHECK(channel_proxy_);
|
| +
|
| + filter_ = new BrowserPluginCompositingFilter(
|
| + impl_loop_,
|
| + instance_id_,
|
| + base::Bind(
|
| + &BrowserPluginTextureProvider::OnMessageReceived,
|
| + base::Unretained(this)));
|
| +
|
| + channel_proxy_->AddFilter(filter_);
|
| +}
|
| +
|
| +void BrowserPluginTextureProvider::RemoveFilter() {
|
| + if (filter_) {
|
| + channel_proxy_->RemoveFilter(filter_);
|
| + }
|
| +}
|
| +
|
| +bool BrowserPluginTextureProvider::IsOnCorrectThread() {
|
| + return impl_loop_ == base::MessageLoopProxy::current();
|
| +}
|
| +
|
| +} // namespace content
|
|
|