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

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

Issue 12612005: Revert 186627 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 gpu::Mailbox& mailbox_name, 66 const std::string& mailbox_name,
67 unsigned sync_point) { 67 unsigned sync_point) {
68 if (mailbox_name.IsZero()) 68 if (mailbox_name.empty())
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(GL_TEXTURE_2D, mailbox_name.name); 90 context->consumeTextureCHROMIUM(
91 GL_TEXTURE_2D,
92 reinterpret_cast<const int8*>(mailbox_name.data()));
91 context->deleteTexture(texture_id); 93 context->deleteTexture(texture_id);
92 } 94 }
93 95
94 void BrowserPluginCompositingHelper::MailboxReleased( 96 void BrowserPluginCompositingHelper::MailboxReleased(
95 const gpu::Mailbox& mailbox_name, 97 const std::string& mailbox_name,
96 int gpu_route_id, 98 int gpu_route_id,
97 int gpu_host_id, 99 int gpu_host_id,
98 unsigned sync_point) { 100 unsigned sync_point) {
99 // This means the GPU process crashed and we have nothing further to do. 101 // This means the GPU process crashed and we have nothing further to do.
100 // Nobody is expecting an ACK and the buffer doesn't need to be deleted 102 // Nobody is expecting an ACK and the buffer doesn't need to be deleted
101 // because it went away with the GPU process. 103 // because it went away with the GPU process.
102 if (last_gpu_host_id_ != gpu_host_id) 104 if (last_gpu_host_id_ != gpu_host_id)
103 return; 105 return;
104 106
105 // This means the guest crashed. 107 // This means the guest crashed.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 container_->setWebLayer(NULL); 149 container_->setWebLayer(NULL);
148 container_ = NULL; 150 container_ = NULL;
149 151
150 texture_layer_ = NULL; 152 texture_layer_ = NULL;
151 background_layer_ = NULL; 153 background_layer_ = NULL;
152 web_layer_.reset(); 154 web_layer_.reset();
153 } 155 }
154 156
155 void BrowserPluginCompositingHelper::OnBuffersSwapped( 157 void BrowserPluginCompositingHelper::OnBuffersSwapped(
156 const gfx::Size& size, 158 const gfx::Size& size,
157 const gpu::Mailbox& mailbox_name, 159 const std::string& mailbox_name,
158 int gpu_route_id, 160 int gpu_route_id,
159 int gpu_host_id, 161 int gpu_host_id,
160 float device_scale_factor) { 162 float device_scale_factor) {
161 // If the guest crashed but the GPU process didn't, we may still have 163 // If the guest crashed but the GPU process didn't, we may still have
162 // a transport surface waiting on an ACK, which we must send to 164 // a transport surface waiting on an ACK, which we must send to
163 // avoid leaking. 165 // avoid leaking.
164 if (last_gpu_route_id_ != gpu_route_id && last_gpu_host_id_ == gpu_host_id) 166 if (last_gpu_route_id_ != gpu_route_id && last_gpu_host_id_ == gpu_host_id)
165 ack_pending_for_crashed_guest_ = ack_pending_; 167 ack_pending_for_crashed_guest_ = ack_pending_;
166 168
167 // If these mismatch, we are either just starting up, GPU process crashed or 169 // If these mismatch, we are either just starting up, GPU process crashed or
(...skipping 26 matching lines...) Expand all
194 if (buffer_size_ != size) { 196 if (buffer_size_ != size) {
195 buffer_size_ = size; 197 buffer_size_ = size;
196 // The container size is in DIP, so is the layer size. 198 // The container size is in DIP, so is the layer size.
197 // Buffer size is in physical pixels, so we need to adjust 199 // Buffer size is in physical pixels, so we need to adjust
198 // it by the device scale factor. 200 // it by the device scale factor.
199 gfx::Size device_scale_adjusted_size = gfx::ToFlooredSize( 201 gfx::Size device_scale_adjusted_size = gfx::ToFlooredSize(
200 gfx::ScaleSize(buffer_size_, 1.0f / device_scale_factor)); 202 gfx::ScaleSize(buffer_size_, 1.0f / device_scale_factor));
201 texture_layer_->setBounds(device_scale_adjusted_size); 203 texture_layer_->setBounds(device_scale_adjusted_size);
202 } 204 }
203 205
204 bool current_mailbox_valid = !mailbox_name.IsZero(); 206 bool current_mailbox_valid = !mailbox_name.empty();
205 if (!last_mailbox_valid_) { 207 if (!last_mailbox_valid_) {
206 MailboxReleased(gpu::Mailbox(), gpu_route_id, gpu_host_id, 0); 208 MailboxReleased(std::string(), gpu_route_id, gpu_host_id, 0);
207 if (!current_mailbox_valid) 209 if (!current_mailbox_valid)
208 return; 210 return;
209 } 211 }
210 212
211 cc::TextureMailbox::ReleaseCallback callback; 213 cc::TextureMailbox::ReleaseCallback callback;
212 if (current_mailbox_valid) { 214 if (current_mailbox_valid) {
213 callback = base::Bind(&BrowserPluginCompositingHelper::MailboxReleased, 215 callback = base::Bind(&BrowserPluginCompositingHelper::MailboxReleased,
214 scoped_refptr<BrowserPluginCompositingHelper>(this), 216 scoped_refptr<BrowserPluginCompositingHelper>(this),
215 mailbox_name, 217 mailbox_name,
216 gpu_route_id, 218 gpu_route_id,
217 gpu_host_id); 219 gpu_host_id);
218 } 220 }
219 texture_layer_->setTextureMailbox(cc::TextureMailbox(mailbox_name, 221 texture_layer_->setTextureMailbox(cc::TextureMailbox(mailbox_name,
220 callback)); 222 callback));
221 last_mailbox_valid_ = current_mailbox_valid; 223 last_mailbox_valid_ = current_mailbox_valid;
222 } 224 }
223 225
224 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) { 226 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) {
225 if (texture_layer_) 227 if (texture_layer_)
226 texture_layer_->setIsDrawable(visible); 228 texture_layer_->setIsDrawable(visible);
227 } 229 }
228 230
229 } // namespace content 231 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698