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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 180723023: gpu: Mailbox emulation with EGLImage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address piman's comments Created 6 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) 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 "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 const char* function_name_; 297 const char* function_name_;
298 ErrorState* error_state_; 298 ErrorState* error_state_;
299 DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); 299 DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor);
300 }; 300 };
301 301
302 // Temporarily changes a decoder's bound texture and restore it when this 302 // Temporarily changes a decoder's bound texture and restore it when this
303 // object goes out of scope. Also temporarily switches to using active texture 303 // object goes out of scope. Also temporarily switches to using active texture
304 // unit zero in case the client has changed that to something invalid. 304 // unit zero in case the client has changed that to something invalid.
305 class ScopedTextureBinder { 305 class ScopedTextureBinder {
306 public: 306 public:
307 ScopedTextureBinder(ContextState* state, GLuint id, GLenum target); 307 explicit ScopedTextureBinder(ContextState* state, GLuint id, GLenum target);
308 ~ScopedTextureBinder(); 308 ~ScopedTextureBinder();
309 309
310 private: 310 private:
311 ContextState* state_; 311 ContextState* state_;
312 GLenum target_; 312 GLenum target_;
313 DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder); 313 DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder);
314 }; 314 };
315 315
316 // Temporarily changes a decoder's bound render buffer and restore it when this 316 // Temporarily changes a decoder's bound render buffer and restore it when this
317 // object goes out of scope. 317 // object goes out of scope.
318 class ScopedRenderBufferBinder { 318 class ScopedRenderBufferBinder {
319 public: 319 public:
320 ScopedRenderBufferBinder(ContextState* state, GLuint id); 320 explicit ScopedRenderBufferBinder(ContextState* state, GLuint id);
321 ~ScopedRenderBufferBinder(); 321 ~ScopedRenderBufferBinder();
322 322
323 private: 323 private:
324 ContextState* state_; 324 ContextState* state_;
325 DISALLOW_COPY_AND_ASSIGN(ScopedRenderBufferBinder); 325 DISALLOW_COPY_AND_ASSIGN(ScopedRenderBufferBinder);
326 }; 326 };
327 327
328 // Temporarily changes a decoder's bound frame buffer and restore it when this 328 // Temporarily changes a decoder's bound frame buffer and restore it when this
329 // object goes out of scope. 329 // object goes out of scope.
330 class ScopedFrameBufferBinder { 330 class ScopedFrameBufferBinder {
331 public: 331 public:
332 ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, GLuint id); 332 explicit ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, GLuint id);
333 ~ScopedFrameBufferBinder(); 333 ~ScopedFrameBufferBinder();
334 334
335 private: 335 private:
336 GLES2DecoderImpl* decoder_; 336 GLES2DecoderImpl* decoder_;
337 DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder); 337 DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder);
338 }; 338 };
339 339
340 // Temporarily changes a decoder's bound frame buffer to a resolved version of 340 // Temporarily changes a decoder's bound frame buffer to a resolved version of
341 // the multisampled offscreen render buffer if that buffer is multisampled, and, 341 // the multisampled offscreen render buffer if that buffer is multisampled, and,
342 // if it is bound or enforce_internal_framebuffer is true. If internal is 342 // if it is bound or enforce_internal_framebuffer is true. If internal is
343 // true, the resolved framebuffer is not visible to the parent. 343 // true, the resolved framebuffer is not visible to the parent.
344 class ScopedResolvedFrameBufferBinder { 344 class ScopedResolvedFrameBufferBinder {
345 public: 345 public:
346 ScopedResolvedFrameBufferBinder(GLES2DecoderImpl* decoder, 346 explicit ScopedResolvedFrameBufferBinder(GLES2DecoderImpl* decoder,
347 bool enforce_internal_framebuffer, 347 bool enforce_internal_framebuffer,
348 bool internal); 348 bool internal);
349 ~ScopedResolvedFrameBufferBinder(); 349 ~ScopedResolvedFrameBufferBinder();
350 350
351 private: 351 private:
352 GLES2DecoderImpl* decoder_; 352 GLES2DecoderImpl* decoder_;
353 bool resolve_and_bind_; 353 bool resolve_and_bind_;
354 DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); 354 DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder);
355 }; 355 };
356 356
357 class ScopedModifyPixels {
358 public:
359 explicit ScopedModifyPixels(TextureRef* ref);
360 ~ScopedModifyPixels();
361
362 private:
363 TextureRef* ref_;
364 };
365
366 ScopedModifyPixels::ScopedModifyPixels(TextureRef* ref) : ref_(ref) {
367 if (ref_)
368 ref_->texture()->OnWillModifyPixels();
369 }
370
371 ScopedModifyPixels::~ScopedModifyPixels() {
372 if (ref_)
373 ref_->texture()->OnDidModifyPixels();
374 }
375
376 class ScopedRenderTo {
377 public:
378 explicit ScopedRenderTo(Framebuffer* framebuffer);
379 ~ScopedRenderTo();
380
381 private:
382 const Framebuffer* framebuffer_;
383 };
384
385 ScopedRenderTo::ScopedRenderTo(Framebuffer* framebuffer)
386 : framebuffer_(framebuffer) {
387 if (framebuffer)
388 framebuffer_->OnWillRenderTo();
389 }
390
391 ScopedRenderTo::~ScopedRenderTo() {
392 if (framebuffer_)
393 framebuffer_->OnDidRenderTo();
394 }
395
357 // Encapsulates an OpenGL texture. 396 // Encapsulates an OpenGL texture.
358 class BackTexture { 397 class BackTexture {
359 public: 398 public:
360 explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); 399 explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state);
361 ~BackTexture(); 400 ~BackTexture();
362 401
363 // Create a new render texture. 402 // Create a new render texture.
364 void Create(); 403 void Create();
365 404
366 // Set the initial size and format of a render texture or resize it. 405 // Set the initial size and format of a render texture or resize it.
(...skipping 6013 matching lines...) Expand 10 before | Expand all | Expand 10 after
6380 if (!SimulateAttrib0( 6419 if (!SimulateAttrib0(
6381 function_name, max_vertex_accessed, &simulated_attrib_0)) { 6420 function_name, max_vertex_accessed, &simulated_attrib_0)) {
6382 return error::kNoError; 6421 return error::kNoError;
6383 } 6422 }
6384 bool simulated_fixed_attribs = false; 6423 bool simulated_fixed_attribs = false;
6385 if (SimulateFixedAttribs( 6424 if (SimulateFixedAttribs(
6386 function_name, max_vertex_accessed, &simulated_fixed_attribs, 6425 function_name, max_vertex_accessed, &simulated_fixed_attribs,
6387 primcount)) { 6426 primcount)) {
6388 bool textures_set = !PrepareTexturesForRender(); 6427 bool textures_set = !PrepareTexturesForRender();
6389 ApplyDirtyState(); 6428 ApplyDirtyState();
6429 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get());
6390 if (!instanced) { 6430 if (!instanced) {
6391 glDrawArrays(mode, first, count); 6431 glDrawArrays(mode, first, count);
6392 } else { 6432 } else {
6393 glDrawArraysInstancedANGLE(mode, first, count, primcount); 6433 glDrawArraysInstancedANGLE(mode, first, count, primcount);
6394 } 6434 }
6395 ProcessPendingQueries(); 6435 ProcessPendingQueries();
6396 if (textures_set) { 6436 if (textures_set) {
6397 RestoreStateForTextures(); 6437 RestoreStateForTextures();
6398 } 6438 }
6399 if (simulated_fixed_attribs) { 6439 if (simulated_fixed_attribs) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
6509 // TODO(gman): Refactor to hide these details in BufferManager or 6549 // TODO(gman): Refactor to hide these details in BufferManager or
6510 // VertexAttribManager. 6550 // VertexAttribManager.
6511 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); 6551 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset);
6512 bool used_client_side_array = false; 6552 bool used_client_side_array = false;
6513 if (element_array_buffer->IsClientSideArray()) { 6553 if (element_array_buffer->IsClientSideArray()) {
6514 used_client_side_array = true; 6554 used_client_side_array = true;
6515 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 6555 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
6516 indices = element_array_buffer->GetRange(offset, 0); 6556 indices = element_array_buffer->GetRange(offset, 0);
6517 } 6557 }
6518 6558
6559 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get());
6519 if (!instanced) { 6560 if (!instanced) {
6520 glDrawElements(mode, count, type, indices); 6561 glDrawElements(mode, count, type, indices);
6521 } else { 6562 } else {
6522 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); 6563 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount);
6523 } 6564 }
6524 6565
6525 if (used_client_side_array) { 6566 if (used_client_side_array) {
6526 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 6567 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
6527 element_array_buffer->service_id()); 6568 element_array_buffer->service_id());
6528 } 6569 }
(...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after
8300 width, height, texture->IsImmutable())) { 8341 width, height, texture->IsImmutable())) {
8301 LOCAL_SET_GL_ERROR( 8342 LOCAL_SET_GL_ERROR(
8302 GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); 8343 GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big");
8303 return; 8344 return;
8304 } 8345 }
8305 if (copyHeight > 0 && copyWidth > 0) { 8346 if (copyHeight > 0 && copyWidth > 0) {
8306 GLint dx = copyX - x; 8347 GLint dx = copyX - x;
8307 GLint dy = copyY - y; 8348 GLint dy = copyY - y;
8308 GLint destX = dx; 8349 GLint destX = dx;
8309 GLint destY = dy; 8350 GLint destY = dy;
8351 ScopedModifyPixels modify(texture_ref);
8310 glCopyTexSubImage2D(target, level, 8352 glCopyTexSubImage2D(target, level,
8311 destX, destY, copyX, copyY, 8353 destX, destY, copyX, copyY,
8312 copyWidth, copyHeight); 8354 copyWidth, copyHeight);
8313 } 8355 }
8314 } else { 8356 } else {
8357 ScopedModifyPixels modify(texture_ref);
8315 glCopyTexImage2D(target, level, internal_format, 8358 glCopyTexImage2D(target, level, internal_format,
8316 copyX, copyY, copyWidth, copyHeight, border); 8359 copyX, copyY, copyWidth, copyHeight, border);
8317 } 8360 }
8318 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D"); 8361 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D");
8319 if (error == GL_NO_ERROR) { 8362 if (error == GL_NO_ERROR) {
8320 texture_manager()->SetLevelInfo( 8363 texture_manager()->SetLevelInfo(
8321 texture_ref, target, level, internal_format, width, height, 1, 8364 texture_ref, target, level, internal_format, width, height, 1,
8322 border, internal_format, GL_UNSIGNED_BYTE, true); 8365 border, internal_format, GL_UNSIGNED_BYTE, true);
8323 } 8366 }
8324 } 8367 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
8404 uint32 pixels_size = 0; 8447 uint32 pixels_size = 0;
8405 if (!GLES2Util::ComputeImageDataSizes( 8448 if (!GLES2Util::ComputeImageDataSizes(
8406 width, height, format, type, state_.unpack_alignment, &pixels_size, 8449 width, height, format, type, state_.unpack_alignment, &pixels_size,
8407 NULL, NULL)) { 8450 NULL, NULL)) {
8408 LOCAL_SET_GL_ERROR( 8451 LOCAL_SET_GL_ERROR(
8409 GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large"); 8452 GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large");
8410 return; 8453 return;
8411 } 8454 }
8412 scoped_ptr<char[]> zero(new char[pixels_size]); 8455 scoped_ptr<char[]> zero(new char[pixels_size]);
8413 memset(zero.get(), 0, pixels_size); 8456 memset(zero.get(), 0, pixels_size);
8457 ScopedModifyPixels modify(texture_ref);
8414 glTexSubImage2D( 8458 glTexSubImage2D(
8415 target, level, xoffset, yoffset, width, height, 8459 target, level, xoffset, yoffset, width, height,
8416 format, type, zero.get()); 8460 format, type, zero.get());
8417 } 8461 }
8418 8462
8419 if (copyHeight > 0 && copyWidth > 0) { 8463 if (copyHeight > 0 && copyWidth > 0) {
8420 GLint dx = copyX - x; 8464 GLint dx = copyX - x;
8421 GLint dy = copyY - y; 8465 GLint dy = copyY - y;
8422 GLint destX = xoffset + dx; 8466 GLint destX = xoffset + dx;
8423 GLint destY = yoffset + dy; 8467 GLint destY = yoffset + dy;
8468 ScopedModifyPixels modify(texture_ref);
8424 glCopyTexSubImage2D(target, level, 8469 glCopyTexSubImage2D(target, level,
8425 destX, destY, copyX, copyY, 8470 destX, destY, copyX, copyY,
8426 copyWidth, copyHeight); 8471 copyWidth, copyHeight);
8427 } 8472 }
8428 } 8473 }
8429 8474
8430 bool GLES2DecoderImpl::ValidateTexSubImage2D( 8475 bool GLES2DecoderImpl::ValidateTexSubImage2D(
8431 error::Error* error, 8476 error::Error* error,
8432 const char* function_name, 8477 const char* function_name,
8433 GLenum target, 8478 GLenum target,
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
9285 return error::kLostContext; 9330 return error::kLostContext;
9286 } 9331 }
9287 9332
9288 error::Error GLES2DecoderImpl::HandleInsertSyncPointCHROMIUM( 9333 error::Error GLES2DecoderImpl::HandleInsertSyncPointCHROMIUM(
9289 uint32 immediate_data_size, const cmds::InsertSyncPointCHROMIUM& c) { 9334 uint32 immediate_data_size, const cmds::InsertSyncPointCHROMIUM& c) {
9290 return error::kUnknownCommand; 9335 return error::kUnknownCommand;
9291 } 9336 }
9292 9337
9293 error::Error GLES2DecoderImpl::HandleWaitSyncPointCHROMIUM( 9338 error::Error GLES2DecoderImpl::HandleWaitSyncPointCHROMIUM(
9294 uint32 immediate_data_size, const cmds::WaitSyncPointCHROMIUM& c) { 9339 uint32 immediate_data_size, const cmds::WaitSyncPointCHROMIUM& c) {
9340 group_->mailbox_manager()->PullTextureUpdates();
9295 if (wait_sync_point_callback_.is_null()) 9341 if (wait_sync_point_callback_.is_null())
9296 return error::kNoError; 9342 return error::kNoError;
9297 9343
9298 return wait_sync_point_callback_.Run(c.sync_point) ? 9344 return wait_sync_point_callback_.Run(c.sync_point) ?
9299 error::kNoError : error::kDeferCommandUntilLater; 9345 error::kNoError : error::kDeferCommandUntilLater;
9300 } 9346 }
9301 9347
9302 error::Error GLES2DecoderImpl::HandleDiscardBackbufferCHROMIUM( 9348 error::Error GLES2DecoderImpl::HandleDiscardBackbufferCHROMIUM(
9303 uint32 immediate_data_size, const cmds::DiscardBackbufferCHROMIUM& c) { 9349 uint32 immediate_data_size, const cmds::DiscardBackbufferCHROMIUM& c) {
9304 if (surface_->DeferDraws()) 9350 if (surface_->DeferDraws())
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
9834 9880
9835 texture_manager()->SetLevelInfo( 9881 texture_manager()->SetLevelInfo(
9836 dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, 9882 dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width,
9837 source_height, 1, 0, internal_format, dest_type, true); 9883 source_height, 1, 0, internal_format, dest_type, true);
9838 } else { 9884 } else {
9839 texture_manager()->SetLevelCleared( 9885 texture_manager()->SetLevelCleared(
9840 dest_texture_ref, GL_TEXTURE_2D, level, true); 9886 dest_texture_ref, GL_TEXTURE_2D, level, true);
9841 } 9887 }
9842 9888
9843 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); 9889 DoWillUseTexImageIfNeeded(source_texture, source_texture->target());
9890 ScopedModifyPixels modify(dest_texture_ref);
9844 9891
9845 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix 9892 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix
9846 // before presenting. 9893 // before presenting.
9847 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { 9894 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) {
9848 // TODO(hkuang): get the StreamTexture transform matrix in GPU process 9895 // TODO(hkuang): get the StreamTexture transform matrix in GPU process
9849 // instead of using default matrix crbug.com/226218. 9896 // instead of using default matrix crbug.com/226218.
9850 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 9897 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f,
9851 0.0f, 1.0f, 0.0f, 0.0f, 9898 0.0f, 1.0f, 0.0f, 0.0f,
9852 0.0f, 0.0f, 1.0f, 0.0f, 9899 0.0f, 0.0f, 1.0f, 0.0f,
9853 0.0f, 0.0f, 0.0f, 1.0f}; 9900 0.0f, 0.0f, 0.0f, 1.0f};
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
10540 DoDidUseTexImageIfNeeded(texture, texture->target()); 10587 DoDidUseTexImageIfNeeded(texture, texture->target());
10541 } 10588 }
10542 10589
10543 // Include the auto-generated part of this file. We split this because it means 10590 // Include the auto-generated part of this file. We split this because it means
10544 // we can easily edit the non-auto generated parts right here in this file 10591 // we can easily edit the non-auto generated parts right here in this file
10545 // instead of having to edit some template or the code generator. 10592 // instead of having to edit some template or the code generator.
10546 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10593 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10547 10594
10548 } // namespace gles2 10595 } // namespace gles2
10549 } // namespace gpu 10596 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698