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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_texture_provider.cc

Issue 11359024: Texture provider to feed data to the impl side thread for webview compositing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/renderer/browser_plugin/browser_plugin_texture_provider.h"
6
7 #include "base/message_loop.h"
8 #include "content/common/browser_plugin_messages.h"
9 #include "content/renderer/browser_plugin/browser_plugin_compositing_filter.h"
10 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
11 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
12 #include "content/renderer/render_view_impl.h"
13 #include "content/renderer/render_thread_impl.h"
14 #include "content/renderer/gpu/compositor_thread.h"
15
16 #include "ui/gfx/size.h"
17
18 using WebKit::WebFloatRect;
19
20 namespace content {
21
22 // Called on main therad
23 BrowserPluginTextureProvider::BrowserPluginTextureProvider(
24 int instance_id,
25 int host_routing_id,
26 IPC::ChannelProxy* channel_proxy,
27 scoped_refptr<base::MessageLoopProxy> message_loop)
28 : client_(0),
29 filter_(0),
30 instance_id_(instance_id),
31 impl_loop_(message_loop),
32 channel_proxy_(channel_proxy),
33 host_routing_id_(host_routing_id),
34 texture_size_(0, 0),
35 pending_swap_buffers_(false),
36 pending_swap_buffers_surface_handle_(0),
37 pending_swap_buffers_route_id_(0),
38 pending_swap_buffers_gpu_host_id_(0) {
39 }
40
41 void BrowserPluginTextureProvider::Initialize() {
42 SetUpFilter();
43 }
44
45 BrowserPluginTextureProvider::~BrowserPluginTextureProvider() {
46 }
47
48 // Called on the main thread; ends the lifetime on this thread
49 void BrowserPluginTextureProvider::Destroy() {
50 impl_loop_->PostTask(FROM_HERE, base::Bind(
51 &BrowserPluginTextureProvider::DestroyImpl,
52 base::Unretained(this)));
53 }
54
55 // Called on impl thread
56 void BrowserPluginTextureProvider::DestroyImpl() {
57 DCHECK(IsOnCorrectThread());
58 RemoveFilter();
59 if (client_)
60 client_->stopUsingProvider();
61
62 delete this;
63 }
64
65 // Called on impl thread (we store our impl thread loop here)
66 void BrowserPluginTextureProvider::setTextureProviderClient(Client* client) {
67 DCHECK(IsOnCorrectThread());
68 client_ = client;
69 if (pending_swap_buffers_) {
70 OnBuffersSwapped(instance_id_,
71 pending_swap_buffers_surface_handle_,
72 pending_swap_buffers_route_id_,
73 pending_swap_buffers_gpu_host_id_);
74 pending_swap_buffers_ = false;
75 }
76 }
77
78 // Called on impl thread
79 void BrowserPluginTextureProvider::OnMessageReceived(
80 const IPC::Message& message) {
81 IPC_BEGIN_MESSAGE_MAP(BrowserPluginTextureProvider, message)
82 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped)
83 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SurfaceResize, OnSurfaceResize)
84 IPC_END_MESSAGE_MAP()
85 }
86
87 // Called on impl thread
88 void BrowserPluginTextureProvider::OnBuffersSwapped(int instance_id,
89 uint64 surface_handle,
90 int route_id,
91 int gpu_host_id) {
92 DCHECK(surface_handle != 0);
93 DCHECK(instance_id == instance_id_);
94 DCHECK(IsOnCorrectThread());
95
96 if (!client_) {
97 pending_swap_buffers_ = true;
98 pending_swap_buffers_surface_handle_ = surface_handle;
99 pending_swap_buffers_route_id_ = route_id;
100 pending_swap_buffers_gpu_host_id_ = gpu_host_id;
101 return;
102 }
103
104 client_->didReceiveFrame(surface_handle);
105 Send(new BrowserPluginHostMsg_BuffersSwappedACK(
106 host_routing_id_,
107 route_id,
108 gpu_host_id,
109 client_->insertSyncPoint()));
110 }
111
112 // Called on impl thread
113 void BrowserPluginTextureProvider::OnSurfaceResize(
114 int instance_id,
115 const gfx::Size& size) {
116 DCHECK(instance_id == instance_id_);
117 DCHECK(IsOnCorrectThread());
118 // TODO: figure out what resizing behaviour is needed here.
119 texture_size_ = size;
120 if (client_)
121 client_->didUpdateTextureParams(true, true, WebFloatRect(0, 0, 1, 1));
122 }
123
124 // Called on any thread
125 bool BrowserPluginTextureProvider::Send(IPC::Message* message) {
126 DCHECK(channel_proxy_);
127 return channel_proxy_->Send(message);
128 }
129
130 // Called on impl thread to create a new filter and attach it to the
131 // ChannelProxy
132 void BrowserPluginTextureProvider::SetUpFilter() {
133 DCHECK(channel_proxy_);
134
135 filter_ = new BrowserPluginCompositingFilter(
136 impl_loop_,
137 instance_id_,
138 base::Bind(
139 &BrowserPluginTextureProvider::OnMessageReceived,
140 base::Unretained(this)));
141
142 channel_proxy_->AddFilter(filter_);
143 }
144
145 void BrowserPluginTextureProvider::RemoveFilter() {
146 if (filter_) {
147 channel_proxy_->RemoveFilter(filter_);
148 }
149 }
150
151 bool BrowserPluginTextureProvider::IsOnCorrectThread() {
152 return impl_loop_ == base::MessageLoopProxy::current();
153 }
154
155 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698