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

Side by Side Diff: content/common/gpu/texture_image_transport_surface.cc

Issue 10052018: Drop frontbuffers with ui-use-gpu-process, synchronized with browser, decoupled from backbuffer dro… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor cleanup Created 8 years, 8 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) 2012 The Chromium Authors. All rights reserved. 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 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/common/gpu/texture_image_transport_surface.h" 5 #include "content/common/gpu/texture_image_transport_surface.h"
6 6
7 #include "content/common/gpu/gpu_channel.h" 7 #include "content/common/gpu/gpu_channel.h"
8 #include "content/common/gpu/gpu_channel_manager.h" 8 #include "content/common/gpu/gpu_channel_manager.h"
9 #include "content/common/gpu/gpu_messages.h" 9 #include "content/common/gpu/gpu_messages.h"
10 #include "gpu/command_buffer/service/context_group.h" 10 #include "gpu/command_buffer/service/context_group.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 }; 49 };
50 50
51 } // anonymous namespace 51 } // anonymous namespace
52 52
53 TextureImageTransportSurface::TextureImageTransportSurface( 53 TextureImageTransportSurface::TextureImageTransportSurface(
54 GpuChannelManager* manager, 54 GpuChannelManager* manager,
55 GpuCommandBufferStub* stub, 55 GpuCommandBufferStub* stub,
56 const gfx::GLSurfaceHandle& handle) 56 const gfx::GLSurfaceHandle& handle)
57 : fbo_id_(0), 57 : fbo_id_(0),
58 front_(0), 58 front_(0),
59 stub_destroyed_(false) { 59 stub_destroyed_(false),
60 backbuffer_allocated_(true),
61 frontbuffer_allocated_(true) {
60 GpuChannel* parent_channel = manager->LookupChannel(handle.parent_client_id); 62 GpuChannel* parent_channel = manager->LookupChannel(handle.parent_client_id);
61 DCHECK(parent_channel); 63 DCHECK(parent_channel);
62 GpuCommandBufferStub* parent_stub = parent_channel->LookupCommandBuffer( 64 GpuCommandBufferStub* parent_stub = parent_channel->LookupCommandBuffer(
63 handle.parent_context_id); 65 handle.parent_context_id);
64 DCHECK(parent_stub); 66 DCHECK(parent_stub);
65 parent_stub_ = parent_stub->AsWeakPtr(); 67 parent_stub_ = parent_stub->AsWeakPtr();
66 TextureManager* texture_manager = 68 TextureManager* texture_manager =
67 parent_stub_->decoder()->GetContextGroup()->texture_manager(); 69 parent_stub_->decoder()->GetContextGroup()->texture_manager();
68 DCHECK(texture_manager); 70 DCHECK(texture_manager);
69 71
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 if (stub_destroyed_) { 124 if (stub_destroyed_) {
123 // Early-exit so that we don't recreate the fbo. We still want to return 125 // Early-exit so that we don't recreate the fbo. We still want to return
124 // true, so that the context is made current and the GLES2DecoderImpl can 126 // true, so that the context is made current and the GLES2DecoderImpl can
125 // release its own resources. 127 // release its own resources.
126 return true; 128 return true;
127 } 129 }
128 130
129 if (!fbo_id_) { 131 if (!fbo_id_) {
130 glGenFramebuffersEXT(1, &fbo_id_); 132 glGenFramebuffersEXT(1, &fbo_id_);
131 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_id_); 133 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_id_);
132 CreateBackTexture(gfx::Size(1, 1)); 134 CreateTexture(back(), gfx::Size(1, 1));
133 135
134 #ifndef NDEBUG 136 #ifndef NDEBUG
135 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 137 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
136 if (status != GL_FRAMEBUFFER_COMPLETE) { 138 if (status != GL_FRAMEBUFFER_COMPLETE) {
137 DLOG(ERROR) << "Framebuffer incomplete."; 139 DLOG(ERROR) << "Framebuffer incomplete.";
138 return false; 140 return false;
139 } 141 }
140 #endif 142 #endif
141 } 143 }
142 144
143 return true; 145 return true;
144 } 146 }
145 147
146 unsigned int TextureImageTransportSurface::GetBackingFrameBufferObject() { 148 unsigned int TextureImageTransportSurface::GetBackingFrameBufferObject() {
147 return fbo_id_; 149 return fbo_id_;
148 } 150 }
149 151
150 void TextureImageTransportSurface::SetBufferAllocation( 152 void TextureImageTransportSurface::SetBackbufferAllocation(bool allocated) {
151 BufferAllocationState state) { 153 if (backbuffer_allocated_ == allocated)
154 return;
152 if (!helper_->MakeCurrent()) 155 if (!helper_->MakeCurrent())
153 return; 156 return;
154 switch (state) { 157 if (allocated)
155 case BUFFER_ALLOCATION_FRONT_AND_BACK: 158 CreateTexture(back(), textures_[back()].size);
156 CreateBackTexture(textures_[back()].size); 159 else
157 break; 160 RequestReleaseTexture(back());
158 case BUFFER_ALLOCATION_FRONT_ONLY: 161 }
159 case BUFFER_ALLOCATION_NONE: 162
160 ReleaseBackTexture(); 163 void TextureImageTransportSurface::SetFrontbufferAllocation(bool allocated) {
161 break; 164 if (frontbuffer_allocated_ == allocated)
162 }; 165 return;
166 if (!helper_->MakeCurrent())
167 return;
168 if (allocated)
169 CreateTexture(front(), textures_[front()].size);
mmocny 2012/04/11 22:58:36 Maybe I should be using back() surface size here
170 else
171 RequestReleaseTexture(front());
163 } 172 }
164 173
165 void* TextureImageTransportSurface::GetShareHandle() { 174 void* TextureImageTransportSurface::GetShareHandle() {
166 return GetHandle(); 175 return GetHandle();
167 } 176 }
168 177
169 void* TextureImageTransportSurface::GetDisplay() { 178 void* TextureImageTransportSurface::GetDisplay() {
170 return parent_stub_.get() ? parent_stub_->surface()->GetDisplay() : NULL; 179 return parent_stub_.get() ? parent_stub_->surface()->GetDisplay() : NULL;
171 } 180 }
172 181
173 void* TextureImageTransportSurface::GetConfig() { 182 void* TextureImageTransportSurface::GetConfig() {
174 return parent_stub_.get() ? parent_stub_->surface()->GetConfig() : NULL; 183 return parent_stub_.get() ? parent_stub_->surface()->GetConfig() : NULL;
175 } 184 }
176 185
177 void TextureImageTransportSurface::OnResize(gfx::Size size) { 186 void TextureImageTransportSurface::OnResize(gfx::Size size) {
178 CreateBackTexture(size); 187 CreateTexture(back(), size);
179 } 188 }
180 189
181 void TextureImageTransportSurface::OnWillDestroyStub( 190 void TextureImageTransportSurface::OnWillDestroyStub(
182 GpuCommandBufferStub* stub) { 191 GpuCommandBufferStub* stub) {
183 glDeleteFramebuffersEXT(1, &fbo_id_); 192 glDeleteFramebuffersEXT(1, &fbo_id_);
184 CHECK_GL_ERROR(); 193 CHECK_GL_ERROR();
185 fbo_id_ = 0; 194 fbo_id_ = 0;
186 195
187 stub->RemoveDestructionObserver(this); 196 stub->RemoveDestructionObserver(this);
188 stub_destroyed_ = true; 197 stub_destroyed_ = true;
189 } 198 }
190 199
191 bool TextureImageTransportSurface::SwapBuffers() { 200 bool TextureImageTransportSurface::SwapBuffers() {
201 DCHECK(backbuffer_allocated_);
202 if (!frontbuffer_allocated_) {
203 previous_damage_rect_ = gfx::Rect(textures_[back()].size);
204 return true;
205 }
192 glFlush(); 206 glFlush();
193 front_ = back(); 207 front_ = back();
194 previous_damage_rect_ = gfx::Rect(textures_[front_].size); 208 previous_damage_rect_ = gfx::Rect(textures_[front()].size);
195 209
196 DCHECK(textures_[front_].client_id != 0); 210 DCHECK(textures_[front()].client_id != 0);
197 211
198 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; 212 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params;
199 params.surface_handle = textures_[front_].client_id; 213 params.surface_handle = textures_[front()].client_id;
200 helper_->SendAcceleratedSurfaceBuffersSwapped(params); 214 helper_->SendAcceleratedSurfaceBuffersSwapped(params);
201 helper_->SetScheduled(false); 215 helper_->SetScheduled(false);
202 return true; 216 return true;
203 } 217 }
204 218
205 bool TextureImageTransportSurface::PostSubBuffer( 219 bool TextureImageTransportSurface::PostSubBuffer(
206 int x, int y, int width, int height) { 220 int x, int y, int width, int height) {
221 DCHECK(backbuffer_allocated_);
222 if (!frontbuffer_allocated_) {
223 previous_damage_rect_ = gfx::Rect(textures_[back()].size);
224 return true;
225 }
207 if (!parent_stub_.get()) 226 if (!parent_stub_.get())
208 return false; 227 return false;
209 228
210 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 229 TextureInfo* info = GetParentInfo(textures_[back()].client_id);
211 if (!info) 230 if (!info)
212 return false; 231 return false;
213 int back_texture_service_id = info->service_id(); 232 int back_texture_service_id = info->service_id();
214 233
215 info = GetParentInfo(textures_[front_].client_id); 234 info = GetParentInfo(textures_[front()].client_id);
216 if (!info) 235 if (!info)
217 return false; 236 return false;
218 int front_texture_service_id = info->service_id(); 237 int front_texture_service_id = info->service_id();
219 238
220 gfx::Size expected_size = textures_[back()].size; 239 gfx::Size expected_size = textures_[back()].size;
221 bool surfaces_same_size = textures_[front_].size == expected_size; 240 bool surfaces_same_size = textures_[front()].size == expected_size;
222 241
223 const gfx::Rect new_damage_rect(x, y, width, height); 242 const gfx::Rect new_damage_rect(x, y, width, height);
224 243
225 // An empty damage rect is a successful no-op. 244 // An empty damage rect is a successful no-op.
226 if (new_damage_rect.IsEmpty()) 245 if (new_damage_rect.IsEmpty())
227 return true; 246 return true;
228 247
229 if (surfaces_same_size) { 248 if (surfaces_same_size) {
230 std::vector<gfx::Rect> regions_to_copy; 249 std::vector<gfx::Rect> regions_to_copy;
231 GetRegionsToCopy(previous_damage_rect_, new_damage_rect, &regions_to_copy); 250 GetRegionsToCopy(previous_damage_rect_, new_damage_rect, &regions_to_copy);
(...skipping 15 matching lines...) Expand all
247 } 266 }
248 } 267 }
249 } else { 268 } else {
250 DCHECK(new_damage_rect == gfx::Rect(expected_size)); 269 DCHECK(new_damage_rect == gfx::Rect(expected_size));
251 } 270 }
252 271
253 glFlush(); 272 glFlush();
254 front_ = back(); 273 front_ = back();
255 274
256 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; 275 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params;
257 params.surface_handle = textures_[front_].client_id; 276 params.surface_handle = textures_[front()].client_id;
258 params.x = x; 277 params.x = x;
259 params.y = y; 278 params.y = y;
260 params.width = width; 279 params.width = width;
261 params.height = height; 280 params.height = height;
262 helper_->SendAcceleratedSurfacePostSubBuffer(params); 281 helper_->SendAcceleratedSurfacePostSubBuffer(params);
263 helper_->SetScheduled(false); 282 helper_->SetScheduled(false);
264 283
265 previous_damage_rect_ = new_damage_rect; 284 previous_damage_rect_ = new_damage_rect;
266 return true; 285 return true;
267 } 286 }
(...skipping 12 matching lines...) Expand all
280 299
281 void* TextureImageTransportSurface::GetHandle() { 300 void* TextureImageTransportSurface::GetHandle() {
282 return parent_stub_.get() ? parent_stub_->surface()->GetHandle() : NULL; 301 return parent_stub_.get() ? parent_stub_->surface()->GetHandle() : NULL;
283 } 302 }
284 303
285 304
286 void TextureImageTransportSurface::OnNewSurfaceACK( 305 void TextureImageTransportSurface::OnNewSurfaceACK(
287 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) { 306 uint64 surface_handle, TransportDIB::Handle /*shm_handle*/) {
288 } 307 }
289 308
309 void TextureImageTransportSurface::OnReleaseSurfaceACK(
310 uint64 surface_id, bool success) {
311 if (success)
312 ReleaseTexture(textures_[front()].client_id == surface_id ?
313 front() : back());
314 helper_->SetScheduled(true);
315 }
316
290 void TextureImageTransportSurface::OnBuffersSwappedACK() { 317 void TextureImageTransportSurface::OnBuffersSwappedACK() {
291 if (helper_->MakeCurrent()) { 318 if (helper_->MakeCurrent()) {
292 if (textures_[front_].size != textures_[back()].size) { 319 if (textures_[front()].size != textures_[back()].size) {
293 CreateBackTexture(textures_[front_].size); 320 CreateTexture(back(), textures_[front()].size);
294 } else { 321 } else {
295 AttachBackTextureToFBO(); 322 AttachTextureToFBO(back());
296 } 323 }
297 } 324 }
298 325
299 // Even if MakeCurrent fails, schedule anyway, to trigger the lost context 326 // Even if MakeCurrent fails, schedule anyway, to trigger the lost context
300 // logic. 327 // logic.
301 helper_->SetScheduled(true); 328 helper_->SetScheduled(true);
302 } 329 }
303 330
304 void TextureImageTransportSurface::OnPostSubBufferACK() { 331 void TextureImageTransportSurface::OnPostSubBufferACK() {
305 OnBuffersSwappedACK(); 332 OnBuffersSwappedACK();
306 } 333 }
307 334
308 void TextureImageTransportSurface::OnResizeViewACK() { 335 void TextureImageTransportSurface::OnResizeViewACK() {
309 NOTREACHED(); 336 NOTREACHED();
310 } 337 }
311 338
312 void TextureImageTransportSurface::ReleaseBackTexture() { 339 void TextureImageTransportSurface::RequestReleaseTexture(int id) {
340 Texture& texture = textures_[id];
341 if (!texture.sent_to_client) {
342 ReleaseTexture(id);
343 return;
344 }
345 GpuHostMsg_AcceleratedSurfaceRelease_Params params;
346 params.identifier = texture.client_id;
347 helper_->SendAcceleratedSurfaceRelease(params);
348 helper_->SetScheduled(false);
349 }
350
351 void TextureImageTransportSurface::ReleaseTexture(int id) {
313 if (!parent_stub_.get()) 352 if (!parent_stub_.get())
314 return; 353 return;
315 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 354 Texture& texture = textures_[id];
355 TextureInfo* info = GetParentInfo(texture.client_id);
316 if (!info) 356 if (!info)
317 return; 357 return;
318 358
319 GLuint service_id = info->service_id(); 359 GLuint service_id = info->service_id();
320 if (!service_id) 360 if (!service_id)
321 return; 361 return;
322 info->SetServiceId(0); 362 info->SetServiceId(0);
323 363
324 { 364 {
325 ScopedFrameBufferBinder fbo_binder(fbo_id_); 365 ScopedFrameBufferBinder fbo_binder(fbo_id_);
326 glDeleteTextures(1, &service_id); 366 glDeleteTextures(1, &service_id);
327 } 367 }
328 glFlush(); 368 glFlush();
329 CHECK_GL_ERROR(); 369 CHECK_GL_ERROR();
370 texture.sent_to_client = false;
371 if (id == front())
372 frontbuffer_allocated_ = false;
373 else
374 backbuffer_allocated_ = false;
330 } 375 }
331 376
332 void TextureImageTransportSurface::CreateBackTexture(const gfx::Size& size) { 377 void TextureImageTransportSurface::CreateTexture(
378 int id, const gfx::Size& size) {
333 if (!parent_stub_.get()) 379 if (!parent_stub_.get())
334 return; 380 return;
335 Texture& texture = textures_[back()]; 381 Texture& texture = textures_[id];
336 TextureInfo* info = GetParentInfo(texture.client_id); 382 TextureInfo* info = GetParentInfo(texture.client_id);
337 if (!info) 383 if (!info)
338 return; 384 return;
339 385
340 GLuint service_id = info->service_id(); 386 GLuint service_id = info->service_id();
341 387
342 if (service_id && texture.size == size) 388 if (service_id && texture.size == size)
343 return; 389 return;
344 390
345 if (!service_id) { 391 if (!service_id) {
(...skipping 24 matching lines...) Expand all
370 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 416 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
371 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 417 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
372 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 418 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 419 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
374 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 420 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
375 size.width(), size.height(), 0, 421 size.width(), size.height(), 0,
376 GL_RGBA, GL_UNSIGNED_BYTE, NULL); 422 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
377 CHECK_GL_ERROR(); 423 CHECK_GL_ERROR();
378 } 424 }
379 425
380 AttachBackTextureToFBO(); 426 AttachTextureToFBO(id);
381 427
382 GpuHostMsg_AcceleratedSurfaceNew_Params params; 428 GpuHostMsg_AcceleratedSurfaceNew_Params params;
383 params.width = size.width(); 429 params.width = size.width();
384 params.height = size.height(); 430 params.height = size.height();
385 params.surface_handle = texture.client_id; 431 params.surface_handle = texture.client_id;
386 helper_->SendAcceleratedSurfaceNew(params); 432 helper_->SendAcceleratedSurfaceNew(params);
387 texture.sent_to_client = true; 433 texture.sent_to_client = true;
434
435 if (id == front())
436 frontbuffer_allocated_ = true;
437 else
438 backbuffer_allocated_ = true;
388 } 439 }
389 440
390 void TextureImageTransportSurface::AttachBackTextureToFBO() { 441 void TextureImageTransportSurface::AttachTextureToFBO(int id) {
391 if (!parent_stub_.get()) 442 if (!parent_stub_.get())
392 return; 443 return;
393 TextureInfo* info = GetParentInfo(textures_[back()].client_id); 444 TextureInfo* info = GetParentInfo(textures_[id].client_id);
394 if (!info) 445 if (!info)
395 return; 446 return;
396 447
397 ScopedFrameBufferBinder fbo_binder(fbo_id_); 448 ScopedFrameBufferBinder fbo_binder(fbo_id_);
398 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, 449 glFramebufferTexture2DEXT(GL_FRAMEBUFFER,
399 GL_COLOR_ATTACHMENT0, 450 GL_COLOR_ATTACHMENT0,
400 GL_TEXTURE_2D, 451 GL_TEXTURE_2D,
401 info->service_id(), 452 info->service_id(),
402 0); 453 0);
403 glFlush(); 454 glFlush();
404 CHECK_GL_ERROR(); 455 CHECK_GL_ERROR();
405 456
406 #ifndef NDEBUG 457 #ifndef NDEBUG
407 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 458 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
408 if (status != GL_FRAMEBUFFER_COMPLETE) { 459 if (status != GL_FRAMEBUFFER_COMPLETE) {
409 DLOG(ERROR) << "Framebuffer incomplete."; 460 DLOG(ERROR) << "Framebuffer incomplete.";
410 } 461 }
411 #endif 462 #endif
412 } 463 }
413 464
414 TextureInfo* TextureImageTransportSurface::GetParentInfo(uint32 client_id) { 465 TextureInfo* TextureImageTransportSurface::GetParentInfo(uint32 client_id) {
415 DCHECK(parent_stub_.get()); 466 DCHECK(parent_stub_.get());
416 TextureManager* texture_manager = 467 TextureManager* texture_manager =
417 parent_stub_->decoder()->GetContextGroup()->texture_manager(); 468 parent_stub_->decoder()->GetContextGroup()->texture_manager();
418 TextureInfo* info = texture_manager->GetTextureInfo(client_id); 469 TextureInfo* info = texture_manager->GetTextureInfo(client_id);
419 return info; 470 return info;
420 } 471 }
OLDNEW
« no previous file with comments | « content/common/gpu/texture_image_transport_surface.h ('k') | content/port/browser/render_widget_host_view_port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698