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

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

Issue 12440005: Use gpu::Mailbox in IPCs instead of std::string (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/browser_plugin/browser_plugin_compositing_helper.h" 5 #include "content/renderer/browser_plugin/browser_plugin_compositing_helper.h"
6 6
7 #include "cc/context_provider.h" 7 #include "cc/context_provider.h"
8 #include "cc/solid_color_layer.h" 8 #include "cc/solid_color_layer.h"
9 #include "cc/texture_layer.h" 9 #include "cc/texture_layer.h"
10 #include "content/common/browser_plugin/browser_plugin_messages.h" 10 #include "content/common/browser_plugin/browser_plugin_messages.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 57
58 // If we have a mailbox that was freed up from the compositor, 58 // If we have a mailbox that was freed up from the compositor,
59 // but we are not expected to return it to the guest renderer 59 // but we are not expected to return it to the guest renderer
60 // via an ACK, we should free it because we now own it. 60 // via an ACK, we should free it because we now own it.
61 // To free the mailbox memory, we need a context to consume it 61 // To free the mailbox memory, we need a context to consume it
62 // into a texture ID and then delete this texture ID. 62 // into a texture ID and then delete this texture ID.
63 // We use a shared graphics context accessible from the main 63 // We use a shared graphics context accessible from the main
64 // thread to do it. 64 // thread to do it.
65 void BrowserPluginCompositingHelper::FreeMailboxMemory( 65 void BrowserPluginCompositingHelper::FreeMailboxMemory(
66 const std::string& mailbox_name, 66 const gpu::Mailbox& mailbox_name,
67 unsigned sync_point) { 67 unsigned sync_point) {
68 if (mailbox_name.empty()) 68 if (mailbox_name.IsZero())
69 return; 69 return;
70 70
71 scoped_refptr<cc::ContextProvider> context_provider = 71 scoped_refptr<cc::ContextProvider> context_provider =
72 RenderThreadImpl::current()->OffscreenContextProviderForMainThread(); 72 RenderThreadImpl::current()->OffscreenContextProviderForMainThread();
73 if (!context_provider->InitializeOnMainThread()) 73 if (!context_provider->InitializeOnMainThread())
74 return; 74 return;
75 if (!context_provider->BindToCurrentThread()) 75 if (!context_provider->BindToCurrentThread())
76 return; 76 return;
77 77
78 WebKit::WebGraphicsContext3D *context = context_provider->Context3d(); 78 WebKit::WebGraphicsContext3D *context = context_provider->Context3d();
79 // When a buffer is released from the compositor, we also get a 79 // When a buffer is released from the compositor, we also get a
80 // sync point that specifies when in the command buffer 80 // sync point that specifies when in the command buffer
81 // it's safe to use it again. 81 // it's safe to use it again.
82 // If the sync point is non-zero, we need to tell our context 82 // If the sync point is non-zero, we need to tell our context
83 // to wait until this sync point is reached before we can safely 83 // to wait until this sync point is reached before we can safely
84 // delete the buffer. 84 // delete the buffer.
85 if (sync_point) 85 if (sync_point)
86 context->waitSyncPoint(sync_point); 86 context->waitSyncPoint(sync_point);
87 87
88 unsigned texture_id = context->createTexture(); 88 unsigned texture_id = context->createTexture();
89 context->bindTexture(GL_TEXTURE_2D, texture_id); 89 context->bindTexture(GL_TEXTURE_2D, texture_id);
90 context->consumeTextureCHROMIUM( 90 context->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox_name.name);
91 GL_TEXTURE_2D,
92 reinterpret_cast<const int8*>(mailbox_name.data()));
93 context->deleteTexture(texture_id); 91 context->deleteTexture(texture_id);
94 } 92 }
95 93
96 void BrowserPluginCompositingHelper::MailboxReleased( 94 void BrowserPluginCompositingHelper::MailboxReleased(
97 const std::string& mailbox_name, 95 const gpu::Mailbox& mailbox_name,
98 int gpu_route_id, 96 int gpu_route_id,
99 int gpu_host_id, 97 int gpu_host_id,
100 unsigned sync_point) { 98 unsigned sync_point) {
101 // This means the GPU process crashed and we have nothing further to do. 99 // This means the GPU process crashed and we have nothing further to do.
102 // Nobody is expecting an ACK and the buffer doesn't need to be deleted 100 // Nobody is expecting an ACK and the buffer doesn't need to be deleted
103 // because it went away with the GPU process. 101 // because it went away with the GPU process.
104 if (last_gpu_host_id_ != gpu_host_id) 102 if (last_gpu_host_id_ != gpu_host_id)
105 return; 103 return;
106 104
107 // This means the guest crashed. 105 // This means the guest crashed.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 container_->setWebLayer(NULL); 147 container_->setWebLayer(NULL);
150 container_ = NULL; 148 container_ = NULL;
151 149
152 texture_layer_ = NULL; 150 texture_layer_ = NULL;
153 background_layer_ = NULL; 151 background_layer_ = NULL;
154 web_layer_.reset(); 152 web_layer_.reset();
155 } 153 }
156 154
157 void BrowserPluginCompositingHelper::OnBuffersSwapped( 155 void BrowserPluginCompositingHelper::OnBuffersSwapped(
158 const gfx::Size& size, 156 const gfx::Size& size,
159 const std::string& mailbox_name, 157 const gpu::Mailbox& mailbox_name,
160 int gpu_route_id, 158 int gpu_route_id,
161 int gpu_host_id, 159 int gpu_host_id,
162 float device_scale_factor) { 160 float device_scale_factor) {
163 // If the guest crashed but the GPU process didn't, we may still have 161 // If the guest crashed but the GPU process didn't, we may still have
164 // a transport surface waiting on an ACK, which we must send to 162 // a transport surface waiting on an ACK, which we must send to
165 // avoid leaking. 163 // avoid leaking.
166 if (last_gpu_route_id_ != gpu_route_id && last_gpu_host_id_ == gpu_host_id) 164 if (last_gpu_route_id_ != gpu_route_id && last_gpu_host_id_ == gpu_host_id)
167 ack_pending_for_crashed_guest_ = ack_pending_; 165 ack_pending_for_crashed_guest_ = ack_pending_;
168 166
169 // If these mismatch, we are either just starting up, GPU process crashed or 167 // If these mismatch, we are either just starting up, GPU process crashed or
(...skipping 26 matching lines...) Expand all
196 if (buffer_size_ != size) { 194 if (buffer_size_ != size) {
197 buffer_size_ = size; 195 buffer_size_ = size;
198 // The container size is in DIP, so is the layer size. 196 // The container size is in DIP, so is the layer size.
199 // Buffer size is in physical pixels, so we need to adjust 197 // Buffer size is in physical pixels, so we need to adjust
200 // it by the device scale factor. 198 // it by the device scale factor.
201 gfx::Size device_scale_adjusted_size = gfx::ToFlooredSize( 199 gfx::Size device_scale_adjusted_size = gfx::ToFlooredSize(
202 gfx::ScaleSize(buffer_size_, 1.0f / device_scale_factor)); 200 gfx::ScaleSize(buffer_size_, 1.0f / device_scale_factor));
203 texture_layer_->SetBounds(device_scale_adjusted_size); 201 texture_layer_->SetBounds(device_scale_adjusted_size);
204 } 202 }
205 203
206 bool current_mailbox_valid = !mailbox_name.empty(); 204 bool current_mailbox_valid = !mailbox_name.IsZero();
207 if (!last_mailbox_valid_) { 205 if (!last_mailbox_valid_) {
208 MailboxReleased(std::string(), gpu_route_id, gpu_host_id, 0); 206 MailboxReleased(gpu::Mailbox(), gpu_route_id, gpu_host_id, 0);
209 if (!current_mailbox_valid) 207 if (!current_mailbox_valid)
210 return; 208 return;
211 } 209 }
212 210
213 cc::TextureMailbox::ReleaseCallback callback; 211 cc::TextureMailbox::ReleaseCallback callback;
214 if (current_mailbox_valid) { 212 if (current_mailbox_valid) {
215 callback = base::Bind(&BrowserPluginCompositingHelper::MailboxReleased, 213 callback = base::Bind(&BrowserPluginCompositingHelper::MailboxReleased,
216 scoped_refptr<BrowserPluginCompositingHelper>(this), 214 scoped_refptr<BrowserPluginCompositingHelper>(this),
217 mailbox_name, 215 mailbox_name,
218 gpu_route_id, 216 gpu_route_id,
219 gpu_host_id); 217 gpu_host_id);
220 } 218 }
221 texture_layer_->SetTextureMailbox(cc::TextureMailbox(mailbox_name, 219 texture_layer_->SetTextureMailbox(cc::TextureMailbox(mailbox_name,
222 callback)); 220 callback));
223 texture_layer_->SetNeedsDisplay(); 221 texture_layer_->SetNeedsDisplay();
224 last_mailbox_valid_ = current_mailbox_valid; 222 last_mailbox_valid_ = current_mailbox_valid;
225 } 223 }
226 224
227 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) { 225 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) {
228 if (texture_layer_) 226 if (texture_layer_)
229 texture_layer_->SetIsDrawable(visible); 227 texture_layer_->SetIsDrawable(visible);
230 } 228 }
231 229
232 } // namespace content 230 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698