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 2117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2128 }; | 2128 }; |
2129 | 2129 |
2130 // Same as above, but without the head and footroom. | 2130 // Same as above, but without the head and footroom. |
2131 float yuv_adjust_full[3] = { | 2131 float yuv_adjust_full[3] = { |
2132 0.0f, -128.f, -128.f, | 2132 0.0f, -128.f, -128.f, |
2133 }; | 2133 }; |
2134 | 2134 |
2135 float* yuv_to_rgb = NULL; | 2135 float* yuv_to_rgb = NULL; |
2136 float* yuv_adjust = NULL; | 2136 float* yuv_adjust = NULL; |
2137 | 2137 |
2138 gfx::ColorSpace gfx_color_space; | |
2138 switch (color_space) { | 2139 switch (color_space) { |
2139 case YUVVideoDrawQuad::REC_601: | 2140 case YUVVideoDrawQuad::REC_601: |
2140 yuv_to_rgb = yuv_to_rgb_rec601; | 2141 yuv_to_rgb = yuv_to_rgb_rec601; |
2141 yuv_adjust = yuv_adjust_constrained; | 2142 yuv_adjust = yuv_adjust_constrained; |
2143 gfx_color_space = gfx::ColorSpace::CreateREC601(); | |
2142 break; | 2144 break; |
2143 case YUVVideoDrawQuad::REC_709: | 2145 case YUVVideoDrawQuad::REC_709: |
2144 yuv_to_rgb = yuv_to_rgb_rec709; | 2146 yuv_to_rgb = yuv_to_rgb_rec709; |
2145 yuv_adjust = yuv_adjust_constrained; | 2147 yuv_adjust = yuv_adjust_constrained; |
2148 gfx_color_space = gfx::ColorSpace::CreateREC709(); | |
2146 break; | 2149 break; |
2147 case YUVVideoDrawQuad::JPEG: | 2150 case YUVVideoDrawQuad::JPEG: |
2148 yuv_to_rgb = yuv_to_rgb_jpeg; | 2151 yuv_to_rgb = yuv_to_rgb_jpeg; |
2149 yuv_adjust = yuv_adjust_full; | 2152 yuv_adjust = yuv_adjust_full; |
2153 gfx_color_space = gfx::ColorSpace::CreateJpeg(); | |
2150 break; | 2154 break; |
2151 } | 2155 } |
2152 | 2156 |
2153 // Formula according to BT.601-7 section 2.5.3. | 2157 // Formula according to BT.601-7 section 2.5.3. |
2154 DCHECK_LE(YUVVideoDrawQuad::kMinBitsPerChannel, bits_per_channel); | 2158 DCHECK_LE(YUVVideoDrawQuad::kMinBitsPerChannel, bits_per_channel); |
2155 DCHECK_LE(bits_per_channel, YUVVideoDrawQuad::kMaxBitsPerChannel); | 2159 DCHECK_LE(bits_per_channel, YUVVideoDrawQuad::kMaxBitsPerChannel); |
2156 float adjustment_multiplier = | 2160 float adjustment_multiplier = |
2157 (1 << (bits_per_channel - 8)) * 1.0f / ((1 << bits_per_channel) - 1); | 2161 (1 << (bits_per_channel - 8)) * 1.0f / ((1 << bits_per_channel) - 1); |
2158 | 2162 |
2159 for (int i = 0; i < 9; ++i) | 2163 for (int i = 0; i < 9; ++i) |
2160 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * resource_multiplier; | 2164 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * resource_multiplier; |
2161 | 2165 |
2162 for (int i = 0; i < 3; ++i) { | 2166 for (int i = 0; i < 3; ++i) { |
2163 yuv_adjust_with_offset[i] = | 2167 yuv_adjust_with_offset[i] = |
2164 yuv_adjust[i] * adjustment_multiplier / resource_multiplier - | 2168 yuv_adjust[i] * adjustment_multiplier / resource_multiplier - |
2165 resource_offset; | 2169 resource_offset; |
2166 } | 2170 } |
2171 | |
2172 // TODO(ccameron): Delete the above code, and just the below code instead. | |
2173 | |
2174 // Start with the resource adjust. | |
2175 SkMatrix44 full_transform; | |
hubbe
2017/02/02 04:51:37
I still think GetAffineApproximation() is a better
ccameron
2017/02/02 17:33:52
This patch is solving a different problem than tha
hubbe
2017/02/02 18:35:25
Matching is perhaps not the right goal since the c
| |
2176 { | |
2177 full_transform.setScale(resource_multiplier, resource_multiplier, | |
2178 resource_multiplier); | |
2179 full_transform.postTranslate(resource_offset, resource_offset, | |
2180 resource_offset); | |
2181 } | |
hubbe
2017/02/02 04:51:36
What is this {} for?
(Same for the ones below.)
ccameron
2017/02/02 17:33:52
In the instances below, it's to show to the reader
hubbe
2017/02/02 18:35:25
For me the add cognitive load when I read the code
| |
2182 | |
2183 // Then apply the range adjust. | |
2184 { | |
2185 SkMatrix44 range_adjust; | |
2186 gfx_color_space.GetRangeAdjustMatrix(&range_adjust); | |
2187 full_transform.postConcat(range_adjust); | |
2188 } | |
2189 | |
2190 // Then apply the YUV to RGB full_transform. | |
2191 { | |
2192 SkMatrix44 rgb_to_yuv; | |
2193 SkMatrix44 yuv_to_rgb; | |
2194 gfx_color_space.GetTransferMatrix(&rgb_to_yuv); | |
hubbe
2017/02/02 04:51:37
In one case, this is is not a linear matrix...
ccameron
2017/02/02 17:33:52
How to handle this in the general case is a good q
hubbe
2017/02/02 18:35:25
The problem with the BT2020_CL case is that it dep
| |
2195 rgb_to_yuv.invert(&yuv_to_rgb); | |
2196 full_transform.postConcat(yuv_to_rgb); | |
2197 } | |
2198 | |
2199 // For the upcoming DCHECKs, convert from the form | |
2200 // rgb = A*yuv+b | |
2201 // to the form | |
2202 // rgb = A*(yuv+b) | |
2203 float adjust[4] = {0, 0, 0, 0}; | |
2204 { | |
2205 SkMatrix44 full_transform_inverse; | |
2206 full_transform.invert(&full_transform_inverse); | |
2207 float adjust_preimage[4] = {full_transform.get(0, 3), | |
2208 full_transform.get(1, 3), | |
2209 full_transform.get(2, 3), 0}; | |
2210 full_transform_inverse.mapScalars(adjust_preimage, adjust); | |
2211 } | |
2212 | |
2213 // TODO(ccameron): The gfx::ColorSpace-based approach produces some pixel | |
2214 // differences. For the initial checkin, DCHECK that the parameters are | |
2215 // very close. The subsequent checkins will delete the old path. | |
2216 const float kEpsilon = 1.f / 255.f; | |
2217 for (int i = 0; i < 3; ++i) { | |
2218 for (int j = 0; j < 3; ++j) { | |
2219 float diff = yuv_to_rgb_multiplied[3 * j + i] - full_transform.get(i, j); | |
2220 DCHECK_LT(std::abs(diff), kEpsilon); | |
2221 } | |
2222 float diff = yuv_adjust_with_offset[i] - adjust[i]; | |
2223 DCHECK_LT(std::abs(diff), kEpsilon); | |
2224 } | |
2167 } | 2225 } |
2168 | 2226 |
2169 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, | 2227 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, |
2170 const YUVVideoDrawQuad* quad, | 2228 const YUVVideoDrawQuad* quad, |
2171 const gfx::QuadF* clip_region) { | 2229 const gfx::QuadF* clip_region) { |
2172 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2230 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
2173 | 2231 |
2174 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2232 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
2175 gl_, &highp_threshold_cache_, highp_threshold_min_, | 2233 gl_, &highp_threshold_cache_, highp_threshold_min_, |
2176 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 2234 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3597 return; | 3655 return; |
3598 | 3656 |
3599 // Report GPU overdraw as a percentage of |max_result|. | 3657 // Report GPU overdraw as a percentage of |max_result|. |
3600 TRACE_COUNTER1( | 3658 TRACE_COUNTER1( |
3601 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", | 3659 TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"), "GPU Overdraw", |
3602 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / | 3660 (std::accumulate(overdraw->begin(), overdraw->end(), 0) * 100) / |
3603 max_result); | 3661 max_result); |
3604 } | 3662 } |
3605 | 3663 |
3606 } // namespace cc | 3664 } // namespace cc |
OLD | NEW |