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

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: oops 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ScopedModifyPixels(TextureRef* ref);
piman 2014/03/13 04:41:58 nit: explicit
no sievers 2014/03/13 20:50:15 Done.
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 ScopedRenderTo(Framebuffer* framebuffer);
piman 2014/03/13 04:41:58 nit: explicit
no sievers 2014/03/13 20:50:15 Done.
379 ~ScopedRenderTo();
380
381 private:
382 const Framebuffer::Attachment* color_buffer_;
383 };
384
385 ScopedRenderTo::ScopedRenderTo(Framebuffer* framebuffer) : color_buffer_(NULL) {
386 if (framebuffer) {
387 color_buffer_ = framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0);
piman 2014/03/13 04:41:58 Do we need color attachments 1..n? Maybe depth/ste
no sievers 2014/03/13 20:50:15 Done.
388 if (color_buffer_)
389 color_buffer_->OnWillRenderTo();
390 }
391 }
392
393 ScopedRenderTo::~ScopedRenderTo() {
394 if (color_buffer_)
395 color_buffer_->OnDidRenderTo();
396 }
397
357 // Encapsulates an OpenGL texture. 398 // Encapsulates an OpenGL texture.
358 class BackTexture { 399 class BackTexture {
359 public: 400 public:
360 explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); 401 explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state);
361 ~BackTexture(); 402 ~BackTexture();
362 403
363 // Create a new render texture. 404 // Create a new render texture.
364 void Create(); 405 void Create();
365 406
366 // Set the initial size and format of a render texture or resize it. 407 // 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( 6421 if (!SimulateAttrib0(
6381 function_name, max_vertex_accessed, &simulated_attrib_0)) { 6422 function_name, max_vertex_accessed, &simulated_attrib_0)) {
6382 return error::kNoError; 6423 return error::kNoError;
6383 } 6424 }
6384 bool simulated_fixed_attribs = false; 6425 bool simulated_fixed_attribs = false;
6385 if (SimulateFixedAttribs( 6426 if (SimulateFixedAttribs(
6386 function_name, max_vertex_accessed, &simulated_fixed_attribs, 6427 function_name, max_vertex_accessed, &simulated_fixed_attribs,
6387 primcount)) { 6428 primcount)) {
6388 bool textures_set = !PrepareTexturesForRender(); 6429 bool textures_set = !PrepareTexturesForRender();
6389 ApplyDirtyState(); 6430 ApplyDirtyState();
6431 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get());
6390 if (!instanced) { 6432 if (!instanced) {
6391 glDrawArrays(mode, first, count); 6433 glDrawArrays(mode, first, count);
6392 } else { 6434 } else {
6393 glDrawArraysInstancedANGLE(mode, first, count, primcount); 6435 glDrawArraysInstancedANGLE(mode, first, count, primcount);
6394 } 6436 }
6395 ProcessPendingQueries(); 6437 ProcessPendingQueries();
6396 if (textures_set) { 6438 if (textures_set) {
6397 RestoreStateForTextures(); 6439 RestoreStateForTextures();
6398 } 6440 }
6399 if (simulated_fixed_attribs) { 6441 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 6551 // TODO(gman): Refactor to hide these details in BufferManager or
6510 // VertexAttribManager. 6552 // VertexAttribManager.
6511 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); 6553 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset);
6512 bool used_client_side_array = false; 6554 bool used_client_side_array = false;
6513 if (element_array_buffer->IsClientSideArray()) { 6555 if (element_array_buffer->IsClientSideArray()) {
6514 used_client_side_array = true; 6556 used_client_side_array = true;
6515 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 6557 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
6516 indices = element_array_buffer->GetRange(offset, 0); 6558 indices = element_array_buffer->GetRange(offset, 0);
6517 } 6559 }
6518 6560
6561 ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get());
6519 if (!instanced) { 6562 if (!instanced) {
6520 glDrawElements(mode, count, type, indices); 6563 glDrawElements(mode, count, type, indices);
6521 } else { 6564 } else {
6522 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); 6565 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount);
6523 } 6566 }
6524 6567
6525 if (used_client_side_array) { 6568 if (used_client_side_array) {
6526 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 6569 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
6527 element_array_buffer->service_id()); 6570 element_array_buffer->service_id());
6528 } 6571 }
(...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after
8300 width, height, texture->IsImmutable())) { 8343 width, height, texture->IsImmutable())) {
8301 LOCAL_SET_GL_ERROR( 8344 LOCAL_SET_GL_ERROR(
8302 GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); 8345 GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big");
8303 return; 8346 return;
8304 } 8347 }
8305 if (copyHeight > 0 && copyWidth > 0) { 8348 if (copyHeight > 0 && copyWidth > 0) {
8306 GLint dx = copyX - x; 8349 GLint dx = copyX - x;
8307 GLint dy = copyY - y; 8350 GLint dy = copyY - y;
8308 GLint destX = dx; 8351 GLint destX = dx;
8309 GLint destY = dy; 8352 GLint destY = dy;
8353 ScopedModifyPixels modify(texture_ref);
8310 glCopyTexSubImage2D(target, level, 8354 glCopyTexSubImage2D(target, level,
8311 destX, destY, copyX, copyY, 8355 destX, destY, copyX, copyY,
8312 copyWidth, copyHeight); 8356 copyWidth, copyHeight);
8313 } 8357 }
8314 } else { 8358 } else {
8359 ScopedModifyPixels modify(texture_ref);
8315 glCopyTexImage2D(target, level, internal_format, 8360 glCopyTexImage2D(target, level, internal_format,
8316 copyX, copyY, copyWidth, copyHeight, border); 8361 copyX, copyY, copyWidth, copyHeight, border);
8317 } 8362 }
8318 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D"); 8363 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D");
8319 if (error == GL_NO_ERROR) { 8364 if (error == GL_NO_ERROR) {
8320 texture_manager()->SetLevelInfo( 8365 texture_manager()->SetLevelInfo(
8321 texture_ref, target, level, internal_format, width, height, 1, 8366 texture_ref, target, level, internal_format, width, height, 1,
8322 border, internal_format, GL_UNSIGNED_BYTE, true); 8367 border, internal_format, GL_UNSIGNED_BYTE, true);
8323 } 8368 }
8324 } 8369 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
8404 uint32 pixels_size = 0; 8449 uint32 pixels_size = 0;
8405 if (!GLES2Util::ComputeImageDataSizes( 8450 if (!GLES2Util::ComputeImageDataSizes(
8406 width, height, format, type, state_.unpack_alignment, &pixels_size, 8451 width, height, format, type, state_.unpack_alignment, &pixels_size,
8407 NULL, NULL)) { 8452 NULL, NULL)) {
8408 LOCAL_SET_GL_ERROR( 8453 LOCAL_SET_GL_ERROR(
8409 GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large"); 8454 GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large");
8410 return; 8455 return;
8411 } 8456 }
8412 scoped_ptr<char[]> zero(new char[pixels_size]); 8457 scoped_ptr<char[]> zero(new char[pixels_size]);
8413 memset(zero.get(), 0, pixels_size); 8458 memset(zero.get(), 0, pixels_size);
8459 ScopedModifyPixels modify(texture_ref);
8414 glTexSubImage2D( 8460 glTexSubImage2D(
8415 target, level, xoffset, yoffset, width, height, 8461 target, level, xoffset, yoffset, width, height,
8416 format, type, zero.get()); 8462 format, type, zero.get());
8417 } 8463 }
8418 8464
8419 if (copyHeight > 0 && copyWidth > 0) { 8465 if (copyHeight > 0 && copyWidth > 0) {
8420 GLint dx = copyX - x; 8466 GLint dx = copyX - x;
8421 GLint dy = copyY - y; 8467 GLint dy = copyY - y;
8422 GLint destX = xoffset + dx; 8468 GLint destX = xoffset + dx;
8423 GLint destY = yoffset + dy; 8469 GLint destY = yoffset + dy;
8470 ScopedModifyPixels modify(texture_ref);
8424 glCopyTexSubImage2D(target, level, 8471 glCopyTexSubImage2D(target, level,
8425 destX, destY, copyX, copyY, 8472 destX, destY, copyX, copyY,
8426 copyWidth, copyHeight); 8473 copyWidth, copyHeight);
8427 } 8474 }
8428 } 8475 }
8429 8476
8430 bool GLES2DecoderImpl::ValidateTexSubImage2D( 8477 bool GLES2DecoderImpl::ValidateTexSubImage2D(
8431 error::Error* error, 8478 error::Error* error,
8432 const char* function_name, 8479 const char* function_name,
8433 GLenum target, 8480 GLenum target,
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
9285 return error::kLostContext; 9332 return error::kLostContext;
9286 } 9333 }
9287 9334
9288 error::Error GLES2DecoderImpl::HandleInsertSyncPointCHROMIUM( 9335 error::Error GLES2DecoderImpl::HandleInsertSyncPointCHROMIUM(
9289 uint32 immediate_data_size, const cmds::InsertSyncPointCHROMIUM& c) { 9336 uint32 immediate_data_size, const cmds::InsertSyncPointCHROMIUM& c) {
9290 return error::kUnknownCommand; 9337 return error::kUnknownCommand;
9291 } 9338 }
9292 9339
9293 error::Error GLES2DecoderImpl::HandleWaitSyncPointCHROMIUM( 9340 error::Error GLES2DecoderImpl::HandleWaitSyncPointCHROMIUM(
9294 uint32 immediate_data_size, const cmds::WaitSyncPointCHROMIUM& c) { 9341 uint32 immediate_data_size, const cmds::WaitSyncPointCHROMIUM& c) {
9342 group_->mailbox_manager()->PullTextureUpdates();
9295 if (wait_sync_point_callback_.is_null()) 9343 if (wait_sync_point_callback_.is_null())
9296 return error::kNoError; 9344 return error::kNoError;
9297 9345
9298 return wait_sync_point_callback_.Run(c.sync_point) ? 9346 return wait_sync_point_callback_.Run(c.sync_point) ?
9299 error::kNoError : error::kDeferCommandUntilLater; 9347 error::kNoError : error::kDeferCommandUntilLater;
9300 } 9348 }
9301 9349
9302 error::Error GLES2DecoderImpl::HandleDiscardBackbufferCHROMIUM( 9350 error::Error GLES2DecoderImpl::HandleDiscardBackbufferCHROMIUM(
9303 uint32 immediate_data_size, const cmds::DiscardBackbufferCHROMIUM& c) { 9351 uint32 immediate_data_size, const cmds::DiscardBackbufferCHROMIUM& c) {
9304 if (surface_->DeferDraws()) 9352 if (surface_->DeferDraws())
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
9834 9882
9835 texture_manager()->SetLevelInfo( 9883 texture_manager()->SetLevelInfo(
9836 dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, 9884 dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width,
9837 source_height, 1, 0, internal_format, dest_type, true); 9885 source_height, 1, 0, internal_format, dest_type, true);
9838 } else { 9886 } else {
9839 texture_manager()->SetLevelCleared( 9887 texture_manager()->SetLevelCleared(
9840 dest_texture_ref, GL_TEXTURE_2D, level, true); 9888 dest_texture_ref, GL_TEXTURE_2D, level, true);
9841 } 9889 }
9842 9890
9843 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); 9891 DoWillUseTexImageIfNeeded(source_texture, source_texture->target());
9892 ScopedModifyPixels modify(dest_texture_ref);
9844 9893
9845 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix 9894 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix
9846 // before presenting. 9895 // before presenting.
9847 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { 9896 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) {
9848 // TODO(hkuang): get the StreamTexture transform matrix in GPU process 9897 // TODO(hkuang): get the StreamTexture transform matrix in GPU process
9849 // instead of using default matrix crbug.com/226218. 9898 // instead of using default matrix crbug.com/226218.
9850 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 9899 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f,
9851 0.0f, 1.0f, 0.0f, 0.0f, 9900 0.0f, 1.0f, 0.0f, 0.0f,
9852 0.0f, 0.0f, 1.0f, 0.0f, 9901 0.0f, 0.0f, 1.0f, 0.0f,
9853 0.0f, 0.0f, 0.0f, 1.0f}; 9902 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()); 10589 DoDidUseTexImageIfNeeded(texture, texture->target());
10541 } 10590 }
10542 10591
10543 // Include the auto-generated part of this file. We split this because it means 10592 // 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 10593 // 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. 10594 // instead of having to edit some template or the code generator.
10546 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10595 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10547 10596
10548 } // namespace gles2 10597 } // namespace gles2
10549 } // namespace gpu 10598 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698