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 <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 bool enforce_internal_framebuffer, | 317 bool enforce_internal_framebuffer, |
318 bool internal); | 318 bool internal); |
319 ~ScopedResolvedFramebufferBinder(); | 319 ~ScopedResolvedFramebufferBinder(); |
320 | 320 |
321 private: | 321 private: |
322 GLES2DecoderImpl* decoder_; | 322 GLES2DecoderImpl* decoder_; |
323 bool resolve_and_bind_; | 323 bool resolve_and_bind_; |
324 DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFramebufferBinder); | 324 DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFramebufferBinder); |
325 }; | 325 }; |
326 | 326 |
327 // Reset the base level of the texture currently bound to the | |
328 // texture target and restore it after calling texImage2D. | |
329 class ScopedTextureBaseLevelResetter { | |
330 public: | |
331 explicit ScopedTextureBaseLevelResetter(GLenum target, | |
Zhenyao Mo
2017/06/09 21:28:06
nit: no need for explicit because you have three a
| |
332 GLint base_level, | |
333 bool reset_base_level) | |
334 : target_(target), | |
335 base_level_(base_level), | |
336 reset_base_level_(reset_base_level) { | |
337 DCHECK(target_ == GL_TEXTURE_2D); | |
338 if (reset_base_level_) { | |
Zhenyao Mo
2017/06/09 21:28:06
&& base_level
| |
339 glTexParameteri(target_, GL_TEXTURE_BASE_LEVEL, 0); | |
340 } | |
341 } | |
342 | |
343 ~ScopedTextureBaseLevelResetter() { | |
344 if (reset_base_level_) { | |
Zhenyao Mo
2017/06/09 21:28:06
&& base_level
| |
345 glTexParameteri(target_, GL_TEXTURE_BASE_LEVEL, base_level_); | |
346 } | |
347 } | |
348 | |
349 private: | |
350 GLenum target_; | |
351 GLint base_level_; | |
352 bool reset_base_level_; | |
353 DISALLOW_COPY_AND_ASSIGN(ScopedTextureBaseLevelResetter); | |
354 }; | |
355 | |
327 // Encapsulates an OpenGL texture. | 356 // Encapsulates an OpenGL texture. |
328 class BackTexture { | 357 class BackTexture { |
329 public: | 358 public: |
330 explicit BackTexture(GLES2DecoderImpl* decoder); | 359 explicit BackTexture(GLES2DecoderImpl* decoder); |
331 ~BackTexture(); | 360 ~BackTexture(); |
332 | 361 |
333 // Create a new render texture. | 362 // Create a new render texture. |
334 void Create(); | 363 void Create(); |
335 | 364 |
336 // Set the initial size and format of a render texture or resize it. | 365 // Set the initial size and format of a render texture or resize it. |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 GLint srcY0, | 672 GLint srcY0, |
644 GLint srcX1, | 673 GLint srcX1, |
645 GLint srcY1, | 674 GLint srcY1, |
646 GLint dstX0, | 675 GLint dstX0, |
647 GLint dstY0, | 676 GLint dstY0, |
648 GLint dstX1, | 677 GLint dstX1, |
649 GLint dstY1, | 678 GLint dstY1, |
650 GLbitfield mask, | 679 GLbitfield mask, |
651 GLenum filter); | 680 GLenum filter); |
652 | 681 |
682 void TexImage2DHelper(GLenum target, | |
683 GLint level, | |
684 GLenum internal_format, | |
685 GLsizei width, | |
686 GLsizei height, | |
687 GLint border, | |
688 GLenum format, | |
689 GLenum type, | |
690 const void* pixels, | |
691 GLint base_level, | |
692 bool reset_base_level); | |
693 | |
653 PathManager* path_manager() { return group_->path_manager(); } | 694 PathManager* path_manager() { return group_->path_manager(); } |
654 | 695 |
655 private: | 696 private: |
656 friend class ScopedFramebufferBinder; | 697 friend class ScopedFramebufferBinder; |
657 friend class ScopedResolvedFramebufferBinder; | 698 friend class ScopedResolvedFramebufferBinder; |
699 friend class ScopedTextureBaseLevelResetter; | |
Zhenyao Mo
2017/06/09 21:28:06
Why this needs to be a friend?
| |
658 friend class BackFramebuffer; | 700 friend class BackFramebuffer; |
659 friend class BackRenderbuffer; | 701 friend class BackRenderbuffer; |
660 friend class BackTexture; | 702 friend class BackTexture; |
661 | 703 |
662 enum FramebufferOperation { | 704 enum FramebufferOperation { |
663 kFramebufferDiscard, | 705 kFramebufferDiscard, |
664 kFramebufferInvalidate, | 706 kFramebufferInvalidate, |
665 kFramebufferInvalidateSub | 707 kFramebufferInvalidateSub |
666 }; | 708 }; |
667 | 709 |
(...skipping 5569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6237 bool texture_zero_level_set = false; | 6279 bool texture_zero_level_set = false; |
6238 GLenum type = 0; | 6280 GLenum type = 0; |
6239 GLenum internal_format = 0; | 6281 GLenum internal_format = 0; |
6240 GLenum format = 0; | 6282 GLenum format = 0; |
6241 if (workarounds().set_zero_level_before_generating_mipmap && | 6283 if (workarounds().set_zero_level_before_generating_mipmap && |
6242 target == GL_TEXTURE_2D) { | 6284 target == GL_TEXTURE_2D) { |
6243 if (base_level != 0 && | 6285 if (base_level != 0 && |
6244 !tex->GetLevelType(target, 0, &type, &internal_format) && | 6286 !tex->GetLevelType(target, 0, &type, &internal_format) && |
6245 tex->GetLevelType(target, tex->base_level(), &type, &internal_format)) { | 6287 tex->GetLevelType(target, tex->base_level(), &type, &internal_format)) { |
6246 format = TextureManager::ExtractFormatFromStorageFormat(internal_format); | 6288 format = TextureManager::ExtractFormatFromStorageFormat(internal_format); |
6247 glTexImage2D(target, 0, internal_format, 1, 1, 0, format, type, nullptr); | 6289 TexImage2DHelper(target, 0, internal_format, 1, 1, 0, format, type, |
6290 nullptr, base_level, | |
6291 workarounds().reset_teximage2d_base_level); | |
6248 texture_zero_level_set = true; | 6292 texture_zero_level_set = true; |
6249 } | 6293 } |
6250 } | 6294 } |
6251 | 6295 |
6252 bool enable_srgb = 0; | 6296 bool enable_srgb = 0; |
6253 if (target == GL_TEXTURE_2D) { | 6297 if (target == GL_TEXTURE_2D) { |
6254 tex->GetLevelType(target, tex->base_level(), &type, &internal_format); | 6298 tex->GetLevelType(target, tex->base_level(), &type, &internal_format); |
6255 enable_srgb = GLES2Util::GetColorEncodingFromInternalFormat( | 6299 enable_srgb = GLES2Util::GetColorEncodingFromInternalFormat( |
6256 internal_format) == GL_SRGB; | 6300 internal_format) == GL_SRGB; |
6257 } | 6301 } |
(...skipping 13 matching lines...) Expand all Loading... | |
6271 glGenerateMipmapEXT(target); | 6315 glGenerateMipmapEXT(target); |
6272 } | 6316 } |
6273 } else { | 6317 } else { |
6274 glGenerateMipmapEXT(target); | 6318 glGenerateMipmapEXT(target); |
6275 } | 6319 } |
6276 | 6320 |
6277 if (texture_zero_level_set) { | 6321 if (texture_zero_level_set) { |
6278 // This may have some unwanted side effects, but we expect command buffer | 6322 // This may have some unwanted side effects, but we expect command buffer |
6279 // validation to prevent you from doing anything weird with the texture | 6323 // validation to prevent you from doing anything weird with the texture |
6280 // after this, like calling texSubImage2D sucessfully. | 6324 // after this, like calling texSubImage2D sucessfully. |
6281 glTexImage2D(target, 0, internal_format, 0, 0, 0, format, type, nullptr); | 6325 TexImage2DHelper(target, 0, internal_format, 0, 0, 0, format, type, nullptr, |
6326 base_level, workarounds().reset_teximage2d_base_level); | |
6282 } | 6327 } |
6283 | 6328 |
6284 if (workarounds().set_texture_filter_before_generating_mipmap) { | 6329 if (workarounds().set_texture_filter_before_generating_mipmap) { |
6285 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, | 6330 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, |
6286 texture_ref->texture()->min_filter()); | 6331 texture_ref->texture()->min_filter()); |
6287 } | 6332 } |
6288 GLenum error = LOCAL_PEEK_GL_ERROR("glGenerateMipmap"); | 6333 GLenum error = LOCAL_PEEK_GL_ERROR("glGenerateMipmap"); |
6289 if (error == GL_NO_ERROR) { | 6334 if (error == GL_NO_ERROR) { |
6290 texture_manager()->MarkMipmapsGenerated(texture_ref); | 6335 texture_manager()->MarkMipmapsGenerated(texture_ref); |
6291 } | 6336 } |
(...skipping 2116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8408 } else if (feature_info_->feature_flags().angle_framebuffer_multisample) { | 8453 } else if (feature_info_->feature_flags().angle_framebuffer_multisample) { |
8409 // This is ES2 only. | 8454 // This is ES2 only. |
8410 glBlitFramebufferANGLE( | 8455 glBlitFramebufferANGLE( |
8411 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); | 8456 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
8412 } else { | 8457 } else { |
8413 glBlitFramebufferEXT( | 8458 glBlitFramebufferEXT( |
8414 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); | 8459 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
8415 } | 8460 } |
8416 } | 8461 } |
8417 | 8462 |
8463 void GLES2DecoderImpl::TexImage2DHelper(GLenum target, | |
8464 GLint level, | |
8465 GLenum internal_format, | |
8466 GLsizei width, | |
8467 GLsizei height, | |
8468 GLint border, | |
8469 GLenum format, | |
8470 GLenum type, | |
8471 const void* pixels, | |
8472 GLint base_level, | |
8473 bool reset_base_level) { | |
8474 ScopedTextureBaseLevelResetter baseLevelResetter(target, base_level, | |
8475 reset_base_level); | |
8476 glTexImage2D(target, level, internal_format, width, height, 0, format, type, | |
8477 pixels); | |
8478 } | |
8479 | |
8418 bool GLES2DecoderImpl::ValidateRenderbufferStorageMultisample( | 8480 bool GLES2DecoderImpl::ValidateRenderbufferStorageMultisample( |
8419 GLsizei samples, | 8481 GLsizei samples, |
8420 GLenum internalformat, | 8482 GLenum internalformat, |
8421 GLsizei width, | 8483 GLsizei width, |
8422 GLsizei height) { | 8484 GLsizei height) { |
8423 if (samples > renderbuffer_manager()->max_samples()) { | 8485 if (samples > renderbuffer_manager()->max_samples()) { |
8424 LOCAL_SET_GL_ERROR( | 8486 LOCAL_SET_GL_ERROR( |
8425 GL_INVALID_VALUE, | 8487 GL_INVALID_VALUE, |
8426 "glRenderbufferStorageMultisample", "samples too large"); | 8488 "glRenderbufferStorageMultisample", "samples too large"); |
8427 return false; | 8489 return false; |
(...skipping 5329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13757 if (format_info != nullptr && !format_info->support_check(*feature_info_)) { | 13819 if (format_info != nullptr && !format_info->support_check(*feature_info_)) { |
13758 std::unique_ptr<uint8_t[]> decompressed_data = DecompressTextureData( | 13820 std::unique_ptr<uint8_t[]> decompressed_data = DecompressTextureData( |
13759 state_, *format_info, width, height, depth, image_size, data); | 13821 state_, *format_info, width, height, depth, image_size, data); |
13760 if (!decompressed_data) { | 13822 if (!decompressed_data) { |
13761 MarkContextLost(error::kGuilty); | 13823 MarkContextLost(error::kGuilty); |
13762 group_->LoseContexts(error::kInnocent); | 13824 group_->LoseContexts(error::kInnocent); |
13763 return error::kLostContext; | 13825 return error::kLostContext; |
13764 } | 13826 } |
13765 state_.PushTextureDecompressionUnpackState(); | 13827 state_.PushTextureDecompressionUnpackState(); |
13766 if (dimension == ContextState::k2D) { | 13828 if (dimension == ContextState::k2D) { |
13767 glTexImage2D(target, level, format_info->decompressed_internal_format, | 13829 TexImage2DHelper(target, level, format_info->decompressed_internal_format, |
13768 width, height, border, format_info->decompressed_format, | 13830 width, height, border, format_info->decompressed_format, |
13769 format_info->decompressed_type, decompressed_data.get()); | 13831 format_info->decompressed_type, decompressed_data.get(), |
13832 texture->base_level(), | |
13833 workarounds().reset_teximage2d_base_level); | |
13770 } else { | 13834 } else { |
13771 glTexImage3D( | 13835 glTexImage3D( |
13772 target, level, format_info->decompressed_internal_format, | 13836 target, level, format_info->decompressed_internal_format, |
13773 width, height, depth, border, format_info->decompressed_format, | 13837 width, height, depth, border, format_info->decompressed_format, |
13774 format_info->decompressed_type, decompressed_data.get()); | 13838 format_info->decompressed_type, decompressed_data.get()); |
13775 } | 13839 } |
13776 state_.RestoreUnpackState(); | 13840 state_.RestoreUnpackState(); |
13777 } else { | 13841 } else { |
13778 if (dimension == ContextState::k2D) { | 13842 if (dimension == ContextState::k2D) { |
13779 glCompressedTexImage2D(target, level, internal_format, width, height, | 13843 glCompressedTexImage2D(target, level, internal_format, width, height, |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14398 | 14462 |
14399 if (src.x() != x || src.y() != y || | 14463 if (src.x() != x || src.y() != y || |
14400 src.width() != width || src.height() != height) { | 14464 src.width() != width || src.height() != height) { |
14401 { | 14465 { |
14402 // Add extra scope to destroy zero and the object it owns right | 14466 // Add extra scope to destroy zero and the object it owns right |
14403 // after its usage. | 14467 // after its usage. |
14404 // some part was clipped so clear the rect. | 14468 // some part was clipped so clear the rect. |
14405 | 14469 |
14406 std::unique_ptr<char[]> zero(new char[pixels_size]); | 14470 std::unique_ptr<char[]> zero(new char[pixels_size]); |
14407 memset(zero.get(), 0, pixels_size); | 14471 memset(zero.get(), 0, pixels_size); |
14408 glTexImage2D(target, level, final_internal_format, width, height, border, | 14472 TexImage2DHelper(target, level, final_internal_format, width, height, |
14409 format, type, zero.get()); | 14473 border, format, type, zero.get(), texture->base_level(), |
14474 workarounds().reset_teximage2d_base_level); | |
14410 } | 14475 } |
14411 | 14476 |
14412 if (!src.IsEmpty()) { | 14477 if (!src.IsEmpty()) { |
14413 GLint destX = src.x() - x; | 14478 GLint destX = src.x() - x; |
14414 GLint destY = src.y() - y; | 14479 GLint destY = src.y() - y; |
14415 if (requires_luma_blit) { | 14480 if (requires_luma_blit) { |
14416 copy_tex_image_blit_->DoCopyTexSubImageToLUMACompatibilityTexture( | 14481 copy_tex_image_blit_->DoCopyTexSubImageToLUMACompatibilityTexture( |
14417 this, texture->service_id(), texture->target(), target, format, | 14482 this, texture->service_id(), texture->target(), target, format, |
14418 type, level, destX, destY, 0, | 14483 type, level, destX, destY, 0, |
14419 src.x(), src.y(), src.width(), src.height(), | 14484 src.x(), src.y(), src.width(), src.height(), |
(...skipping 2426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16846 } | 16911 } |
16847 | 16912 |
16848 // Resize the destination texture to the dimensions of the source texture. | 16913 // Resize the destination texture to the dimensions of the source texture. |
16849 if (!dest_level_defined || dest_width != source_width || | 16914 if (!dest_level_defined || dest_width != source_width || |
16850 dest_height != source_height || | 16915 dest_height != source_height || |
16851 dest_internal_format != internal_format || | 16916 dest_internal_format != internal_format || |
16852 dest_type_previous != dest_type) { | 16917 dest_type_previous != dest_type) { |
16853 // Ensure that the glTexImage2D succeeds. | 16918 // Ensure that the glTexImage2D succeeds. |
16854 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); | 16919 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); |
16855 glBindTexture(dest_binding_target, dest_texture->service_id()); | 16920 glBindTexture(dest_binding_target, dest_texture->service_id()); |
16856 glTexImage2D(dest_target, dest_level, | 16921 TexImage2DHelper( |
16857 TextureManager::AdjustTexInternalFormat(feature_info_.get(), | 16922 dest_target, dest_level, |
16858 internal_format), | 16923 TextureManager::AdjustTexInternalFormat(feature_info_.get(), |
16859 source_width, source_height, 0, | 16924 internal_format), |
16860 TextureManager::AdjustTexFormat(feature_info_.get(), format), | 16925 source_width, source_height, 0, |
16861 dest_type, nullptr); | 16926 TextureManager::AdjustTexFormat(feature_info_.get(), format), dest_type, |
16927 nullptr, dest_texture->base_level(), | |
16928 workarounds().reset_teximage2d_base_level); | |
16862 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); | 16929 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); |
16863 if (error != GL_NO_ERROR) { | 16930 if (error != GL_NO_ERROR) { |
16864 RestoreCurrentTextureBindings(&state_, dest_binding_target, | 16931 RestoreCurrentTextureBindings(&state_, dest_binding_target, |
16865 state_.active_texture_unit); | 16932 state_.active_texture_unit); |
16866 return; | 16933 return; |
16867 } | 16934 } |
16868 | 16935 |
16869 texture_manager()->SetLevelInfo(dest_texture_ref, dest_target, dest_level, | 16936 texture_manager()->SetLevelInfo(dest_texture_ref, dest_target, dest_level, |
16870 internal_format, source_width, | 16937 internal_format, source_width, |
16871 source_height, 1, 0, format, dest_type, | 16938 source_height, 1, 0, format, dest_type, |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17295 } | 17362 } |
17296 | 17363 |
17297 TRACE_EVENT0( | 17364 TRACE_EVENT0( |
17298 "gpu", | 17365 "gpu", |
17299 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); | 17366 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); |
17300 | 17367 |
17301 DoBindOrCopyTexImageIfNeeded(source_texture, source_texture->target(), 0); | 17368 DoBindOrCopyTexImageIfNeeded(source_texture, source_texture->target(), 0); |
17302 | 17369 |
17303 // As a fallback, copy into a non-compressed GL_RGBA texture. | 17370 // As a fallback, copy into a non-compressed GL_RGBA texture. |
17304 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); | 17371 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); |
17305 glTexImage2D(dest_texture->target(), 0, GL_RGBA, source_width, source_height, | 17372 TexImage2DHelper(dest_texture->target(), 0, GL_RGBA, source_width, |
17306 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 17373 source_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr, |
17374 dest_texture->base_level(), | |
17375 workarounds().reset_teximage2d_base_level); | |
17307 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); | 17376 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); |
17308 if (error != GL_NO_ERROR) { | 17377 if (error != GL_NO_ERROR) { |
17309 RestoreCurrentTextureBindings(&state_, dest_texture->target(), | 17378 RestoreCurrentTextureBindings(&state_, dest_texture->target(), |
17310 state_.active_texture_unit); | 17379 state_.active_texture_unit); |
17311 return; | 17380 return; |
17312 } | 17381 } |
17313 | 17382 |
17314 texture_manager()->SetLevelInfo( | 17383 texture_manager()->SetLevelInfo( |
17315 dest_texture_ref, dest_texture->target(), 0, GL_RGBA, source_width, | 17384 dest_texture_ref, dest_texture->target(), 0, GL_RGBA, source_width, |
17316 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 17385 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
(...skipping 2365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19682 } | 19751 } |
19683 | 19752 |
19684 // Include the auto-generated part of this file. We split this because it means | 19753 // Include the auto-generated part of this file. We split this because it means |
19685 // we can easily edit the non-auto generated parts right here in this file | 19754 // we can easily edit the non-auto generated parts right here in this file |
19686 // instead of having to edit some template or the code generator. | 19755 // instead of having to edit some template or the code generator. |
19687 #include "base/macros.h" | 19756 #include "base/macros.h" |
19688 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 19757 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
19689 | 19758 |
19690 } // namespace gles2 | 19759 } // namespace gles2 |
19691 } // namespace gpu | 19760 } // namespace gpu |
OLD | NEW |