| 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 2554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2565 ? DoTexSubImageArguments::kTexSubImage3D | 2565 ? DoTexSubImageArguments::kTexSubImage3D |
| 2566 : DoTexSubImageArguments::kTexSubImage2D}; | 2566 : DoTexSubImageArguments::kTexSubImage2D}; |
| 2567 DoTexSubImageRowByRowWorkaround(texture_state, state, sub_args, | 2567 DoTexSubImageRowByRowWorkaround(texture_state, state, sub_args, |
| 2568 unpack_params); | 2568 unpack_params); |
| 2569 | 2569 |
| 2570 SetLevelCleared(texture_ref, args.target, args.level, true); | 2570 SetLevelCleared(texture_ref, args.target, args.level, true); |
| 2571 return; | 2571 return; |
| 2572 } | 2572 } |
| 2573 } | 2573 } |
| 2574 | 2574 |
| 2575 if (args.command_type == DoTexImageArguments::kTexImage3D && |
| 2576 texture_state->unpack_image_height_workaround_with_unpack_buffer && |
| 2577 buffer) { |
| 2578 ContextState::Dimension dimension = ContextState::k3D; |
| 2579 const PixelStoreParams unpack_params(state->GetUnpackParams(dimension)); |
| 2580 if (unpack_params.image_height != 0 && |
| 2581 unpack_params.image_height != args.height) { |
| 2582 ReserveTexImageToBeFilled(texture_state, state, framebuffer_state, |
| 2583 function_name, texture_ref, args); |
| 2584 |
| 2585 DoTexSubImageArguments sub_args = { |
| 2586 args.target, |
| 2587 args.level, |
| 2588 0, |
| 2589 0, |
| 2590 0, |
| 2591 args.width, |
| 2592 args.height, |
| 2593 args.depth, |
| 2594 args.format, |
| 2595 args.type, |
| 2596 args.pixels, |
| 2597 args.pixels_size, |
| 2598 args.padding, |
| 2599 DoTexSubImageArguments::kTexSubImage3D}; |
| 2600 DoTexSubImageLayerByLayerWorkaround(texture_state, state, sub_args, |
| 2601 unpack_params); |
| 2602 |
| 2603 SetLevelCleared(texture_ref, args.target, args.level, true); |
| 2604 return; |
| 2605 } |
| 2606 } |
| 2607 |
| 2575 if (texture_state->unpack_alignment_workaround_with_unpack_buffer && buffer) { | 2608 if (texture_state->unpack_alignment_workaround_with_unpack_buffer && buffer) { |
| 2576 uint32_t buffer_size = static_cast<uint32_t>(buffer->size()); | 2609 uint32_t buffer_size = static_cast<uint32_t>(buffer->size()); |
| 2577 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding) { | 2610 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding) { |
| 2578 // In ValidateTexImage(), we already made sure buffer size is no less | 2611 // In ValidateTexImage(), we already made sure buffer size is no less |
| 2579 // than offset + pixels_size. | 2612 // than offset + pixels_size. |
| 2580 ReserveTexImageToBeFilled(texture_state, state, framebuffer_state, | 2613 ReserveTexImageToBeFilled(texture_state, state, framebuffer_state, |
| 2581 function_name, texture_ref, args); | 2614 function_name, texture_ref, args); |
| 2582 | 2615 |
| 2583 DoTexSubImageArguments sub_args = { | 2616 DoTexSubImageArguments sub_args = { |
| 2584 args.target, args.level, 0, 0, 0, args.width, args.height, args.depth, | 2617 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... |
| 2773 if (unpack_params.row_length != 0 && | 2806 if (unpack_params.row_length != 0 && |
| 2774 unpack_params.row_length < args.width) { | 2807 unpack_params.row_length < args.width) { |
| 2775 // The rows overlap in unpack memory. Upload the texture row by row to | 2808 // The rows overlap in unpack memory. Upload the texture row by row to |
| 2776 // work around driver bug. | 2809 // work around driver bug. |
| 2777 DoTexSubImageRowByRowWorkaround(texture_state, state, args, | 2810 DoTexSubImageRowByRowWorkaround(texture_state, state, args, |
| 2778 unpack_params); | 2811 unpack_params); |
| 2779 return; | 2812 return; |
| 2780 } | 2813 } |
| 2781 } | 2814 } |
| 2782 | 2815 |
| 2816 if (args.command_type == DoTexSubImageArguments::kTexSubImage3D && |
| 2817 texture_state->unpack_image_height_workaround_with_unpack_buffer && |
| 2818 buffer) { |
| 2819 ContextState::Dimension dimension = ContextState::k3D; |
| 2820 const PixelStoreParams unpack_params(state->GetUnpackParams(dimension)); |
| 2821 if (unpack_params.image_height != 0 && |
| 2822 unpack_params.image_height != args.height) { |
| 2823 DoTexSubImageLayerByLayerWorkaround(texture_state, state, args, |
| 2824 unpack_params); |
| 2825 return; |
| 2826 } |
| 2827 } |
| 2828 |
| 2783 if (texture_state->unpack_alignment_workaround_with_unpack_buffer && buffer) { | 2829 if (texture_state->unpack_alignment_workaround_with_unpack_buffer && buffer) { |
| 2784 uint32_t buffer_size = static_cast<uint32_t>(buffer->size()); | 2830 uint32_t buffer_size = static_cast<uint32_t>(buffer->size()); |
| 2785 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding) { | 2831 if (buffer_size - args.pixels_size - ToGLuint(args.pixels) < args.padding) { |
| 2786 DoTexSubImageWithAlignmentWorkaround(texture_state, state, args); | 2832 DoTexSubImageWithAlignmentWorkaround(texture_state, state, args); |
| 2787 return; | 2833 return; |
| 2788 } | 2834 } |
| 2789 } | 2835 } |
| 2790 | 2836 |
| 2791 if (full_image && !texture_state->texsubimage_faster_than_teximage && | 2837 if (full_image && !texture_state->texsubimage_faster_than_teximage && |
| 2792 !texture->IsImmutable() && !texture->HasImages()) { | 2838 !texture->IsImmutable() && !texture->HasImages()) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2982 glTexSubImage2D(args.target, args.level, args.xoffset, row + args.yoffset, | 3028 glTexSubImage2D(args.target, args.level, args.xoffset, row + args.yoffset, |
| 2983 args.width, 1, format, args.type, row_pixels); | 3029 args.width, 1, format, args.type, row_pixels); |
| 2984 } | 3030 } |
| 2985 } | 3031 } |
| 2986 | 3032 |
| 2987 // Restore unpack state | 3033 // Restore unpack state |
| 2988 glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_params.alignment); | 3034 glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_params.alignment); |
| 2989 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpack_params.row_length); | 3035 glPixelStorei(GL_UNPACK_ROW_LENGTH, unpack_params.row_length); |
| 2990 } | 3036 } |
| 2991 | 3037 |
| 3038 void TextureManager::DoTexSubImageLayerByLayerWorkaround( |
| 3039 DecoderTextureState* texture_state, |
| 3040 ContextState* state, |
| 3041 const DoTexSubImageArguments& args, |
| 3042 const PixelStoreParams& unpack_params) { |
| 3043 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0); |
| 3044 |
| 3045 GLenum format = AdjustTexFormat(feature_info_.get(), args.format); |
| 3046 |
| 3047 GLsizei row_length = |
| 3048 unpack_params.row_length ? unpack_params.row_length : args.width; |
| 3049 GLsizei row_bytes = |
| 3050 row_length * GLES2Util::ComputeImageGroupSize(format, args.type); |
| 3051 GLsizei alignment_diff = row_bytes % unpack_params.alignment; |
| 3052 if (alignment_diff != 0) { |
| 3053 row_bytes += unpack_params.alignment - alignment_diff; |
| 3054 } |
| 3055 DCHECK_EQ(0, row_bytes % unpack_params.alignment); |
| 3056 |
| 3057 // process the texture layer by layer |
| 3058 GLsizei image_height = unpack_params.image_height; |
| 3059 GLsizei image_bytes = row_bytes * image_height; |
| 3060 const GLubyte* image_pixels = reinterpret_cast<const GLubyte*>(args.pixels); |
| 3061 for (GLsizei image = 0; image < args.depth - 1; ++image) { |
| 3062 glTexSubImage3D(args.target, args.level, args.xoffset, args.yoffset, |
| 3063 image + args.zoffset, args.width, args.height, 1, format, |
| 3064 args.type, image_pixels); |
| 3065 |
| 3066 image_pixels += image_bytes; |
| 3067 } |
| 3068 |
| 3069 // Process the last image row by row |
| 3070 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 3071 const GLubyte* row_pixels = image_pixels; |
| 3072 for (GLsizei row = 0; row < args.height; ++row) { |
| 3073 glTexSubImage3D(args.target, args.level, args.xoffset, row + args.yoffset, |
| 3074 args.depth - 1 + args.zoffset, args.width, 1, 1, format, |
| 3075 args.type, row_pixels); |
| 3076 row_pixels += row_bytes; |
| 3077 } |
| 3078 // Restore unpack state |
| 3079 glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_params.alignment); |
| 3080 glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, unpack_params.image_height); |
| 3081 } |
| 3082 |
| 2992 // static | 3083 // static |
| 2993 GLenum TextureManager::AdjustTexInternalFormat( | 3084 GLenum TextureManager::AdjustTexInternalFormat( |
| 2994 const gles2::FeatureInfo* feature_info, | 3085 const gles2::FeatureInfo* feature_info, |
| 2995 GLenum format) { | 3086 GLenum format) { |
| 2996 if (feature_info->gl_version_info().is_desktop_core_profile) { | 3087 if (feature_info->gl_version_info().is_desktop_core_profile) { |
| 2997 const Texture::CompatibilitySwizzle* swizzle = | 3088 const Texture::CompatibilitySwizzle* swizzle = |
| 2998 GetCompatibilitySwizzle(format); | 3089 GetCompatibilitySwizzle(format); |
| 2999 if (swizzle) | 3090 if (swizzle) |
| 3000 return swizzle->dest_format; | 3091 return swizzle->dest_format; |
| 3001 } | 3092 } |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3507 uint32_t TextureManager::GetServiceIdGeneration() const { | 3598 uint32_t TextureManager::GetServiceIdGeneration() const { |
| 3508 return current_service_id_generation_; | 3599 return current_service_id_generation_; |
| 3509 } | 3600 } |
| 3510 | 3601 |
| 3511 void TextureManager::IncrementServiceIdGeneration() { | 3602 void TextureManager::IncrementServiceIdGeneration() { |
| 3512 current_service_id_generation_++; | 3603 current_service_id_generation_++; |
| 3513 } | 3604 } |
| 3514 | 3605 |
| 3515 } // namespace gles2 | 3606 } // namespace gles2 |
| 3516 } // namespace gpu | 3607 } // namespace gpu |
| OLD | NEW |