Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: cc/render_surface_filters.cc

Issue 12033075: Switch back to the original brightness filter implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed temporary build crutches Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | cc/render_surface_filters_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/render_surface_filters.h" 5 #include "cc/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"
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
12 #include "third_party/skia/include/core/SkCanvas.h" 12 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 13 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
14 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" 14 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
15 #include "third_party/skia/include/effects/SkMagnifierImageFilter.h" 15 #include "third_party/skia/include/effects/SkMagnifierImageFilter.h"
16 #include "third_party/skia/include/gpu/SkGpuDevice.h" 16 #include "third_party/skia/include/gpu/SkGpuDevice.h"
17 #include "third_party/skia/include/gpu/SkGrPixelRef.h" 17 #include "third_party/skia/include/gpu/SkGrPixelRef.h"
18 #include "ui/gfx/size_f.h" 18 #include "ui/gfx/size_f.h"
19 19
20 namespace cc { 20 namespace cc {
21 21
22 namespace { 22 namespace {
23 23
24 void getBrightnessMatrix(float amount, SkScalar matrix[20]) 24 void getBrightnessMatrix(float amount, SkScalar matrix[20])
25 { 25 {
26 // Spec implementation
27 // (http://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#brightnessEqu ivalent)
28 // <feFunc[R|G|B] type="linear" slope="[amount]">
26 memset(matrix, 0, 20 * sizeof(SkScalar)); 29 memset(matrix, 0, 20 * sizeof(SkScalar));
27 // Old implementation, a la the draft spec, a straight-up scale, 30 matrix[0] = matrix[6] = matrix[12] = amount;
28 // representing <feFunc[R|G|B] type="linear" slope="[amount]"> 31 matrix[18] = 1;
29 // (See http://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#bright nessEquivalent) 32 }
30 // matrix[0] = matrix[6] = matrix[12] = amount; 33
31 // matrix[18] = 1; 34 void getSaturatingBrightnessMatrix(float amount, SkScalar matrix[20])
32 // New implementation, a translation in color space, representing 35 {
33 // <feFunc[R|G|B] type="linear" intercept="[amount]"/> 36 // Legacy implementation used by internal clients.
34 // (See https://www.w3.org/Bugs/Public/show_bug.cgi?id=15647) 37 // <feFunc[R|G|B] type="linear" intercept="[amount]"/>
38 memset(matrix, 0, 20 * sizeof(SkScalar));
35 matrix[0] = matrix[6] = matrix[12] = matrix[18] = 1; 39 matrix[0] = matrix[6] = matrix[12] = matrix[18] = 1;
36 matrix[4] = matrix[9] = matrix[14] = amount * 255; 40 matrix[4] = matrix[9] = matrix[14] = amount * 255;
37 } 41 }
38 42
39 void getContrastMatrix(float amount, SkScalar matrix[20]) 43 void getContrastMatrix(float amount, SkScalar matrix[20])
40 { 44 {
41 memset(matrix, 0, 20 * sizeof(SkScalar)); 45 memset(matrix, 0, 20 * sizeof(SkScalar));
42 matrix[0] = matrix[6] = matrix[12] = amount; 46 matrix[0] = matrix[6] = matrix[12] = amount;
43 matrix[4] = matrix[9] = matrix[14] = (-0.5f * amount + 0.5f) * 255; 47 matrix[4] = matrix[9] = matrix[14] = (-0.5f * amount + 0.5f) * 255;
44 matrix[18] = 1; 48 matrix[18] = 1;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 || componentNeedsClamping(matrix+15); 195 || componentNeedsClamping(matrix+15);
192 } 196 }
193 197
194 bool getColorMatrix(const WebKit::WebFilterOperation& op, SkScalar matrix[20]) 198 bool getColorMatrix(const WebKit::WebFilterOperation& op, SkScalar matrix[20])
195 { 199 {
196 switch (op.type()) { 200 switch (op.type()) {
197 case WebKit::WebFilterOperation::FilterTypeBrightness: { 201 case WebKit::WebFilterOperation::FilterTypeBrightness: {
198 getBrightnessMatrix(op.amount(), matrix); 202 getBrightnessMatrix(op.amount(), matrix);
199 return true; 203 return true;
200 } 204 }
205 case WebKit::WebFilterOperation::FilterTypeSaturatingBrightness: {
206 getSaturatingBrightnessMatrix(op.amount(), matrix);
207 return true;
208 }
201 case WebKit::WebFilterOperation::FilterTypeContrast: { 209 case WebKit::WebFilterOperation::FilterTypeContrast: {
202 getContrastMatrix(op.amount(), matrix); 210 getContrastMatrix(op.amount(), matrix);
203 return true; 211 return true;
204 } 212 }
205 case WebKit::WebFilterOperation::FilterTypeGrayscale: { 213 case WebKit::WebFilterOperation::FilterTypeGrayscale: {
206 getGrayscaleMatrix(1 - op.amount(), matrix); 214 getGrayscaleMatrix(1 - op.amount(), matrix);
207 return true; 215 return true;
208 } 216 }
209 case WebKit::WebFilterOperation::FilterTypeSepia: { 217 case WebKit::WebFilterOperation::FilterTypeSepia: {
210 getSepiaMatrix(1 - op.amount(), matrix); 218 getSepiaMatrix(1 - op.amount(), matrix);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 newList.append(WebKit::WebFilterOperation::createColorMatrixFilter(a ccumulatedColorMatrix)); 353 newList.append(WebKit::WebFilterOperation::createColorMatrixFilter(a ccumulatedColorMatrix));
346 haveAccumulatedColorMatrix = false; 354 haveAccumulatedColorMatrix = false;
347 355
348 switch (op.type()) { 356 switch (op.type()) {
349 case WebKit::WebFilterOperation::FilterTypeBlur: 357 case WebKit::WebFilterOperation::FilterTypeBlur:
350 case WebKit::WebFilterOperation::FilterTypeDropShadow: 358 case WebKit::WebFilterOperation::FilterTypeDropShadow:
351 case WebKit::WebFilterOperation::FilterTypeZoom: 359 case WebKit::WebFilterOperation::FilterTypeZoom:
352 newList.append(op); 360 newList.append(op);
353 break; 361 break;
354 case WebKit::WebFilterOperation::FilterTypeBrightness: 362 case WebKit::WebFilterOperation::FilterTypeBrightness:
363 case WebKit::WebFilterOperation::FilterTypeSaturatingBrightness:
355 case WebKit::WebFilterOperation::FilterTypeContrast: 364 case WebKit::WebFilterOperation::FilterTypeContrast:
356 case WebKit::WebFilterOperation::FilterTypeGrayscale: 365 case WebKit::WebFilterOperation::FilterTypeGrayscale:
357 case WebKit::WebFilterOperation::FilterTypeSepia: 366 case WebKit::WebFilterOperation::FilterTypeSepia:
358 case WebKit::WebFilterOperation::FilterTypeSaturate: 367 case WebKit::WebFilterOperation::FilterTypeSaturate:
359 case WebKit::WebFilterOperation::FilterTypeHueRotate: 368 case WebKit::WebFilterOperation::FilterTypeHueRotate:
360 case WebKit::WebFilterOperation::FilterTypeInvert: 369 case WebKit::WebFilterOperation::FilterTypeInvert:
361 case WebKit::WebFilterOperation::FilterTypeOpacity: 370 case WebKit::WebFilterOperation::FilterTypeOpacity:
362 case WebKit::WebFilterOperation::FilterTypeColorMatrix: 371 case WebKit::WebFilterOperation::FilterTypeColorMatrix:
363 default: // FIXME: temporary place holder to prevent build failures
364 break; 372 break;
365 } 373 }
366 } 374 }
367 if (haveAccumulatedColorMatrix) 375 if (haveAccumulatedColorMatrix)
368 newList.append(WebKit::WebFilterOperation::createColorMatrixFilter(accum ulatedColorMatrix)); 376 newList.append(WebKit::WebFilterOperation::createColorMatrixFilter(accum ulatedColorMatrix));
369 return newList; 377 return newList;
370 } 378 }
371 379
372 SkBitmap RenderSurfaceFilters::apply(const WebKit::WebFilterOperations& filters, unsigned textureId, const gfx::SizeF& size, WebKit::WebGraphicsContext3D* conte xt3D, GrContext* grContext) 380 SkBitmap RenderSurfaceFilters::apply(const WebKit::WebFilterOperations& filters, unsigned textureId, const gfx::SizeF& size, WebKit::WebGraphicsContext3D* conte xt3D, GrContext* grContext)
373 { 381 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 op.zoomRect().width, 428 op.zoomRect().width,
421 op.zoomRect().height), 429 op.zoomRect().height),
422 op.amount())); 430 op.amount()));
423 paint.setImageFilter(zoomFilter.get()); 431 paint.setImageFilter(zoomFilter.get());
424 canvas->saveLayer(0, &paint); 432 canvas->saveLayer(0, &paint);
425 canvas->drawBitmap(state.source(), 0, 0); 433 canvas->drawBitmap(state.source(), 0, 0);
426 canvas->restore(); 434 canvas->restore();
427 break; 435 break;
428 } 436 }
429 case WebKit::WebFilterOperation::FilterTypeBrightness: 437 case WebKit::WebFilterOperation::FilterTypeBrightness:
438 case WebKit::WebFilterOperation::FilterTypeSaturatingBrightness:
430 case WebKit::WebFilterOperation::FilterTypeContrast: 439 case WebKit::WebFilterOperation::FilterTypeContrast:
431 case WebKit::WebFilterOperation::FilterTypeGrayscale: 440 case WebKit::WebFilterOperation::FilterTypeGrayscale:
432 case WebKit::WebFilterOperation::FilterTypeSepia: 441 case WebKit::WebFilterOperation::FilterTypeSepia:
433 case WebKit::WebFilterOperation::FilterTypeSaturate: 442 case WebKit::WebFilterOperation::FilterTypeSaturate:
434 case WebKit::WebFilterOperation::FilterTypeHueRotate: 443 case WebKit::WebFilterOperation::FilterTypeHueRotate:
435 case WebKit::WebFilterOperation::FilterTypeInvert: 444 case WebKit::WebFilterOperation::FilterTypeInvert:
436 case WebKit::WebFilterOperation::FilterTypeOpacity: 445 case WebKit::WebFilterOperation::FilterTypeOpacity:
437 default: // FIXME: temporary place holder to prevent build failures
438 NOTREACHED(); 446 NOTREACHED();
439 break; 447 break;
440 } 448 }
441 state.swap(); 449 state.swap();
442 } 450 }
443 context3D->flush(); 451 context3D->flush();
444 return state.source(); 452 return state.source();
445 } 453 }
446 454
447 } // namespace cc 455 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/render_surface_filters_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698