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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 bool enforce_internal_framebuffer, | 315 bool enforce_internal_framebuffer, |
316 bool internal); | 316 bool internal); |
317 ~ScopedResolvedFramebufferBinder(); | 317 ~ScopedResolvedFramebufferBinder(); |
318 | 318 |
319 private: | 319 private: |
320 GLES2DecoderImpl* decoder_; | 320 GLES2DecoderImpl* decoder_; |
321 bool resolve_and_bind_; | 321 bool resolve_and_bind_; |
322 DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFramebufferBinder); | 322 DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFramebufferBinder); |
323 }; | 323 }; |
324 | 324 |
325 // Reset a texture's base level and restore it after calling | |
326 // texImage2D | |
qiankun
2017/04/26 04:16:20
Merge line 325 and 326.
yizhou.jiang
2017/04/27 04:23:22
Done.
| |
327 class ScopedTextureBaseLevelResetter { | |
328 public: | |
329 explicit ScopedTextureBaseLevelResetter( | |
330 TextureRef* texture_ref, | |
331 scoped_refptr<gpu::gles2::FeatureInfo> feature_info); | |
332 ~ScopedTextureBaseLevelResetter(); | |
333 | |
334 private: | |
335 TextureRef* texture_ref_; | |
336 scoped_refptr<gpu::gles2::FeatureInfo> feature_info_; | |
337 DISALLOW_COPY_AND_ASSIGN(ScopedTextureBaseLevelResetter); | |
338 }; | |
339 | |
325 // Encapsulates an OpenGL texture. | 340 // Encapsulates an OpenGL texture. |
326 class BackTexture { | 341 class BackTexture { |
327 public: | 342 public: |
328 explicit BackTexture(GLES2DecoderImpl* decoder); | 343 explicit BackTexture(GLES2DecoderImpl* decoder); |
329 ~BackTexture(); | 344 ~BackTexture(); |
330 | 345 |
331 // Create a new render texture. | 346 // Create a new render texture. |
332 void Create(); | 347 void Create(); |
333 | 348 |
334 // Set the initial size and format of a render texture or resize it. | 349 // Set the initial size and format of a render texture or resize it. |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 GLint dstX1, | 675 GLint dstX1, |
661 GLint dstY1, | 676 GLint dstY1, |
662 GLbitfield mask, | 677 GLbitfield mask, |
663 GLenum filter); | 678 GLenum filter); |
664 | 679 |
665 PathManager* path_manager() { return group_->path_manager(); } | 680 PathManager* path_manager() { return group_->path_manager(); } |
666 | 681 |
667 private: | 682 private: |
668 friend class ScopedFramebufferBinder; | 683 friend class ScopedFramebufferBinder; |
669 friend class ScopedResolvedFramebufferBinder; | 684 friend class ScopedResolvedFramebufferBinder; |
685 friend class ScopedTextureBaseLevelResetter; | |
670 friend class BackFramebuffer; | 686 friend class BackFramebuffer; |
671 friend class BackRenderbuffer; | 687 friend class BackRenderbuffer; |
672 friend class BackTexture; | 688 friend class BackTexture; |
673 | 689 |
674 enum FramebufferOperation { | 690 enum FramebufferOperation { |
675 kFramebufferDiscard, | 691 kFramebufferDiscard, |
676 kFramebufferInvalidate, | 692 kFramebufferInvalidate, |
677 kFramebufferInvalidateSub | 693 kFramebufferInvalidateSub |
678 }; | 694 }; |
679 | 695 |
(...skipping 1899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2579 glBindFramebufferEXT(GL_FRAMEBUFFER, id); | 2595 glBindFramebufferEXT(GL_FRAMEBUFFER, id); |
2580 decoder->OnFboChanged(); | 2596 decoder->OnFboChanged(); |
2581 } | 2597 } |
2582 | 2598 |
2583 ScopedFramebufferBinder::~ScopedFramebufferBinder() { | 2599 ScopedFramebufferBinder::~ScopedFramebufferBinder() { |
2584 ScopedGLErrorSuppressor suppressor( | 2600 ScopedGLErrorSuppressor suppressor( |
2585 "ScopedFramebufferBinder::dtor", decoder_->GetErrorState()); | 2601 "ScopedFramebufferBinder::dtor", decoder_->GetErrorState()); |
2586 decoder_->RestoreCurrentFramebufferBindings(); | 2602 decoder_->RestoreCurrentFramebufferBindings(); |
2587 } | 2603 } |
2588 | 2604 |
2605 ScopedTextureBaseLevelResetter::ScopedTextureBaseLevelResetter( | |
2606 TextureRef* texture_ref, | |
2607 scoped_refptr<gpu::gles2::FeatureInfo> feature_info) | |
2608 : texture_ref_(texture_ref), feature_info_(feature_info) { | |
2609 if (texture_ref_ && | |
qiankun
2017/04/26 04:16:19
Isn't texture_ref_ always non-null? You can just p
yizhou.jiang
2017/04/27 04:23:22
Done.
| |
2610 feature_info_->workarounds().reset_teximage2d_base_level) { | |
2611 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); | |
2612 } | |
2613 } | |
2614 | |
2615 ScopedTextureBaseLevelResetter::~ScopedTextureBaseLevelResetter() { | |
2616 if (texture_ref_ && | |
2617 feature_info_->workarounds().reset_teximage2d_base_level) { | |
2618 Texture* texture = texture_ref_->texture(); | |
2619 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, | |
2620 texture->base_level()); | |
2621 } | |
2622 } | |
2623 | |
2589 ScopedResolvedFramebufferBinder::ScopedResolvedFramebufferBinder( | 2624 ScopedResolvedFramebufferBinder::ScopedResolvedFramebufferBinder( |
2590 GLES2DecoderImpl* decoder, bool enforce_internal_framebuffer, bool internal) | 2625 GLES2DecoderImpl* decoder, bool enforce_internal_framebuffer, bool internal) |
2591 : decoder_(decoder) { | 2626 : decoder_(decoder) { |
2592 resolve_and_bind_ = ( | 2627 resolve_and_bind_ = ( |
2593 decoder_->offscreen_target_frame_buffer_.get() && | 2628 decoder_->offscreen_target_frame_buffer_.get() && |
2594 decoder_->IsOffscreenBufferMultisampled() && | 2629 decoder_->IsOffscreenBufferMultisampled() && |
2595 (!decoder_->framebuffer_state_.bound_read_framebuffer.get() || | 2630 (!decoder_->framebuffer_state_.bound_read_framebuffer.get() || |
2596 enforce_internal_framebuffer)); | 2631 enforce_internal_framebuffer)); |
2597 if (!resolve_and_bind_) | 2632 if (!resolve_and_bind_) |
2598 return; | 2633 return; |
(...skipping 3683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6282 // chain is properly generated from the base level. | 6317 // chain is properly generated from the base level. |
6283 bool texture_zero_level_set = false; | 6318 bool texture_zero_level_set = false; |
6284 GLenum type = 0; | 6319 GLenum type = 0; |
6285 GLenum internal_format = 0; | 6320 GLenum internal_format = 0; |
6286 GLenum format = 0; | 6321 GLenum format = 0; |
6287 if (workarounds().set_zero_level_before_generating_mipmap && | 6322 if (workarounds().set_zero_level_before_generating_mipmap && |
6288 target == GL_TEXTURE_2D) { | 6323 target == GL_TEXTURE_2D) { |
6289 if (base_level != 0 && | 6324 if (base_level != 0 && |
6290 !tex->GetLevelType(target, 0, &type, &internal_format) && | 6325 !tex->GetLevelType(target, 0, &type, &internal_format) && |
6291 tex->GetLevelType(target, tex->base_level(), &type, &internal_format)) { | 6326 tex->GetLevelType(target, tex->base_level(), &type, &internal_format)) { |
6327 ScopedTextureBaseLevelResetter baseLevelResetter(texture_ref, | |
6328 feature_info_); | |
6292 format = TextureManager::ExtractFormatFromStorageFormat(internal_format); | 6329 format = TextureManager::ExtractFormatFromStorageFormat(internal_format); |
6293 glTexImage2D(target, 0, internal_format, 1, 1, 0, format, type, nullptr); | 6330 glTexImage2D(target, 0, internal_format, 1, 1, 0, format, type, nullptr); |
6294 texture_zero_level_set = true; | 6331 texture_zero_level_set = true; |
6295 } | 6332 } |
6296 } | 6333 } |
6297 | 6334 |
6298 bool enable_srgb = 0; | 6335 bool enable_srgb = 0; |
6299 if (target == GL_TEXTURE_2D) { | 6336 if (target == GL_TEXTURE_2D) { |
6300 tex->GetLevelType(target, tex->base_level(), &type, &internal_format); | 6337 tex->GetLevelType(target, tex->base_level(), &type, &internal_format); |
6301 enable_srgb = GLES2Util::GetColorEncodingFromInternalFormat( | 6338 enable_srgb = GLES2Util::GetColorEncodingFromInternalFormat( |
(...skipping 15 matching lines...) Expand all Loading... | |
6317 glGenerateMipmapEXT(target); | 6354 glGenerateMipmapEXT(target); |
6318 } | 6355 } |
6319 } else { | 6356 } else { |
6320 glGenerateMipmapEXT(target); | 6357 glGenerateMipmapEXT(target); |
6321 } | 6358 } |
6322 | 6359 |
6323 if (texture_zero_level_set) { | 6360 if (texture_zero_level_set) { |
6324 // This may have some unwanted side effects, but we expect command buffer | 6361 // This may have some unwanted side effects, but we expect command buffer |
6325 // validation to prevent you from doing anything weird with the texture | 6362 // validation to prevent you from doing anything weird with the texture |
6326 // after this, like calling texSubImage2D sucessfully. | 6363 // after this, like calling texSubImage2D sucessfully. |
6364 ScopedTextureBaseLevelResetter baseLevelResetter(texture_ref, | |
6365 feature_info_); | |
6327 glTexImage2D(target, 0, internal_format, 0, 0, 0, format, type, nullptr); | 6366 glTexImage2D(target, 0, internal_format, 0, 0, 0, format, type, nullptr); |
6328 } | 6367 } |
6329 | 6368 |
6330 if (workarounds().set_texture_filter_before_generating_mipmap) { | 6369 if (workarounds().set_texture_filter_before_generating_mipmap) { |
6331 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, | 6370 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, |
6332 texture_ref->texture()->min_filter()); | 6371 texture_ref->texture()->min_filter()); |
6333 } | 6372 } |
6334 GLenum error = LOCAL_PEEK_GL_ERROR("glGenerateMipmap"); | 6373 GLenum error = LOCAL_PEEK_GL_ERROR("glGenerateMipmap"); |
6335 if (error == GL_NO_ERROR) { | 6374 if (error == GL_NO_ERROR) { |
6336 texture_manager()->MarkMipmapsGenerated(texture_ref); | 6375 texture_manager()->MarkMipmapsGenerated(texture_ref); |
(...skipping 7417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13754 if (format_info != nullptr && !format_info->support_check(*feature_info_)) { | 13793 if (format_info != nullptr && !format_info->support_check(*feature_info_)) { |
13755 std::unique_ptr<uint8_t[]> decompressed_data = DecompressTextureData( | 13794 std::unique_ptr<uint8_t[]> decompressed_data = DecompressTextureData( |
13756 state_, *format_info, width, height, depth, image_size, data); | 13795 state_, *format_info, width, height, depth, image_size, data); |
13757 if (!decompressed_data) { | 13796 if (!decompressed_data) { |
13758 MarkContextLost(error::kGuilty); | 13797 MarkContextLost(error::kGuilty); |
13759 group_->LoseContexts(error::kInnocent); | 13798 group_->LoseContexts(error::kInnocent); |
13760 return error::kLostContext; | 13799 return error::kLostContext; |
13761 } | 13800 } |
13762 state_.PushTextureDecompressionUnpackState(); | 13801 state_.PushTextureDecompressionUnpackState(); |
13763 if (dimension == ContextState::k2D) { | 13802 if (dimension == ContextState::k2D) { |
13803 ScopedTextureBaseLevelResetter baseLevelResetter(texture_ref, | |
13804 feature_info_); | |
13764 glTexImage2D(target, level, format_info->decompressed_internal_format, | 13805 glTexImage2D(target, level, format_info->decompressed_internal_format, |
13765 width, height, border, format_info->decompressed_format, | 13806 width, height, border, format_info->decompressed_format, |
13766 format_info->decompressed_type, decompressed_data.get()); | 13807 format_info->decompressed_type, decompressed_data.get()); |
13767 } else { | 13808 } else { |
13768 glTexImage3D( | 13809 glTexImage3D( |
13769 target, level, format_info->decompressed_internal_format, | 13810 target, level, format_info->decompressed_internal_format, |
13770 width, height, depth, border, format_info->decompressed_format, | 13811 width, height, depth, border, format_info->decompressed_format, |
13771 format_info->decompressed_type, decompressed_data.get()); | 13812 format_info->decompressed_type, decompressed_data.get()); |
13772 } | 13813 } |
13773 state_.RestoreUnpackState(); | 13814 state_.RestoreUnpackState(); |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14395 | 14436 |
14396 if (src.x() != x || src.y() != y || | 14437 if (src.x() != x || src.y() != y || |
14397 src.width() != width || src.height() != height) { | 14438 src.width() != width || src.height() != height) { |
14398 { | 14439 { |
14399 // Add extra scope to destroy zero and the object it owns right | 14440 // Add extra scope to destroy zero and the object it owns right |
14400 // after its usage. | 14441 // after its usage. |
14401 // some part was clipped so clear the rect. | 14442 // some part was clipped so clear the rect. |
14402 | 14443 |
14403 std::unique_ptr<char[]> zero(new char[pixels_size]); | 14444 std::unique_ptr<char[]> zero(new char[pixels_size]); |
14404 memset(zero.get(), 0, pixels_size); | 14445 memset(zero.get(), 0, pixels_size); |
14446 | |
14447 ScopedTextureBaseLevelResetter baseLevelResetter(texture_ref, | |
14448 feature_info_); | |
14405 glTexImage2D(target, level, final_internal_format, width, height, border, | 14449 glTexImage2D(target, level, final_internal_format, width, height, border, |
14406 format, type, zero.get()); | 14450 format, type, zero.get()); |
14407 } | 14451 } |
14408 | 14452 |
14409 if (!src.IsEmpty()) { | 14453 if (!src.IsEmpty()) { |
14410 GLint destX = src.x() - x; | 14454 GLint destX = src.x() - x; |
14411 GLint destY = src.y() - y; | 14455 GLint destY = src.y() - y; |
14412 if (requires_luma_blit) { | 14456 if (requires_luma_blit) { |
14413 copy_tex_image_blit_->DoCopyTexSubImageToLUMACompatibilityTexture( | 14457 copy_tex_image_blit_->DoCopyTexSubImageToLUMACompatibilityTexture( |
14414 this, texture->service_id(), texture->target(), target, format, | 14458 this, texture->service_id(), texture->target(), target, format, |
(...skipping 2456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16871 } | 16915 } |
16872 | 16916 |
16873 // Resize the destination texture to the dimensions of the source texture. | 16917 // Resize the destination texture to the dimensions of the source texture. |
16874 if (!dest_level_defined || dest_width != source_width || | 16918 if (!dest_level_defined || dest_width != source_width || |
16875 dest_height != source_height || | 16919 dest_height != source_height || |
16876 dest_internal_format != internal_format || | 16920 dest_internal_format != internal_format || |
16877 dest_type_previous != dest_type) { | 16921 dest_type_previous != dest_type) { |
16878 // Ensure that the glTexImage2D succeeds. | 16922 // Ensure that the glTexImage2D succeeds. |
16879 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); | 16923 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); |
16880 glBindTexture(dest_binding_target, dest_texture->service_id()); | 16924 glBindTexture(dest_binding_target, dest_texture->service_id()); |
16925 ScopedTextureBaseLevelResetter baseLevelResetter(dest_texture_ref, | |
16926 feature_info_); | |
16881 glTexImage2D(dest_target, dest_level, | 16927 glTexImage2D(dest_target, dest_level, |
16882 TextureManager::AdjustTexInternalFormat(feature_info_.get(), | 16928 TextureManager::AdjustTexInternalFormat(feature_info_.get(), |
16883 internal_format), | 16929 internal_format), |
16884 source_width, source_height, 0, | 16930 source_width, source_height, 0, |
16885 TextureManager::AdjustTexFormat(feature_info_.get(), format), | 16931 TextureManager::AdjustTexFormat(feature_info_.get(), format), |
16886 dest_type, nullptr); | 16932 dest_type, nullptr); |
16887 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); | 16933 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); |
16888 if (error != GL_NO_ERROR) { | 16934 if (error != GL_NO_ERROR) { |
16889 RestoreCurrentTextureBindings(&state_, dest_binding_target); | 16935 RestoreCurrentTextureBindings(&state_, dest_binding_target); |
16890 return; | 16936 return; |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17318 } | 17364 } |
17319 | 17365 |
17320 TRACE_EVENT0( | 17366 TRACE_EVENT0( |
17321 "gpu", | 17367 "gpu", |
17322 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); | 17368 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); |
17323 | 17369 |
17324 DoCopyTexImageIfNeeded(source_texture, source_texture->target()); | 17370 DoCopyTexImageIfNeeded(source_texture, source_texture->target()); |
17325 | 17371 |
17326 // As a fallback, copy into a non-compressed GL_RGBA texture. | 17372 // As a fallback, copy into a non-compressed GL_RGBA texture. |
17327 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); | 17373 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); |
17328 glTexImage2D(dest_texture->target(), 0, GL_RGBA, source_width, source_height, | 17374 { |
17329 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 17375 ScopedTextureBaseLevelResetter baseLevelResetter(dest_texture_ref, |
17376 feature_info_); | |
17377 glTexImage2D(dest_texture->target(), 0, GL_RGBA, source_width, | |
17378 source_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | |
17379 } | |
17330 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); | 17380 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); |
17331 if (error != GL_NO_ERROR) { | 17381 if (error != GL_NO_ERROR) { |
17332 RestoreCurrentTextureBindings(&state_, dest_texture->target()); | 17382 RestoreCurrentTextureBindings(&state_, dest_texture->target()); |
17333 return; | 17383 return; |
17334 } | 17384 } |
17335 | 17385 |
17336 texture_manager()->SetLevelInfo( | 17386 texture_manager()->SetLevelInfo( |
17337 dest_texture_ref, dest_texture->target(), 0, GL_RGBA, source_width, | 17387 dest_texture_ref, dest_texture->target(), 0, GL_RGBA, source_width, |
17338 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | 17388 source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
17339 gfx::Rect(source_width, source_height)); | 17389 gfx::Rect(source_width, source_height)); |
(...skipping 2292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19632 } | 19682 } |
19633 | 19683 |
19634 // Include the auto-generated part of this file. We split this because it means | 19684 // Include the auto-generated part of this file. We split this because it means |
19635 // we can easily edit the non-auto generated parts right here in this file | 19685 // we can easily edit the non-auto generated parts right here in this file |
19636 // instead of having to edit some template or the code generator. | 19686 // instead of having to edit some template or the code generator. |
19637 #include "base/macros.h" | 19687 #include "base/macros.h" |
19638 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 19688 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
19639 | 19689 |
19640 } // namespace gles2 | 19690 } // namespace gles2 |
19641 } // namespace gpu | 19691 } // namespace gpu |
OLD | NEW |