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 <cmath> | 10 #include <cmath> |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1057 GLsizei width, | 1057 GLsizei width, |
1058 GLsizei height, | 1058 GLsizei height, |
1059 GLboolean unpack_flip_y, | 1059 GLboolean unpack_flip_y, |
1060 GLboolean unpack_premultiply_alpha, | 1060 GLboolean unpack_premultiply_alpha, |
1061 GLboolean unpack_unmultiply_alpha); | 1061 GLboolean unpack_unmultiply_alpha); |
1062 | 1062 |
1063 void DoCompressedCopyTextureCHROMIUM(GLenum target, | 1063 void DoCompressedCopyTextureCHROMIUM(GLenum target, |
1064 GLuint source_id, | 1064 GLuint source_id, |
1065 GLuint dest_id); | 1065 GLuint dest_id); |
1066 | 1066 |
1067 void DoCompressedCopySubTextureCHROMIUM(GLenum target, | |
1068 GLuint source_id, | |
1069 GLuint dest_id, | |
1070 GLint xoffset, | |
1071 GLint yoffset, | |
1072 GLint x, | |
1073 GLint y, | |
1074 GLsizei width, | |
1075 GLsizei height); | |
1076 | |
1067 // Wrapper for TexStorage2DEXT. | 1077 // Wrapper for TexStorage2DEXT. |
1068 void DoTexStorage2DEXT( | 1078 void DoTexStorage2DEXT( |
1069 GLenum target, | 1079 GLenum target, |
1070 GLint levels, | 1080 GLint levels, |
1071 GLenum internal_format, | 1081 GLenum internal_format, |
1072 GLsizei width, | 1082 GLsizei width, |
1073 GLsizei height); | 1083 GLsizei height); |
1074 | 1084 |
1075 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); | 1085 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
1076 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, | 1086 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, |
(...skipping 11571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12648 } else { | 12658 } else { |
12649 copy_texture_CHROMIUM_->DoCopyTexture( | 12659 copy_texture_CHROMIUM_->DoCopyTexture( |
12650 this, source_texture->target(), source_texture->service_id(), | 12660 this, source_texture->target(), source_texture->service_id(), |
12651 source_internal_format, dest_texture->service_id(), GL_RGBA, | 12661 source_internal_format, dest_texture->service_id(), GL_RGBA, |
12652 source_width, source_height, false, false, false); | 12662 source_width, source_height, false, false, false); |
12653 } | 12663 } |
12654 | 12664 |
12655 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | 12665 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
12656 } | 12666 } |
12657 | 12667 |
12668 void GLES2DecoderImpl::DoCompressedCopySubTextureCHROMIUM(GLenum target, | |
12669 GLuint source_id, | |
12670 GLuint dest_id, | |
12671 GLint xoffset, | |
12672 GLint yoffset, | |
12673 GLint x, | |
12674 GLint y, | |
12675 GLsizei width, | |
12676 GLsizei height) { | |
reveman
2015/08/05 16:07:40
How are we handling cases where for example width
christiank
2015/08/06 13:48:21
We're falling back to copying into an uncompressed
reveman
2015/08/06 18:38:29
I would prefer if we generated an INVALID_OPERATIO
christiank
2015/08/10 10:55:46
Done.
| |
12677 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompressedCopySubTextureCHROMIUM"); | |
12678 | |
12679 TextureRef* source_texture_ref = GetTexture(source_id); | |
12680 TextureRef* dest_texture_ref = GetTexture(dest_id); | |
12681 Texture* source_texture = source_texture_ref->texture(); | |
12682 Texture* dest_texture = dest_texture_ref->texture(); | |
12683 int source_width = 0; | |
12684 int source_height = 0; | |
12685 gfx::GLImage* image = | |
12686 source_texture->GetLevelImage(source_texture->target(), 0); | |
12687 if (image) { | |
12688 gfx::Size size = image->GetSize(); | |
12689 source_width = size.width(); | |
12690 source_height = size.height(); | |
12691 if (source_width <= 0 || source_height <= 0) { | |
12692 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCompressedCopySubTextureCHROMIUM", | |
12693 "invalid image size"); | |
12694 return; | |
12695 } | |
12696 } else { | |
12697 if (!source_texture->GetLevelSize(source_texture->target(), 0, | |
12698 &source_width, &source_height, nullptr)) { | |
12699 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCompressedCopySubTextureCHROMIUM", | |
12700 "source texture has no level 0"); | |
12701 return; | |
12702 } | |
12703 | |
12704 // Check that this type of texture is allowed. | |
12705 if (!texture_manager()->ValidForTarget(source_texture->target(), 0, | |
12706 source_width, source_height, 1)) { | |
12707 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCompressedCopySubTextureCHROMIUM", | |
12708 "source texture bad dimensions"); | |
12709 return; | |
12710 } | |
12711 } | |
12712 | |
12713 GLenum source_type = 0; | |
12714 GLenum source_internal_format = 0; | |
12715 source_texture->GetLevelType(source_texture->target(), 0, &source_type, | |
12716 &source_internal_format); | |
12717 if (!source_texture->ValidForTexture(source_texture->target(), 0, x, y, 0, | |
12718 width, height, 1, source_type)) { | |
12719 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCompressedCopySubTextureCHROMIUM", | |
12720 "source texture bad dimensions."); | |
12721 return; | |
12722 } | |
12723 | |
12724 GLenum dest_type = 0; | |
12725 GLenum dest_internal_format = 0; | |
12726 bool dest_level_defined = dest_texture->GetLevelType( | |
12727 dest_texture->target(), 0, &dest_type, &dest_internal_format); | |
12728 if (!dest_level_defined) { | |
12729 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, | |
12730 "glCompressedCopySubTextureCHROMIUM", | |
12731 "destination texture is not defined"); | |
12732 return; | |
12733 } | |
12734 if (!dest_texture->ValidForTexture(dest_texture->target(), 0, xoffset, | |
12735 yoffset, 0, width, height, 1, dest_type)) { | |
12736 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCompressedCopySubTextureCHROMIUM", | |
12737 "destination texture bad dimensions."); | |
12738 return; | |
12739 } | |
12740 | |
12741 if (!ValidateCompressedCopyTextureCHROMIUM( | |
12742 "glCompressedCopySubTextureCHROMIUM", target, source_texture_ref, | |
12743 dest_texture_ref)) { | |
12744 return; | |
12745 } | |
12746 | |
12747 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is | |
12748 // needed because it takes 10s of milliseconds to initialize. | |
12749 if (!copy_texture_CHROMIUM_.get()) { | |
12750 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopySubTextureCHROMIUM"); | |
12751 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); | |
12752 copy_texture_CHROMIUM_->Initialize(this); | |
12753 RestoreCurrentFramebufferBindings(); | |
12754 if (LOCAL_PEEK_GL_ERROR("glCompressedCopySubTextureCHROMIUM") != | |
12755 GL_NO_ERROR) { | |
12756 return; | |
12757 } | |
12758 } | |
12759 | |
12760 // Clear the source texture if necessary. | |
12761 if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, | |
12762 source_texture->target(), 0)) { | |
12763 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCompressedCopySubTextureCHROMIUM", | |
12764 "source texture dimensions too big"); | |
12765 return; | |
12766 } | |
12767 | |
12768 int dest_width = 0; | |
12769 int dest_height = 0; | |
12770 bool ok = dest_texture->GetLevelSize( | |
12771 GL_TEXTURE_2D, 0, &dest_width, &dest_height, nullptr); | |
12772 DCHECK(ok); | |
12773 if (xoffset != 0 || yoffset != 0 || width != dest_width || | |
12774 height != dest_height) { | |
12775 gfx::Rect cleared_rect; | |
12776 if (CombineAdjacentRects(dest_texture->GetLevelClearedRect(target, 0), | |
12777 gfx::Rect(xoffset, yoffset, width, height), | |
12778 &cleared_rect)) { | |
12779 DCHECK_GE(cleared_rect.size().GetArea(), | |
12780 dest_texture->GetLevelClearedRect(target, 0).size().GetArea()); | |
12781 texture_manager()->SetLevelClearedRect(dest_texture_ref, target, 0, | |
12782 cleared_rect); | |
12783 } else { | |
12784 // Otherwise clear part of texture level that is not already cleared. | |
12785 if (!texture_manager()->ClearTextureLevel(this, dest_texture_ref, target, | |
12786 0)) { | |
12787 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, | |
12788 "glCompressedCopySubTextureCHROMIUM", | |
12789 "destination texture dimensions too big"); | |
12790 return; | |
12791 } | |
12792 } | |
12793 } else { | |
12794 texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, | |
12795 true); | |
12796 } | |
12797 | |
12798 ScopedTextureBinder binder( | |
12799 &state_, dest_texture->service_id(), GL_TEXTURE_2D); | |
12800 | |
12801 ScopedModifyPixels modify(dest_texture_ref); | |
12802 | |
12803 // Try using GLImage::CopyTexSubImage when possible. | |
12804 if (image) { | |
12805 if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(xoffset, yoffset), | |
12806 gfx::Rect(x, y, width, height))) { | |
12807 return; | |
12808 } | |
12809 } | |
12810 | |
12811 TRACE_EVENT0( | |
12812 "gpu", | |
12813 "GLES2DecoderImpl::DoCompressedCopySubTextureCHROMIUM, fallback"); | |
12814 | |
12815 DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); | |
12816 | |
12817 // As a fallback, copy into a non-compressed GL_RGBA texture. | |
12818 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM"); | |
12819 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dest_width, dest_height, 0, GL_RGBA, | |
12820 GL_UNSIGNED_BYTE, NULL); | |
reveman
2015/08/05 16:07:40
What about the old contents? Updating a sub rect s
christiank
2015/08/06 13:48:21
You're right, I completely missed this detail. I m
| |
12821 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedCopySubTextureCHROMIUM"); | |
12822 if (error != GL_NO_ERROR) | |
12823 return; | |
12824 | |
12825 texture_manager()->SetLevelInfo( | |
12826 dest_texture_ref, GL_TEXTURE_2D, 0, GL_RGBA, dest_width, dest_height, | |
12827 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(dest_width, dest_height)); | |
12828 | |
12829 // TODO(hkuang): get the StreamTexture transform matrix in GPU process. | |
12830 // crbug.com/226218. | |
12831 copy_texture_CHROMIUM_->DoCopySubTexture( | |
12832 this, source_texture->target(), source_texture->service_id(), | |
12833 source_internal_format, dest_texture->service_id(), GL_RGBA, | |
12834 xoffset, yoffset, x, y, width, height, dest_width, dest_height, | |
12835 source_width, source_height, false, false, false); | |
12836 | |
12837 DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); | |
12838 } | |
12839 | |
12658 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { | 12840 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
12659 switch (internalformat) { | 12841 switch (internalformat) { |
12660 case GL_R8: | 12842 case GL_R8: |
12661 return GL_UNSIGNED_BYTE; | 12843 return GL_UNSIGNED_BYTE; |
12662 case GL_R8_SNORM: | 12844 case GL_R8_SNORM: |
12663 return GL_BYTE; | 12845 return GL_BYTE; |
12664 case GL_R16F: | 12846 case GL_R16F: |
12665 return GL_HALF_FLOAT; | 12847 return GL_HALF_FLOAT; |
12666 case GL_R32F: | 12848 case GL_R32F: |
12667 return GL_FLOAT; | 12849 return GL_FLOAT; |
(...skipping 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14405 return error::kNoError; | 14587 return error::kNoError; |
14406 } | 14588 } |
14407 | 14589 |
14408 // Include the auto-generated part of this file. We split this because it means | 14590 // Include the auto-generated part of this file. We split this because it means |
14409 // we can easily edit the non-auto generated parts right here in this file | 14591 // we can easily edit the non-auto generated parts right here in this file |
14410 // instead of having to edit some template or the code generator. | 14592 // instead of having to edit some template or the code generator. |
14411 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 14593 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
14412 | 14594 |
14413 } // namespace gles2 | 14595 } // namespace gles2 |
14414 } // namespace gpu | 14596 } // namespace gpu |
OLD | NEW |