OLD | NEW |
---|---|
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 #include "gpu/command_buffer/service/gpu_tracer.h" | 46 #include "gpu/command_buffer/service/gpu_tracer.h" |
47 #include "gpu/command_buffer/service/image_manager.h" | 47 #include "gpu/command_buffer/service/image_manager.h" |
48 #include "gpu/command_buffer/service/mailbox_manager.h" | 48 #include "gpu/command_buffer/service/mailbox_manager.h" |
49 #include "gpu/command_buffer/service/memory_tracking.h" | 49 #include "gpu/command_buffer/service/memory_tracking.h" |
50 #include "gpu/command_buffer/service/program_manager.h" | 50 #include "gpu/command_buffer/service/program_manager.h" |
51 #include "gpu/command_buffer/service/query_manager.h" | 51 #include "gpu/command_buffer/service/query_manager.h" |
52 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 52 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
53 #include "gpu/command_buffer/service/shader_manager.h" | 53 #include "gpu/command_buffer/service/shader_manager.h" |
54 #include "gpu/command_buffer/service/shader_translator.h" | 54 #include "gpu/command_buffer/service/shader_translator.h" |
55 #include "gpu/command_buffer/service/shader_translator_cache.h" | 55 #include "gpu/command_buffer/service/shader_translator_cache.h" |
56 #include "gpu/command_buffer/service/stream_texture.h" | |
57 #include "gpu/command_buffer/service/stream_texture_manager.h" | |
58 #include "gpu/command_buffer/service/texture_manager.h" | 56 #include "gpu/command_buffer/service/texture_manager.h" |
59 #include "gpu/command_buffer/service/vertex_array_manager.h" | 57 #include "gpu/command_buffer/service/vertex_array_manager.h" |
60 #include "gpu/command_buffer/service/vertex_attrib_manager.h" | 58 #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
61 #include "ui/gl/gl_bindings.h" | 59 #include "ui/gl/gl_bindings.h" |
62 #include "ui/gl/gl_fence.h" | 60 #include "ui/gl/gl_fence.h" |
63 #include "ui/gl/gl_image.h" | 61 #include "ui/gl/gl_image.h" |
64 #include "ui/gl/gl_implementation.h" | 62 #include "ui/gl/gl_implementation.h" |
65 #include "ui/gl/gl_surface.h" | 63 #include "ui/gl/gl_surface.h" |
66 | 64 |
67 #if defined(OS_MACOSX) | 65 #if defined(OS_MACOSX) |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
717 } | 715 } |
718 | 716 |
719 VertexArrayManager* vertex_array_manager() { | 717 VertexArrayManager* vertex_array_manager() { |
720 return vertex_array_manager_.get(); | 718 return vertex_array_manager_.get(); |
721 } | 719 } |
722 | 720 |
723 MemoryTracker* memory_tracker() { | 721 MemoryTracker* memory_tracker() { |
724 return group_->memory_tracker(); | 722 return group_->memory_tracker(); |
725 } | 723 } |
726 | 724 |
727 StreamTextureManager* stream_texture_manager() const { | |
728 return group_->stream_texture_manager(); | |
729 } | |
730 | |
731 bool EnsureGPUMemoryAvailable(size_t estimated_size) { | 725 bool EnsureGPUMemoryAvailable(size_t estimated_size) { |
732 MemoryTracker* tracker = memory_tracker(); | 726 MemoryTracker* tracker = memory_tracker(); |
733 if (tracker) { | 727 if (tracker) { |
734 return tracker->EnsureGPUMemoryAvailable(estimated_size); | 728 return tracker->EnsureGPUMemoryAvailable(estimated_size); |
735 } | 729 } |
736 return true; | 730 return true; |
737 } | 731 } |
738 | 732 |
739 bool IsOffscreenBufferMultisampled() const { | 733 bool IsOffscreenBufferMultisampled() const { |
740 return offscreen_target_samples_ > 1; | 734 return offscreen_target_samples_ > 1; |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1395 // Checks if the current program and vertex attributes are valid for drawing. | 1389 // Checks if the current program and vertex attributes are valid for drawing. |
1396 bool IsDrawValid( | 1390 bool IsDrawValid( |
1397 const char* function_name, GLuint max_vertex_accessed, GLsizei primcount); | 1391 const char* function_name, GLuint max_vertex_accessed, GLsizei primcount); |
1398 | 1392 |
1399 // Returns true if successful, simulated will be true if attrib0 was | 1393 // Returns true if successful, simulated will be true if attrib0 was |
1400 // simulated. | 1394 // simulated. |
1401 bool SimulateAttrib0( | 1395 bool SimulateAttrib0( |
1402 const char* function_name, GLuint max_vertex_accessed, bool* simulated); | 1396 const char* function_name, GLuint max_vertex_accessed, bool* simulated); |
1403 void RestoreStateForAttrib(GLuint attrib); | 1397 void RestoreStateForAttrib(GLuint attrib); |
1404 | 1398 |
1405 // If texture is a stream texture, this will update the stream to the newest | 1399 // Notifies a potentially attached GLImage that we are about to draw with |
1406 // buffer. | 1400 // the texture. |
1407 void UpdateStreamTextureIfNeeded(Texture* texture); | 1401 void PrepareTexImageForDraw(Texture* texture); |
reveman
2013/08/14 15:22:44
PrepareTextureForRender? and maybe not be specific
no sievers
2013/08/14 18:16:48
Done.
| |
1408 | 1402 |
1409 // Returns false if unrenderable textures were replaced. | 1403 // Returns false if unrenderable textures were replaced. |
1410 bool PrepareTexturesForRender(); | 1404 bool PrepareTexturesForRender(); |
1411 void RestoreStateForNonRenderableTextures(); | 1405 void RestoreStateForNonRenderableTextures(); |
1412 | 1406 |
1413 // Returns true if GL_FIXED attribs were simulated. | 1407 // Returns true if GL_FIXED attribs were simulated. |
1414 bool SimulateFixedAttribs( | 1408 bool SimulateFixedAttribs( |
1415 const char* function_name, | 1409 const char* function_name, |
1416 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); | 1410 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); |
1417 void RestoreStateForSimulatedFixedAttribs(); | 1411 void RestoreStateForSimulatedFixedAttribs(); |
(...skipping 2457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3875 Texture* texture = texture_ref->texture(); | 3869 Texture* texture = texture_ref->texture(); |
3876 | 3870 |
3877 // Check the texture exists | 3871 // Check the texture exists |
3878 // Check that we are not trying to bind it to a different target. | 3872 // Check that we are not trying to bind it to a different target. |
3879 if (texture->target() != 0 && texture->target() != target) { | 3873 if (texture->target() != 0 && texture->target() != target) { |
3880 LOCAL_SET_GL_ERROR( | 3874 LOCAL_SET_GL_ERROR( |
3881 GL_INVALID_OPERATION, | 3875 GL_INVALID_OPERATION, |
3882 "glBindTexture", "texture bound to more than 1 target."); | 3876 "glBindTexture", "texture bound to more than 1 target."); |
3883 return; | 3877 return; |
3884 } | 3878 } |
3885 if (texture->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) { | |
3886 LOCAL_SET_GL_ERROR( | |
3887 GL_INVALID_OPERATION, | |
3888 "glBindTexture", "illegal target for stream texture."); | |
3889 return; | |
3890 } | |
3891 LogClientServiceForInfo(texture, client_id, "glBindTexture"); | 3879 LogClientServiceForInfo(texture, client_id, "glBindTexture"); |
3892 if (texture->target() == 0) { | 3880 if (texture->target() == 0) { |
3893 texture_manager()->SetTarget(texture_ref, target); | 3881 texture_manager()->SetTarget(texture_ref, target); |
3894 } | 3882 } |
3895 glBindTexture(target, texture->service_id()); | 3883 glBindTexture(target, texture->service_id()); |
3896 | 3884 |
3897 TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; | 3885 TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
3898 unit.bind_target = target; | 3886 unit.bind_target = target; |
3899 switch (target) { | 3887 switch (target) { |
3900 case GL_TEXTURE_2D: | 3888 case GL_TEXTURE_2D: |
(...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5662 } | 5650 } |
5663 // We know there will be no errors, because we only defer compilation on | 5651 // We know there will be no errors, because we only defer compilation on |
5664 // shaders that were previously compiled successfully. | 5652 // shaders that were previously compiled successfully. |
5665 program_manager()->ForceCompileShader(shader->deferred_compilation_source(), | 5653 program_manager()->ForceCompileShader(shader->deferred_compilation_source(), |
5666 shader, | 5654 shader, |
5667 translator, | 5655 translator, |
5668 feature_info_.get()); | 5656 feature_info_.get()); |
5669 } | 5657 } |
5670 } | 5658 } |
5671 | 5659 |
5672 void GLES2DecoderImpl::UpdateStreamTextureIfNeeded(Texture* texture) { | 5660 void GLES2DecoderImpl::PrepareTexImageForDraw(Texture* texture) { |
5673 if (texture && texture->IsStreamTexture()) { | 5661 if (texture) { |
5674 DCHECK(stream_texture_manager()); | 5662 scoped_refptr<gfx::GLImage> image = |
5675 StreamTexture* stream_tex = | 5663 texture->GetLevelImage(texture->target(), 0); |
no sievers
2013/08/14 04:01:24
need to worry about multiple leves/images here?
| |
5676 stream_texture_manager()->LookupStreamTexture(texture->service_id()); | 5664 if (image.get()) |
5677 if (stream_tex) | 5665 image->WillUseTexImage(); |
5678 stream_tex->Update(); | |
5679 } | 5666 } |
5680 } | 5667 } |
5681 | 5668 |
5682 bool GLES2DecoderImpl::PrepareTexturesForRender() { | 5669 bool GLES2DecoderImpl::PrepareTexturesForRender() { |
5683 DCHECK(state_.current_program.get()); | 5670 DCHECK(state_.current_program.get()); |
5684 bool have_unrenderable_textures = | 5671 bool have_unrenderable_textures = |
5685 texture_manager()->HaveUnrenderableTextures(); | 5672 texture_manager()->HaveUnrenderableTextures(); |
5686 if (!have_unrenderable_textures && !features().oes_egl_image_external) { | 5673 if (!have_unrenderable_textures && !features().oes_egl_image_external) { |
5687 return true; | 5674 return true; |
5688 } | 5675 } |
5689 | 5676 |
5690 bool textures_set = false; | 5677 bool textures_set = false; |
5691 const Program::SamplerIndices& sampler_indices = | 5678 const Program::SamplerIndices& sampler_indices = |
5692 state_.current_program->sampler_indices(); | 5679 state_.current_program->sampler_indices(); |
5693 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { | 5680 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
5694 const Program::UniformInfo* uniform_info = | 5681 const Program::UniformInfo* uniform_info = |
5695 state_.current_program->GetUniformInfo(sampler_indices[ii]); | 5682 state_.current_program->GetUniformInfo(sampler_indices[ii]); |
5696 DCHECK(uniform_info); | 5683 DCHECK(uniform_info); |
5697 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { | 5684 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
5698 GLuint texture_unit_index = uniform_info->texture_units[jj]; | 5685 GLuint texture_unit_index = uniform_info->texture_units[jj]; |
5699 if (texture_unit_index < state_.texture_units.size()) { | 5686 if (texture_unit_index < state_.texture_units.size()) { |
5700 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; | 5687 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
5701 TextureRef* texture = | 5688 TextureRef* texture = |
5702 texture_unit.GetInfoForSamplerType(uniform_info->type).get(); | 5689 texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
5703 if (texture) | 5690 if (texture) |
5704 UpdateStreamTextureIfNeeded(texture->texture()); | 5691 PrepareTexImageForDraw(texture->texture()); |
5705 if (have_unrenderable_textures && | 5692 if (have_unrenderable_textures && |
5706 (!texture || !texture_manager()->CanRender(texture))) { | 5693 (!texture || !texture_manager()->CanRender(texture))) { |
5707 textures_set = true; | 5694 textures_set = true; |
5708 glActiveTexture(GL_TEXTURE0 + texture_unit_index); | 5695 glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
5709 glBindTexture( | 5696 glBindTexture( |
5710 GetBindTargetForSamplerType(uniform_info->type), | 5697 GetBindTargetForSamplerType(uniform_info->type), |
5711 texture_manager()->black_texture_id(uniform_info->type)); | 5698 texture_manager()->black_texture_id(uniform_info->type)); |
5712 LOCAL_RENDER_WARNING( | 5699 LOCAL_RENDER_WARNING( |
5713 std::string("texture bound to texture unit ") + | 5700 std::string("texture bound to texture unit ") + |
5714 base::IntToString(texture_unit_index) + | 5701 base::IntToString(texture_unit_index) + |
(...skipping 3764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9479 *result = GL_ZERO; | 9466 *result = GL_ZERO; |
9480 TextureRef* texture_ref = texture_manager()->GetTexture(client_id); | 9467 TextureRef* texture_ref = texture_manager()->GetTexture(client_id); |
9481 if (!texture_ref) { | 9468 if (!texture_ref) { |
9482 LOCAL_SET_GL_ERROR( | 9469 LOCAL_SET_GL_ERROR( |
9483 GL_INVALID_VALUE, | 9470 GL_INVALID_VALUE, |
9484 "glCreateStreamTextureCHROMIUM", "bad texture id."); | 9471 "glCreateStreamTextureCHROMIUM", "bad texture id."); |
9485 return error::kNoError; | 9472 return error::kNoError; |
9486 } | 9473 } |
9487 | 9474 |
9488 Texture* texture = texture_ref->texture(); | 9475 Texture* texture = texture_ref->texture(); |
9489 if (texture->IsStreamTexture()) { | |
9490 LOCAL_SET_GL_ERROR( | |
9491 GL_INVALID_OPERATION, | |
9492 "glCreateStreamTextureCHROMIUM", "is already a stream texture."); | |
9493 return error::kNoError; | |
9494 } | |
9495 | |
9496 if (texture->target() && texture->target() != GL_TEXTURE_EXTERNAL_OES) { | 9476 if (texture->target() && texture->target() != GL_TEXTURE_EXTERNAL_OES) { |
9497 LOCAL_SET_GL_ERROR( | 9477 LOCAL_SET_GL_ERROR( |
9498 GL_INVALID_OPERATION, | 9478 GL_INVALID_OPERATION, |
9499 "glCreateStreamTextureCHROMIUM", | 9479 "glCreateStreamTextureCHROMIUM", |
9500 "is already bound to incompatible target."); | 9480 "is already bound to incompatible target."); |
9501 return error::kNoError; | 9481 return error::kNoError; |
9482 } else if (!texture->target()) { | |
9483 texture_manager()->SetTarget(texture_ref, GL_TEXTURE_EXTERNAL_OES); | |
9502 } | 9484 } |
9503 | 9485 |
9504 if (!stream_texture_manager()) | 9486 scoped_refptr<gfx::GLImage> image = |
9505 return error::kInvalidArguments; | 9487 gfx::GLImage::CreateGLImageForStreamTexture(texture->service_id()); |
9506 | 9488 |
9507 GLuint object_id = stream_texture_manager()->CreateStreamTexture( | 9489 uint32 image_id = 0; |
9508 texture->service_id(), client_id); | 9490 if (image) { |
9509 | 9491 image_id = group_->GetIdAllocator(id_namespaces::kImages)->AllocateID(); |
9510 if (object_id) { | 9492 image_manager()->AddImage(image, image_id); |
reveman
2013/08/14 15:22:44
I thought we decided to track these separably from
no sievers
2013/08/14 18:16:48
See change above. Now that the pattern matches bet
| |
9511 texture_manager()->SetStreamTexture(texture_ref, true); | 9493 texture_manager()->SetLevelInfo(texture_ref, |
9494 GL_TEXTURE_EXTERNAL_OES, | |
9495 0, | |
9496 GL_RGBA, | |
9497 0, | |
9498 0, | |
9499 1, | |
9500 0, | |
9501 GL_RGBA, | |
9502 GL_UNSIGNED_BYTE, | |
9503 true); | |
9504 texture_manager()->SetLevelImage( | |
9505 texture_ref, GL_TEXTURE_EXTERNAL_OES, 0, image); | |
9512 } else { | 9506 } else { |
9513 LOCAL_SET_GL_ERROR( | 9507 LOCAL_SET_GL_ERROR( |
9514 GL_OUT_OF_MEMORY, | 9508 GL_OUT_OF_MEMORY, |
9515 "glCreateStreamTextureCHROMIUM", "failed to create platform texture."); | 9509 "glCreateStreamTextureCHROMIUM", "failed to create platform texture."); |
9516 } | 9510 } |
9517 | 9511 |
9518 *result = object_id; | 9512 *result = image_id; |
9519 return error::kNoError; | 9513 return error::kNoError; |
9520 } | 9514 } |
9521 | 9515 |
9522 error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM( | 9516 error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM( |
9523 uint32 immediate_data_size, | 9517 uint32 immediate_data_size, |
9524 const cmds::DestroyStreamTextureCHROMIUM& c) { | 9518 const cmds::DestroyStreamTextureCHROMIUM& c) { |
9525 GLuint client_id = c.texture; | 9519 GLuint image_id = c.texture; |
9526 TextureRef* texture_ref = texture_manager()->GetTexture(client_id); | 9520 if (image_id && image_manager()->LookupImage(image_id)) { |
9527 if (texture_ref && texture_manager()->IsStreamTextureOwner(texture_ref)) { | 9521 image_manager()->RemoveImage(image_id); |
9528 if (!stream_texture_manager()) | 9522 group_->GetIdAllocator(id_namespaces::kImages)->FreeID(image_id); |
9529 return error::kInvalidArguments; | |
9530 | |
9531 stream_texture_manager()->DestroyStreamTexture(texture_ref->service_id()); | |
9532 texture_manager()->SetStreamTexture(texture_ref, false); | |
9533 } else { | 9523 } else { |
9534 LOCAL_SET_GL_ERROR( | 9524 LOCAL_SET_GL_ERROR( |
9535 GL_INVALID_VALUE, | 9525 GL_INVALID_VALUE, |
9536 "glDestroyStreamTextureCHROMIUM", "bad texture id."); | 9526 "glDestroyStreamTextureCHROMIUM", "bad texture id."); |
9537 } | 9527 } |
9538 | 9528 |
9539 return error::kNoError; | 9529 return error::kNoError; |
9540 } | 9530 } |
9541 | 9531 |
9542 #if defined(OS_MACOSX) | 9532 #if defined(OS_MACOSX) |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9733 if (!texture_manager()->ValidForTarget(GL_TEXTURE_2D, level, source_width, | 9723 if (!texture_manager()->ValidForTarget(GL_TEXTURE_2D, level, source_width, |
9734 source_height, 1)) { | 9724 source_height, 1)) { |
9735 LOCAL_SET_GL_ERROR( | 9725 LOCAL_SET_GL_ERROR( |
9736 GL_INVALID_VALUE, | 9726 GL_INVALID_VALUE, |
9737 "glCopyTextureCHROMIUM", "Bad dimensions"); | 9727 "glCopyTextureCHROMIUM", "Bad dimensions"); |
9738 return; | 9728 return; |
9739 } | 9729 } |
9740 } | 9730 } |
9741 | 9731 |
9742 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { | 9732 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
9743 UpdateStreamTextureIfNeeded(source_texture); | 9733 PrepareTexImageForDraw(source_texture); |
9744 DCHECK(stream_texture_manager()); | 9734 scoped_refptr<gfx::GLImage> stream_tex = |
9745 StreamTexture* stream_tex = | 9735 source_texture->GetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0); |
9746 stream_texture_manager()->LookupStreamTexture( | |
9747 source_texture->service_id()); | |
9748 if (!stream_tex) { | 9736 if (!stream_tex) { |
9749 LOCAL_SET_GL_ERROR( | 9737 LOCAL_SET_GL_ERROR( |
9750 GL_INVALID_VALUE, | 9738 GL_INVALID_VALUE, |
9751 "glCopyTextureChromium", "Stream texture lookup failed"); | 9739 "glCopyTextureChromium", "Stream texture lookup failed"); |
9752 return; | 9740 return; |
9753 } | 9741 } |
9754 gfx::Size size = stream_tex->GetSize(); | 9742 gfx::Size size = stream_tex->GetSize(); |
9755 source_width = size.width(); | 9743 source_width = size.width(); |
9756 source_height = size.height(); | 9744 source_height = size.height(); |
9757 if (source_width <= 0 || source_height <= 0) { | 9745 if (source_width <= 0 || source_height <= 0) { |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10503 return error::kNoError; | 10491 return error::kNoError; |
10504 } | 10492 } |
10505 | 10493 |
10506 // Include the auto-generated part of this file. We split this because it means | 10494 // Include the auto-generated part of this file. We split this because it means |
10507 // we can easily edit the non-auto generated parts right here in this file | 10495 // we can easily edit the non-auto generated parts right here in this file |
10508 // instead of having to edit some template or the code generator. | 10496 // instead of having to edit some template or the code generator. |
10509 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10497 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
10510 | 10498 |
10511 } // namespace gles2 | 10499 } // namespace gles2 |
10512 } // namespace gpu | 10500 } // namespace gpu |
OLD | NEW |