OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/color_lut_cache.h" | 5 #include "cc/output/color_lut_cache.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 ColorLUTCache::LUT ColorLUTCache::GetLUT(const gfx::ColorTransform* transform) { | 98 ColorLUTCache::LUT ColorLUTCache::GetLUT(const gfx::ColorTransform* transform) { |
99 auto iter = lut_cache_.Get(transform); | 99 auto iter = lut_cache_.Get(transform); |
100 if (iter != lut_cache_.end()) { | 100 if (iter != lut_cache_.end()) { |
101 iter->second.last_used_frame = current_frame_; | 101 iter->second.last_used_frame = current_frame_; |
102 return iter->second.lut; | 102 return iter->second.lut; |
103 } | 103 } |
104 | 104 |
105 LUT lut; | 105 LUT lut; |
106 // If input is HDR, and the output is scRGB, we're going to need | 106 // If input is HDR, and the output is full range, we're going to need |
107 // to produce values outside of 0-1, so we'll need to make a half-float | 107 // to produce values outside of 0-1, so we'll need to make a half-float |
108 // LUT. Also, we'll need to build a larger lut to maintain accuracy. | 108 // LUT. Also, we'll need to build a larger lut to maintain accuracy. |
109 // All LUT sizes should be odd a some transforms hav a knee at 0.5. | 109 // All LUT sizes should be odd as some transforms have a knee at 0.5. |
110 if (transform->GetDstColorSpace() == gfx::ColorSpace::CreateSCRGBLinear() && | 110 if (transform->GetDstColorSpace().FullRangeEncodedValues() && |
111 transform->GetSrcColorSpace().IsHDR() && texture_half_float_linear_) { | 111 transform->GetSrcColorSpace().IsHDR() && texture_half_float_linear_) { |
112 lut.size = 37; | 112 lut.size = 37; |
113 lut.texture = MakeLUT<uint16_t>(transform, lut.size); | 113 lut.texture = MakeLUT<uint16_t>(transform, lut.size); |
114 } else { | 114 } else { |
115 lut.size = 17; | 115 lut.size = 17; |
116 lut.texture = MakeLUT<unsigned char>(transform, lut.size); | 116 lut.texture = MakeLUT<unsigned char>(transform, lut.size); |
117 } | 117 } |
118 lut_cache_.Put(transform, CacheVal(lut, current_frame_)); | 118 lut_cache_.Put(transform, CacheVal(lut, current_frame_)); |
119 return lut; | 119 return lut; |
120 } | 120 } |
121 | 121 |
122 void ColorLUTCache::Swap() { | 122 void ColorLUTCache::Swap() { |
123 current_frame_++; | 123 current_frame_++; |
124 while (!lut_cache_.empty() && | 124 while (!lut_cache_.empty() && |
125 current_frame_ - lut_cache_.rbegin()->second.last_used_frame > | 125 current_frame_ - lut_cache_.rbegin()->second.last_used_frame > |
126 kMaxFramesUnused) { | 126 kMaxFramesUnused) { |
127 gl_->DeleteTextures(1, &lut_cache_.rbegin()->second.lut.texture); | 127 gl_->DeleteTextures(1, &lut_cache_.rbegin()->second.lut.texture); |
128 lut_cache_.ShrinkToSize(lut_cache_.size() - 1); | 128 lut_cache_.ShrinkToSize(lut_cache_.size() - 1); |
129 } | 129 } |
130 } | 130 } |
OLD | NEW |