OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/output/render_surface_filters.h" | 5 #include "cc/output/render_surface_filters.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "skia/ext/refptr.h" | 8 #include "skia/ext/refptr.h" |
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperation.
h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperation.
h" |
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" | 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 void GetContrastMatrix(float amount, SkScalar matrix[20]) { | 40 void GetContrastMatrix(float amount, SkScalar matrix[20]) { |
41 memset(matrix, 0, 20 * sizeof(SkScalar)); | 41 memset(matrix, 0, 20 * sizeof(SkScalar)); |
42 matrix[0] = matrix[6] = matrix[12] = amount; | 42 matrix[0] = matrix[6] = matrix[12] = amount; |
43 matrix[4] = matrix[9] = matrix[14] = (-0.5f * amount + 0.5f) * 255.f; | 43 matrix[4] = matrix[9] = matrix[14] = (-0.5f * amount + 0.5f) * 255.f; |
44 matrix[18] = 1.f; | 44 matrix[18] = 1.f; |
45 } | 45 } |
46 | 46 |
47 void GetSaturateMatrix(float amount, SkScalar matrix[20]) { | 47 void GetSaturateMatrix(float amount, SkScalar matrix[20]) { |
48 // Note, these values are computed to ensure matrixNeedsClamping is false | 48 // Note, these values are computed to ensure MatrixNeedsClamping is false |
49 // for amount in [0..1] | 49 // for amount in [0..1] |
50 matrix[0] = 0.213f + 0.787f * amount; | 50 matrix[0] = 0.213f + 0.787f * amount; |
51 matrix[1] = 0.715f - 0.715f * amount; | 51 matrix[1] = 0.715f - 0.715f * amount; |
52 matrix[2] = 1.f - (matrix[0] + matrix[1]); | 52 matrix[2] = 1.f - (matrix[0] + matrix[1]); |
53 matrix[3] = matrix[4] = 0.f; | 53 matrix[3] = matrix[4] = 0.f; |
54 matrix[5] = 0.213f - 0.213f * amount; | 54 matrix[5] = 0.213f - 0.213f * amount; |
55 matrix[6] = 0.715f + 0.285f * amount; | 55 matrix[6] = 0.715f + 0.285f * amount; |
56 matrix[7] = 1.f - (matrix[5] + matrix[6]); | 56 matrix[7] = 1.f - (matrix[5] + matrix[6]); |
57 matrix[8] = matrix[9] = 0.f; | 57 matrix[8] = matrix[9] = 0.f; |
58 matrix[10] = 0.213f - 0.213f * amount; | 58 matrix[10] = 0.213f - 0.213f * amount; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 matrix[18] = 1.f; | 92 matrix[18] = 1.f; |
93 } | 93 } |
94 | 94 |
95 void GetOpacityMatrix(float amount, SkScalar matrix[20]) { | 95 void GetOpacityMatrix(float amount, SkScalar matrix[20]) { |
96 memset(matrix, 0, 20 * sizeof(SkScalar)); | 96 memset(matrix, 0, 20 * sizeof(SkScalar)); |
97 matrix[0] = matrix[6] = matrix[12] = 1.f; | 97 matrix[0] = matrix[6] = matrix[12] = 1.f; |
98 matrix[18] = amount; | 98 matrix[18] = amount; |
99 } | 99 } |
100 | 100 |
101 void GetGrayscaleMatrix(float amount, SkScalar matrix[20]) { | 101 void GetGrayscaleMatrix(float amount, SkScalar matrix[20]) { |
102 // Note, these values are computed to ensure matrixNeedsClamping is false | 102 // Note, these values are computed to ensure MatrixNeedsClamping is false |
103 // for amount in [0..1] | 103 // for amount in [0..1] |
104 matrix[0] = 0.2126f + 0.7874f * amount; | 104 matrix[0] = 0.2126f + 0.7874f * amount; |
105 matrix[1] = 0.7152f - 0.7152f * amount; | 105 matrix[1] = 0.7152f - 0.7152f * amount; |
106 matrix[2] = 1.f - (matrix[0] + matrix[1]); | 106 matrix[2] = 1.f - (matrix[0] + matrix[1]); |
107 matrix[3] = matrix[4] = 0.f; | 107 matrix[3] = matrix[4] = 0.f; |
108 | 108 |
109 matrix[5] = 0.2126f - 0.2126f * amount; | 109 matrix[5] = 0.2126f - 0.2126f * amount; |
110 matrix[6] = 0.7152f + 0.2848f * amount; | 110 matrix[6] = 0.7152f + 0.2848f * amount; |
111 matrix[7] = 1.f - (matrix[5] + matrix[6]); | 111 matrix[7] = 1.f - (matrix[5] + matrix[6]); |
112 matrix[8] = matrix[9] = 0.f; | 112 matrix[8] = matrix[9] = 0.f; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 SkScalar accumulated_color_matrix[20]; | 316 SkScalar accumulated_color_matrix[20]; |
317 bool have_accumulated_color_matrix = false; | 317 bool have_accumulated_color_matrix = false; |
318 for (unsigned i = 0; i < filters.size(); ++i) { | 318 for (unsigned i = 0; i < filters.size(); ++i) { |
319 const WebKit::WebFilterOperation& op = filters.at(i); | 319 const WebKit::WebFilterOperation& op = filters.at(i); |
320 | 320 |
321 // If the filter is a color matrix, we may be able to combine it with | 321 // If the filter is a color matrix, we may be able to combine it with |
322 // following Filter(s) that also are color matrices. | 322 // following Filter(s) that also are color matrices. |
323 SkScalar matrix[20]; | 323 SkScalar matrix[20]; |
324 if (GetColorMatrix(op, matrix)) { | 324 if (GetColorMatrix(op, matrix)) { |
325 if (have_accumulated_color_matrix) { | 325 if (have_accumulated_color_matrix) { |
326 SkScalar newMatrix[20]; | 326 SkScalar new_matrix[20]; |
327 MultColorMatrix(matrix, accumulated_color_matrix, newMatrix); | 327 MultColorMatrix(matrix, accumulated_color_matrix, new_matrix); |
328 memcpy(accumulated_color_matrix, | 328 memcpy(accumulated_color_matrix, |
329 newMatrix, | 329 new_matrix, |
330 sizeof(accumulated_color_matrix)); | 330 sizeof(accumulated_color_matrix)); |
331 } else { | 331 } else { |
332 memcpy(accumulated_color_matrix, | 332 memcpy(accumulated_color_matrix, |
333 matrix, | 333 matrix, |
334 sizeof(accumulated_color_matrix)); | 334 sizeof(accumulated_color_matrix)); |
335 have_accumulated_color_matrix = true; | 335 have_accumulated_color_matrix = true; |
336 } | 336 } |
337 | 337 |
338 // We can only combine matrices if clamping of color components | 338 // We can only combine matrices if clamping of color components |
339 // would have no effect. | 339 // would have no effect. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 case WebKit::WebFilterOperation::FilterTypeOpacity: | 452 case WebKit::WebFilterOperation::FilterTypeOpacity: |
453 NOTREACHED(); | 453 NOTREACHED(); |
454 break; | 454 break; |
455 } | 455 } |
456 state.Swap(); | 456 state.Swap(); |
457 } | 457 } |
458 return state.Source(); | 458 return state.Source(); |
459 } | 459 } |
460 | 460 |
461 } // namespace cc | 461 } // namespace cc |
OLD | NEW |