Chromium Code Reviews| 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/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 2527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2538 ? DoTexSubImageArguments::kTexSubImage3D | 2538 ? DoTexSubImageArguments::kTexSubImage3D |
| 2539 : DoTexSubImageArguments::kTexSubImage2D}; | 2539 : DoTexSubImageArguments::kTexSubImage2D}; |
| 2540 DoTexSubImageRowByRowWorkaround(texture_state, state, sub_args, | 2540 DoTexSubImageRowByRowWorkaround(texture_state, state, sub_args, |
| 2541 unpack_params); | 2541 unpack_params); |
| 2542 | 2542 |
| 2543 SetLevelCleared(texture_ref, args.target, args.level, true); | 2543 SetLevelCleared(texture_ref, args.target, args.level, true); |
| 2544 return; | 2544 return; |
| 2545 } | 2545 } |
| 2546 } | 2546 } |
| 2547 | 2547 |
| 2548 if (args.command_type == DoTexImageArguments::kTexImage3D && | |
| 2549 texture_state->unpack_image_height_workaround_with_unpack_buffer && | |
| 2550 buffer) { | |
| 2551 ContextState::Dimension dimension = ContextState::k3D; | |
| 2552 const PixelStoreParams unpack_params(state->GetUnpackParams(dimension)); | |
| 2553 if (unpack_params.image_height != 0 && | |
| 2554 unpack_params.image_height != args.height) { | |
| 2555 ReserveTexImageToBeFilled(texture_state, state, framebuffer_state, | |
| 2556 function_name, texture_ref, args); | |
| 2557 | |
| 2558 DoTexSubImageArguments sub_args = { | |
| 2559 args.target, | |
| 2560 args.level, | |
| 2561 0, | |
| 2562 0, | |
| 2563 0, | |
| 2564 args.width, | |
| 2565 args.height, | |
| 2566 args.depth, | |
| 2567 args.format, | |
| 2568 args.type, | |
| 2569 args.pixels, | |
| 2570 args.pixels_size, | |
| 2571 args.padding, | |
| 2572 DoTexSubImageArguments::kTexSubImage3D}; | |
| 2573 DoTexSubImageLayerByLayerWorkaround(texture_state, state, sub_args, | |
| 2574 unpack_params); | |
| 2575 | |
| 2576 SetLevelCleared(texture_ref, args.target, args.level, true); | |
| 2577 return; | |
| 2578 } | |
| 2579 } | |
| 2580 | |
| 2548 if (texture_state->unpack_alignment_workaround_with_unpack_buffer && buffer) { | 2581 if (texture_state->unpack_alignment_workaround_with_unpack_buffer && buffer) { |
| 2549 uint32_t buffer_size = static_cast<uint32_t>(buffer->size()); | 2582 uint32_t buffer_size = static_cast<uint32_t>(buffer->size()); |
| 2550 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding) { | 2583 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding) { |
| 2551 // In ValidateTexImage(), we already made sure buffer size is no less | 2584 // In ValidateTexImage(), we already made sure buffer size is no less |
| 2552 // than offset + pixels_size. | 2585 // than offset + pixels_size. |
| 2553 ReserveTexImageToBeFilled(texture_state, state, framebuffer_state, | 2586 ReserveTexImageToBeFilled(texture_state, state, framebuffer_state, |
| 2554 function_name, texture_ref, args); | 2587 function_name, texture_ref, args); |
| 2555 | 2588 |
| 2556 DoTexSubImageArguments sub_args = { | 2589 DoTexSubImageArguments sub_args = { |
| 2557 args.target, args.level, 0, 0, 0, args.width, args.height, args.depth, | 2590 args.target, args.level, 0, 0, 0, args.width, args.height, args.depth, |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2746 if (unpack_params.row_length != 0 && | 2779 if (unpack_params.row_length != 0 && |
| 2747 unpack_params.row_length < args.width) { | 2780 unpack_params.row_length < args.width) { |
| 2748 // The rows overlap in unpack memory. Upload the texture row by row to | 2781 // The rows overlap in unpack memory. Upload the texture row by row to |
| 2749 // work around driver bug. | 2782 // work around driver bug. |
| 2750 DoTexSubImageRowByRowWorkaround(texture_state, state, args, | 2783 DoTexSubImageRowByRowWorkaround(texture_state, state, args, |
| 2751 unpack_params); | 2784 unpack_params); |
| 2752 return; | 2785 return; |
| 2753 } | 2786 } |
| 2754 } | 2787 } |
| 2755 | 2788 |
| 2789 if (args.command_type == DoTexSubImageArguments::kTexSubImage3D && | |
| 2790 texture_state->unpack_image_height_workaround_with_unpack_buffer && | |
| 2791 buffer) { | |
| 2792 ContextState::Dimension dimension = ContextState::k3D; | |
| 2793 const PixelStoreParams unpack_params(state->GetUnpackParams(dimension)); | |
| 2794 if (unpack_params.image_height != 0 && | |
| 2795 unpack_params.image_height != args.height) { | |
| 2796 DoTexSubImageLayerByLayerWorkaround(texture_state, state, args, | |
| 2797 unpack_params); | |
| 2798 return; | |
| 2799 } | |
| 2800 } | |
| 2801 | |
| 2756 if (texture_state->unpack_alignment_workaround_with_unpack_buffer && buffer) { | 2802 if (texture_state->unpack_alignment_workaround_with_unpack_buffer && buffer) { |
| 2757 uint32_t buffer_size = static_cast<uint32_t>(buffer->size()); | 2803 uint32_t buffer_size = static_cast<uint32_t>(buffer->size()); |
| 2758 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding) { | 2804 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding) { |
| 2759 DoTexSubImageWithAlignmentWorkaround(texture_state, state, args); | 2805 DoTexSubImageWithAlignmentWorkaround(texture_state, state, args); |
| 2760 return; | 2806 return; |
| 2761 } | 2807 } |
| 2762 } | 2808 } |
| 2763 | 2809 |
| 2764 if (full_image && !texture_state->texsubimage_faster_than_teximage && | 2810 if (full_image && !texture_state->texsubimage_faster_than_teximage && |
| 2765 !texture->IsImmutable() && !texture->HasImages()) { | 2811 !texture->IsImmutable() && !texture->HasImages()) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2955 glTexSubImage2D(args.target, args.level, args.xoffset, row + args.yoffset, | 3001 glTexSubImage2D(args.target, args.level, args.xoffset, row + args.yoffset, |
| 2956 args.width, 1, format, args.type, row_pixels); | 3002 args.width, 1, format, args.type, row_pixels); |
| 2957 } | 3003 } |
| 2958 } | 3004 } |
| 2959 | 3005 |
| 2960 // Restore unpack state | 3006 // Restore unpack state |
| 2961 glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_params.alignment); | 3007 glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_params.alignment); |
| 2962 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpack_params.row_length); | 3008 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpack_params.row_length); |
| 2963 } | 3009 } |
| 2964 | 3010 |
| 3011 void TextureManager::DoTexSubImageLayerByLayerWorkaround( | |
| 3012 DecoderTextureState* texture_state, | |
| 3013 ContextState* state, | |
| 3014 const DoTexSubImageArguments& args, | |
| 3015 const PixelStoreParams& unpack_params) { | |
| 3016 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0); | |
| 3017 | |
| 3018 GLenum format = AdjustTexFormat(feature_info_.get(), args.format); | |
| 3019 | |
| 3020 GLsizei row_length = | |
| 3021 unpack_params.row_length ? unpack_params.row_length : args.width; | |
| 3022 GLsizei row_bytes = | |
| 3023 row_length * GLES2Util::ComputeImageGroupSize(format, args.type); | |
| 3024 GLsizei alignment_diff = row_bytes % unpack_params.alignment; | |
| 3025 if (alignment_diff != 0) { | |
| 3026 row_bytes += unpack_params.alignment - alignment_diff; | |
| 3027 } | |
| 3028 DCHECK_EQ(0, row_bytes % unpack_params.alignment); | |
| 3029 | |
| 3030 // process the texture layer by layer | |
| 3031 GLsizei image_height = unpack_params.image_height; | |
| 3032 GLsizei image_bytes = row_bytes * image_height; | |
| 3033 for (GLsizei image = 0; image < args.depth - 1; ++image) { | |
| 3034 GLsizei image_byte_offset = image * image_bytes; | |
| 3035 const GLubyte* image_pixels = | |
|
Zhenyao Mo
2016/10/14 21:29:09
You can move "const GLubyte* image_pixels = cast<c
jiajia.qin
2016/10/17 05:38:57
Done.
| |
| 3036 reinterpret_cast<const GLubyte*>(args.pixels) + image_byte_offset; | |
| 3037 glTexSubImage3D(args.target, args.level, args.xoffset, args.yoffset, | |
| 3038 image + args.zoffset, args.width, args.height, 1, format, | |
| 3039 args.type, image_pixels); | |
| 3040 } | |
| 3041 | |
| 3042 // Process the last image row by row | |
| 3043 GLsizei last_image_offset = (args.depth - 1) * image_bytes; | |
| 3044 const GLubyte* last_image_pixels = | |
| 3045 reinterpret_cast<const GLubyte*>(args.pixels) + last_image_offset; | |
| 3046 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | |
| 3047 for (GLsizei row = 0; row < args.height; ++row) { | |
| 3048 GLsizei byte_offset = row * row_bytes; | |
| 3049 const GLubyte* row_pixels = last_image_pixels + byte_offset; | |
|
Zhenyao Mo
2016/10/14 21:29:09
You can move "const GLubyte* row_pixels = image_pi
jiajia.qin
2016/10/17 05:38:57
Done.
| |
| 3050 glTexSubImage3D(args.target, args.level, args.xoffset, row + args.yoffset, | |
| 3051 args.depth - 1 + args.zoffset, args.width, 1, 1, format, | |
| 3052 args.type, row_pixels); | |
| 3053 } | |
| 3054 glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_params.alignment); | |
| 3055 | |
| 3056 // Restore unpack state | |
| 3057 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, unpack_params.image_height); | |
| 3058 } | |
| 3059 | |
| 2965 // static | 3060 // static |
| 2966 GLenum TextureManager::AdjustTexInternalFormat( | 3061 GLenum TextureManager::AdjustTexInternalFormat( |
| 2967 const gles2::FeatureInfo* feature_info, | 3062 const gles2::FeatureInfo* feature_info, |
| 2968 GLenum format) { | 3063 GLenum format) { |
| 2969 if (feature_info->gl_version_info().is_desktop_core_profile) { | 3064 if (feature_info->gl_version_info().is_desktop_core_profile) { |
| 2970 const Texture::CompatibilitySwizzle* swizzle = | 3065 const Texture::CompatibilitySwizzle* swizzle = |
| 2971 GetCompatibilitySwizzle(format); | 3066 GetCompatibilitySwizzle(format); |
| 2972 if (swizzle) | 3067 if (swizzle) |
| 2973 return swizzle->dest_format; | 3068 return swizzle->dest_format; |
| 2974 } | 3069 } |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3480 uint32_t TextureManager::GetServiceIdGeneration() const { | 3575 uint32_t TextureManager::GetServiceIdGeneration() const { |
| 3481 return current_service_id_generation_; | 3576 return current_service_id_generation_; |
| 3482 } | 3577 } |
| 3483 | 3578 |
| 3484 void TextureManager::IncrementServiceIdGeneration() { | 3579 void TextureManager::IncrementServiceIdGeneration() { |
| 3485 current_service_id_generation_++; | 3580 current_service_id_generation_++; |
| 3486 } | 3581 } |
| 3487 | 3582 |
| 3488 } // namespace gles2 | 3583 } // namespace gles2 |
| 3489 } // namespace gpu | 3584 } // namespace gpu |
| OLD | NEW |