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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/render_surface_filters.h" | 7 #include "cc/render_surface_filters.h" |
8 | 8 |
9 #include "FloatSize.h" | |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
12 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 11 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
13 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | 12 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" |
14 #include "third_party/skia/include/effects/SkMagnifierImageFilter.h" | 13 #include "third_party/skia/include/effects/SkMagnifierImageFilter.h" |
15 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 14 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
16 #include "third_party/skia/include/gpu/SkGrPixelRef.h" | 15 #include "third_party/skia/include/gpu/SkGrPixelRef.h" |
| 16 #include "ui/gfx/size_f.h" |
17 #include <public/WebFilterOperation.h> | 17 #include <public/WebFilterOperation.h> |
18 #include <public/WebFilterOperations.h> | 18 #include <public/WebFilterOperations.h> |
19 #include <public/WebGraphicsContext3D.h> | 19 #include <public/WebGraphicsContext3D.h> |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 void getBrightnessMatrix(float amount, SkScalar matrix[20]) | 25 void getBrightnessMatrix(float amount, SkScalar matrix[20]) |
26 { | 26 { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 matrix[10] = 0.213f - 0.213f * amount; | 60 matrix[10] = 0.213f - 0.213f * amount; |
61 matrix[11] = 0.715f - 0.715f * amount; | 61 matrix[11] = 0.715f - 0.715f * amount; |
62 matrix[12] = 1.f - (matrix[10] + matrix[11]); | 62 matrix[12] = 1.f - (matrix[10] + matrix[11]); |
63 matrix[13] = matrix[14] = 0; | 63 matrix[13] = matrix[14] = 0; |
64 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0; | 64 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0; |
65 matrix[18] = 1; | 65 matrix[18] = 1; |
66 } | 66 } |
67 | 67 |
68 void getHueRotateMatrix(float hue, SkScalar matrix[20]) | 68 void getHueRotateMatrix(float hue, SkScalar matrix[20]) |
69 { | 69 { |
70 float cosHue = cosf(hue * piFloat / 180); | 70 const float kPi = 3.1415926535897932384626433832795f; |
71 float sinHue = sinf(hue * piFloat / 180); | 71 |
| 72 float cosHue = cosf(hue * kPi / 180); |
| 73 float sinHue = sinf(hue * kPi / 180); |
72 matrix[0] = 0.213f + cosHue * 0.787f - sinHue * 0.213f; | 74 matrix[0] = 0.213f + cosHue * 0.787f - sinHue * 0.213f; |
73 matrix[1] = 0.715f - cosHue * 0.715f - sinHue * 0.715f; | 75 matrix[1] = 0.715f - cosHue * 0.715f - sinHue * 0.715f; |
74 matrix[2] = 0.072f - cosHue * 0.072f + sinHue * 0.928f; | 76 matrix[2] = 0.072f - cosHue * 0.072f + sinHue * 0.928f; |
75 matrix[3] = matrix[4] = 0; | 77 matrix[3] = matrix[4] = 0; |
76 matrix[5] = 0.213f - cosHue * 0.213f + sinHue * 0.143f; | 78 matrix[5] = 0.213f - cosHue * 0.213f + sinHue * 0.143f; |
77 matrix[6] = 0.715f + cosHue * 0.285f + sinHue * 0.140f; | 79 matrix[6] = 0.715f + cosHue * 0.285f + sinHue * 0.140f; |
78 matrix[7] = 0.072f - cosHue * 0.072f - sinHue * 0.283f; | 80 matrix[7] = 0.072f - cosHue * 0.072f - sinHue * 0.283f; |
79 matrix[8] = matrix[9] = 0; | 81 matrix[8] = matrix[9] = 0; |
80 matrix[10] = 0.213f - cosHue * 0.213f - sinHue * 0.787f; | 82 matrix[10] = 0.213f - cosHue * 0.213f - sinHue * 0.787f; |
81 matrix[11] = 0.715f - cosHue * 0.715f + sinHue * 0.715f; | 83 matrix[11] = 0.715f - cosHue * 0.715f + sinHue * 0.715f; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 memcpy(matrix, op.matrix(), sizeof(SkScalar[20])); | 231 memcpy(matrix, op.matrix(), sizeof(SkScalar[20])); |
230 return true; | 232 return true; |
231 } | 233 } |
232 default: | 234 default: |
233 return false; | 235 return false; |
234 } | 236 } |
235 } | 237 } |
236 | 238 |
237 class FilterBufferState { | 239 class FilterBufferState { |
238 public: | 240 public: |
239 FilterBufferState(GrContext* grContext, const FloatSize& size, unsigned text
ureId) | 241 FilterBufferState(GrContext* grContext, const gfx::SizeF& size, unsigned tex
tureId) |
240 : m_grContext(grContext) | 242 : m_grContext(grContext) |
241 , m_currentTexture(0) | 243 , m_currentTexture(0) |
242 { | 244 { |
243 // Wrap the source texture in a Ganesh platform texture. | 245 // Wrap the source texture in a Ganesh platform texture. |
244 GrPlatformTextureDesc platformTextureDescription; | 246 GrPlatformTextureDesc platformTextureDescription; |
245 platformTextureDescription.fWidth = size.width(); | 247 platformTextureDescription.fWidth = size.width(); |
246 platformTextureDescription.fHeight = size.height(); | 248 platformTextureDescription.fHeight = size.height(); |
247 platformTextureDescription.fConfig = kSkia8888_GrPixelConfig; | 249 platformTextureDescription.fConfig = kSkia8888_GrPixelConfig; |
248 platformTextureDescription.fTextureHandle = textureId; | 250 platformTextureDescription.fTextureHandle = textureId; |
249 SkAutoTUnref<GrTexture> texture(grContext->createPlatformTexture(platfor
mTextureDescription)); | 251 SkAutoTUnref<GrTexture> texture(grContext->createPlatformTexture(platfor
mTextureDescription)); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 case WebKit::WebFilterOperation::FilterTypeOpacity: | 360 case WebKit::WebFilterOperation::FilterTypeOpacity: |
359 case WebKit::WebFilterOperation::FilterTypeColorMatrix: | 361 case WebKit::WebFilterOperation::FilterTypeColorMatrix: |
360 break; | 362 break; |
361 } | 363 } |
362 } | 364 } |
363 if (haveAccumulatedColorMatrix) | 365 if (haveAccumulatedColorMatrix) |
364 newList.append(WebKit::WebFilterOperation::createColorMatrixFilter(accum
ulatedColorMatrix)); | 366 newList.append(WebKit::WebFilterOperation::createColorMatrixFilter(accum
ulatedColorMatrix)); |
365 return newList; | 367 return newList; |
366 } | 368 } |
367 | 369 |
368 SkBitmap RenderSurfaceFilters::apply(const WebKit::WebFilterOperations& filters,
unsigned textureId, const FloatSize& size, WebKit::WebGraphicsContext3D* contex
t3D, GrContext* grContext) | 370 SkBitmap RenderSurfaceFilters::apply(const WebKit::WebFilterOperations& filters,
unsigned textureId, const gfx::SizeF& size, WebKit::WebGraphicsContext3D* conte
xt3D, GrContext* grContext) |
369 { | 371 { |
370 if (!context3D || !grContext) | 372 if (!context3D || !grContext) |
371 return SkBitmap(); | 373 return SkBitmap(); |
372 | 374 |
373 WebKit::WebFilterOperations optimizedFilters = optimize(filters); | 375 WebKit::WebFilterOperations optimizedFilters = optimize(filters); |
374 FilterBufferState state(grContext, size, textureId); | 376 FilterBufferState state(grContext, size, textureId); |
375 if (!state.init(optimizedFilters.size())) | 377 if (!state.init(optimizedFilters.size())) |
376 return SkBitmap(); | 378 return SkBitmap(); |
377 | 379 |
378 for (unsigned i = 0; i < optimizedFilters.size(); ++i) { | 380 for (unsigned i = 0; i < optimizedFilters.size(); ++i) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 NOTREACHED(); | 434 NOTREACHED(); |
433 break; | 435 break; |
434 } | 436 } |
435 state.swap(); | 437 state.swap(); |
436 } | 438 } |
437 context3D->flush(); | 439 context3D->flush(); |
438 return state.source(); | 440 return state.source(); |
439 } | 441 } |
440 | 442 |
441 } // namespace cc | 443 } // namespace cc |
OLD | NEW |