OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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 "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "skia/ext/texture_handle.h" | 56 #include "skia/ext/texture_handle.h" |
57 #include "third_party/skia/include/core/SkBitmap.h" | 57 #include "third_party/skia/include/core/SkBitmap.h" |
58 #include "third_party/skia/include/core/SkColor.h" | 58 #include "third_party/skia/include/core/SkColor.h" |
59 #include "third_party/skia/include/core/SkColorFilter.h" | 59 #include "third_party/skia/include/core/SkColorFilter.h" |
60 #include "third_party/skia/include/core/SkImage.h" | 60 #include "third_party/skia/include/core/SkImage.h" |
61 #include "third_party/skia/include/core/SkSurface.h" | 61 #include "third_party/skia/include/core/SkSurface.h" |
62 #include "third_party/skia/include/gpu/GrContext.h" | 62 #include "third_party/skia/include/gpu/GrContext.h" |
63 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 63 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
64 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" | 64 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
65 #include "ui/gfx/color_space.h" | 65 #include "ui/gfx/color_space.h" |
| 66 #include "ui/gfx/color_transform.h" |
66 #include "ui/gfx/geometry/quad_f.h" | 67 #include "ui/gfx/geometry/quad_f.h" |
67 #include "ui/gfx/geometry/rect_conversions.h" | 68 #include "ui/gfx/geometry/rect_conversions.h" |
68 #include "ui/gfx/skia_util.h" | 69 #include "ui/gfx/skia_util.h" |
69 | 70 |
70 using gpu::gles2::GLES2Interface; | 71 using gpu::gles2::GLES2Interface; |
71 | 72 |
72 namespace cc { | 73 namespace cc { |
73 namespace { | 74 namespace { |
74 | 75 |
75 Float4 UVTransform(const TextureDrawQuad* quad) { | 76 Float4 UVTransform(const TextureDrawQuad* quad) { |
(...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2022 tile_quad.p3().x(), tile_quad.p3().y(), | 2023 tile_quad.p3().x(), tile_quad.p3().y(), |
2023 }; | 2024 }; |
2024 gl_->Uniform2fv(current_program_->quad_location(), 4, gl_quad); | 2025 gl_->Uniform2fv(current_program_->quad_location(), 4, gl_quad); |
2025 | 2026 |
2026 SetShaderMatrix(current_frame()->projection_matrix * | 2027 SetShaderMatrix(current_frame()->projection_matrix * |
2027 quad->shared_quad_state->quad_to_target_transform); | 2028 quad->shared_quad_state->quad_to_target_transform); |
2028 | 2029 |
2029 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); | 2030 gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); |
2030 } | 2031 } |
2031 | 2032 |
2032 // TODO(ccameron): This has been replicated in ui/gfx/color_transform.cc. Delete | |
2033 // one of the instances. | |
2034 void ComputeYUVToRGBMatrices(const gfx::ColorSpace& src_color_space, | |
2035 const gfx::ColorSpace& dst_color_space, | |
2036 uint32_t bits_per_channel, | |
2037 float resource_multiplier, | |
2038 float resource_offset, | |
2039 float* yuv_to_rgb_matrix) { | |
2040 // Compute the matrix |full_transform| which converts input YUV values to RGB | |
2041 // values. | |
2042 SkMatrix44 full_transform; | |
2043 | |
2044 // Start with the resource adjust. | |
2045 full_transform.setScale(resource_multiplier, resource_multiplier, | |
2046 resource_multiplier); | |
2047 full_transform.preTranslate(-resource_offset, -resource_offset, | |
2048 -resource_offset); | |
2049 | |
2050 // If we're using a LUT for conversion, we only need the resource adjust, | |
2051 // so just return this matrix. | |
2052 if (dst_color_space.IsValid()) { | |
2053 full_transform.asColMajorf(yuv_to_rgb_matrix); | |
2054 return; | |
2055 } | |
2056 | |
2057 // Then apply the range adjust. | |
2058 { | |
2059 SkMatrix44 range_adjust; | |
2060 src_color_space.GetRangeAdjustMatrix(&range_adjust); | |
2061 full_transform.postConcat(range_adjust); | |
2062 } | |
2063 | |
2064 // Then apply the YUV to RGB full_transform. | |
2065 { | |
2066 SkMatrix44 rgb_to_yuv; | |
2067 src_color_space.GetTransferMatrix(&rgb_to_yuv); | |
2068 SkMatrix44 yuv_to_rgb; | |
2069 rgb_to_yuv.invert(&yuv_to_rgb); | |
2070 full_transform.postConcat(yuv_to_rgb); | |
2071 } | |
2072 | |
2073 full_transform.asColMajorf(yuv_to_rgb_matrix); | |
2074 } | |
2075 | |
2076 void GLRenderer::DrawYUVVideoQuad(const YUVVideoDrawQuad* quad, | 2033 void GLRenderer::DrawYUVVideoQuad(const YUVVideoDrawQuad* quad, |
2077 const gfx::QuadF* clip_region) { | 2034 const gfx::QuadF* clip_region) { |
2078 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2035 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
2079 | 2036 |
2080 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2037 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
2081 gl_, &highp_threshold_cache_, highp_threshold_min_, | 2038 gl_, &highp_threshold_cache_, highp_threshold_min_, |
2082 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 2039 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
2083 YUVAlphaTextureMode alpha_texture_mode = quad->a_plane_resource_id() | 2040 YUVAlphaTextureMode alpha_texture_mode = quad->a_plane_resource_id() |
2084 ? YUV_HAS_ALPHA_TEXTURE | 2041 ? YUV_HAS_ALPHA_TEXTURE |
2085 : YUV_NO_ALPHA_TEXTURE; | 2042 : YUV_NO_ALPHA_TEXTURE; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2198 gl_->Uniform1i(current_program_->y_texture_location(), 1); | 2155 gl_->Uniform1i(current_program_->y_texture_location(), 1); |
2199 if (uv_texture_mode == UV_TEXTURE_MODE_UV) { | 2156 if (uv_texture_mode == UV_TEXTURE_MODE_UV) { |
2200 gl_->Uniform1i(current_program_->uv_texture_location(), 2); | 2157 gl_->Uniform1i(current_program_->uv_texture_location(), 2); |
2201 } else { | 2158 } else { |
2202 gl_->Uniform1i(current_program_->u_texture_location(), 2); | 2159 gl_->Uniform1i(current_program_->u_texture_location(), 2); |
2203 gl_->Uniform1i(current_program_->v_texture_location(), 3); | 2160 gl_->Uniform1i(current_program_->v_texture_location(), 3); |
2204 } | 2161 } |
2205 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) | 2162 if (alpha_texture_mode == YUV_HAS_ALPHA_TEXTURE) |
2206 gl_->Uniform1i(current_program_->a_texture_location(), 4); | 2163 gl_->Uniform1i(current_program_->a_texture_location(), 4); |
2207 | 2164 |
2208 float yuv_to_rgb_matrix[16] = {0}; | 2165 gl_->Uniform1f(current_program_->resource_multiplier_location(), |
2209 ComputeYUVToRGBMatrices(src_color_space, dst_color_space, | 2166 quad->resource_multiplier); |
2210 quad->bits_per_channel, quad->resource_multiplier, | 2167 gl_->Uniform1f(current_program_->resource_offset_location(), |
2211 quad->resource_offset, yuv_to_rgb_matrix); | 2168 quad->resource_offset); |
2212 gl_->UniformMatrix4fv(current_program_->yuv_and_resource_matrix_location(), 1, | |
2213 0, yuv_to_rgb_matrix); | |
2214 | 2169 |
2215 // The transform and vertex data are used to figure out the extents that the | 2170 // The transform and vertex data are used to figure out the extents that the |
2216 // un-antialiased quad should have and which vertex this is and the float | 2171 // un-antialiased quad should have and which vertex this is and the float |
2217 // quad passed in via uniform is the actual geometry that gets used to draw | 2172 // quad passed in via uniform is the actual geometry that gets used to draw |
2218 // it. This is why this centered rect is used and not the original quad_rect. | 2173 // it. This is why this centered rect is used and not the original quad_rect. |
2219 auto tile_rect = gfx::RectF(quad->rect); | 2174 auto tile_rect = gfx::RectF(quad->rect); |
2220 | 2175 |
2221 SetShaderOpacity(quad); | 2176 SetShaderOpacity(quad); |
2222 if (!clip_region) { | 2177 if (!clip_region) { |
2223 DrawQuadGeometry(current_frame()->projection_matrix, | 2178 DrawQuadGeometry(current_frame()->projection_matrix, |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3025 gfx::ColorSpace dst_color_space; | 2980 gfx::ColorSpace dst_color_space; |
3026 if (settings_->enable_color_correct_rendering) | 2981 if (settings_->enable_color_correct_rendering) |
3027 dst_color_space = current_frame()->current_render_pass->color_space; | 2982 dst_color_space = current_frame()->current_render_pass->color_space; |
3028 SetUseProgram(program_key, src_color_space, dst_color_space); | 2983 SetUseProgram(program_key, src_color_space, dst_color_space); |
3029 } | 2984 } |
3030 | 2985 |
3031 void GLRenderer::SetUseProgram(const ProgramKey& program_key_no_color, | 2986 void GLRenderer::SetUseProgram(const ProgramKey& program_key_no_color, |
3032 const gfx::ColorSpace& src_color_space, | 2987 const gfx::ColorSpace& src_color_space, |
3033 const gfx::ColorSpace& dst_color_space) { | 2988 const gfx::ColorSpace& dst_color_space) { |
3034 ProgramKey program_key = program_key_no_color; | 2989 ProgramKey program_key = program_key_no_color; |
3035 if (src_color_space.IsValid() && dst_color_space.IsValid()) | 2990 const gfx::ColorTransform* color_transform = |
3036 program_key.SetColorConversionMode(COLOR_CONVERSION_MODE_LUT); | 2991 GetColorTransform(src_color_space, dst_color_space); |
| 2992 program_key.SetColorTransform(color_transform); |
3037 | 2993 |
3038 // Create and set the program if needed. | 2994 // Create and set the program if needed. |
3039 std::unique_ptr<Program>& program = program_cache_[program_key]; | 2995 std::unique_ptr<Program>& program = program_cache_[program_key]; |
3040 if (!program) { | 2996 if (!program) { |
3041 program.reset(new Program); | 2997 program.reset(new Program); |
3042 program->Initialize(output_surface_->context_provider(), program_key); | 2998 program->Initialize(output_surface_->context_provider(), program_key); |
3043 } | 2999 } |
3044 DCHECK(program); | 3000 DCHECK(program); |
3045 if (current_program_ != program.get()) { | 3001 if (current_program_ != program.get()) { |
3046 current_program_ = program.get(); | 3002 current_program_ = program.get(); |
(...skipping 10 matching lines...) Expand all Loading... |
3057 if (current_program_->viewport_location() != -1) { | 3013 if (current_program_->viewport_location() != -1) { |
3058 float viewport[4] = { | 3014 float viewport[4] = { |
3059 static_cast<float>(current_window_space_viewport_.x()), | 3015 static_cast<float>(current_window_space_viewport_.x()), |
3060 static_cast<float>(current_window_space_viewport_.y()), | 3016 static_cast<float>(current_window_space_viewport_.y()), |
3061 static_cast<float>(current_window_space_viewport_.width()), | 3017 static_cast<float>(current_window_space_viewport_.width()), |
3062 static_cast<float>(current_window_space_viewport_.height()), | 3018 static_cast<float>(current_window_space_viewport_.height()), |
3063 }; | 3019 }; |
3064 gl_->Uniform4fv(current_program_->viewport_location(), 1, viewport); | 3020 gl_->Uniform4fv(current_program_->viewport_location(), 1, viewport); |
3065 } | 3021 } |
3066 if (current_program_->lut_texture_location() != -1) { | 3022 if (current_program_->lut_texture_location() != -1) { |
3067 ColorLUTCache::LUT lut = | 3023 ColorLUTCache::LUT lut = color_lut_cache_.GetLUT(color_transform); |
3068 color_lut_cache_.GetLUT(src_color_space, dst_color_space); | |
3069 gl_->ActiveTexture(GL_TEXTURE5); | 3024 gl_->ActiveTexture(GL_TEXTURE5); |
3070 gl_->BindTexture(GL_TEXTURE_2D, lut.texture); | 3025 gl_->BindTexture(GL_TEXTURE_2D, lut.texture); |
3071 gl_->Uniform1i(current_program_->lut_texture_location(), 5); | 3026 gl_->Uniform1i(current_program_->lut_texture_location(), 5); |
3072 gl_->Uniform1f(current_program_->lut_size_location(), lut.size); | 3027 gl_->Uniform1f(current_program_->lut_size_location(), lut.size); |
3073 gl_->ActiveTexture(GL_TEXTURE0); | 3028 gl_->ActiveTexture(GL_TEXTURE0); |
3074 } | 3029 } |
3075 } | 3030 } |
3076 | 3031 |
3077 const Program* GLRenderer::GetProgramIfInitialized( | 3032 const Program* GLRenderer::GetProgramIfInitialized( |
3078 const ProgramKey& desc) const { | 3033 const ProgramKey& desc) const { |
3079 const auto found = program_cache_.find(desc); | 3034 const auto found = program_cache_.find(desc); |
3080 if (found == program_cache_.end()) | 3035 if (found == program_cache_.end()) |
3081 return nullptr; | 3036 return nullptr; |
3082 return found->second.get(); | 3037 return found->second.get(); |
3083 } | 3038 } |
3084 | 3039 |
| 3040 const gfx::ColorTransform* GLRenderer::GetColorTransform( |
| 3041 const gfx::ColorSpace& src, |
| 3042 const gfx::ColorSpace& dst) { |
| 3043 std::unique_ptr<gfx::ColorTransform>& transform = |
| 3044 color_transform_cache_[dst][src]; |
| 3045 if (!transform) { |
| 3046 transform = gfx::ColorTransform::NewColorTransform( |
| 3047 src, dst, gfx::ColorTransform::Intent::INTENT_PERCEPTUAL); |
| 3048 } |
| 3049 return transform.get(); |
| 3050 } |
| 3051 |
3085 void GLRenderer::CleanupSharedObjects() { | 3052 void GLRenderer::CleanupSharedObjects() { |
3086 shared_geometry_ = nullptr; | 3053 shared_geometry_ = nullptr; |
3087 | 3054 |
3088 for (auto& iter : program_cache_) | 3055 for (auto& iter : program_cache_) |
3089 iter.second->Cleanup(gl_); | 3056 iter.second->Cleanup(gl_); |
3090 program_cache_.clear(); | 3057 program_cache_.clear(); |
| 3058 color_transform_cache_.clear(); |
3091 | 3059 |
3092 if (offscreen_framebuffer_id_) | 3060 if (offscreen_framebuffer_id_) |
3093 gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_); | 3061 gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_); |
3094 | 3062 |
3095 if (offscreen_stencil_renderbuffer_id_) | 3063 if (offscreen_stencil_renderbuffer_id_) |
3096 gl_->DeleteRenderbuffers(1, &offscreen_stencil_renderbuffer_id_); | 3064 gl_->DeleteRenderbuffers(1, &offscreen_stencil_renderbuffer_id_); |
3097 | 3065 |
3098 ReleaseRenderPassTextures(); | 3066 ReleaseRenderPassTextures(); |
3099 } | 3067 } |
3100 | 3068 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3530 return; | 3498 return; |
3531 | 3499 |
3532 // Report GPU overdraw as a percentage of |max_result|. | 3500 // Report GPU overdraw as a percentage of |max_result|. |
3533 TRACE_COUNTER1( | 3501 TRACE_COUNTER1( |
3534 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", | 3502 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", |
3535 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / | 3503 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / |
3536 max_result); | 3504 max_result); |
3537 } | 3505 } |
3538 | 3506 |
3539 } // namespace cc | 3507 } // namespace cc |
OLD | NEW |