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

Side by Side Diff: src/effects/SkEmbossMaskFilter.cpp

Issue 173633003: Factory methods for heap-allocated SkMaskFilter objects. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add SkTableMaskFilter::Create(table) and remove deprecated SkEmbossMaskFilter constructor. Created 6 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
« no previous file with comments | « samplecode/SampleEmboss.cpp ('k') | src/views/SkWidgets.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkEmbossMaskFilter.h" 10 #include "SkEmbossMaskFilter.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 // specular should be 0..15.99 as a scalar 43 // specular should be 0..15.99 as a scalar
44 int sp = pin2byte(SkScalarToFixed(specular) >> 12); 44 int sp = pin2byte(SkScalarToFixed(specular) >> 12);
45 45
46 SkEmbossMaskFilter::Light light; 46 SkEmbossMaskFilter::Light light;
47 47
48 memcpy(light.fDirection, direction, sizeof(light.fDirection)); 48 memcpy(light.fDirection, direction, sizeof(light.fDirection));
49 light.fAmbient = SkToU8(am); 49 light.fAmbient = SkToU8(am);
50 light.fSpecular = SkToU8(sp); 50 light.fSpecular = SkToU8(sp);
51 51
52 return SkNEW_ARGS(SkEmbossMaskFilter, (blurSigma, light)); 52 return SkEmbossMaskFilter::Create(blurSigma, light);
53 } 53 }
54 54
55 /////////////////////////////////////////////////////////////////////////////// 55 ///////////////////////////////////////////////////////////////////////////////
56 56
57 static void normalize(SkScalar v[3]) { 57 static void normalize(SkScalar v[3]) {
58 SkScalar mag = SkScalarSquare(v[0]) + SkScalarSquare(v[1]) + SkScalarSquare( v[2]); 58 SkScalar mag = SkScalarSquare(v[0]) + SkScalarSquare(v[1]) + SkScalarSquare( v[2]);
59 mag = SkScalarSqrt(mag); 59 mag = SkScalarSqrt(mag);
60 60
61 for (int i = 0; i < 3; i++) { 61 for (int i = 0; i < 3; i++) {
62 v[i] = SkScalarDiv(v[i], mag); 62 v[i] = SkScalarDiv(v[i], mag);
63 } 63 }
64 } 64 }
65 65
66 SkEmbossMaskFilter::SkEmbossMaskFilter(SkScalar blurSigma, const Light& light) 66 SkEmbossMaskFilter::SkEmbossMaskFilter(SkScalar blurSigma, const Light& light)
67 : fLight(light), fBlurSigma(blurSigma) { 67 : fLight(light), fBlurSigma(blurSigma) {
68 normalize(fLight.fDirection); 68 normalize(fLight.fDirection);
69 } 69 }
70 70
71 SkEmbossMaskFilter::SkEmbossMaskFilter(const Light& light, SkScalar blurRadius)
72 : fLight(light) {
73 normalize(fLight.fDirection);
74
75 fBlurSigma = SkBlurMask::ConvertRadiusToSigma(blurRadius);
76 }
77
78 SkMask::Format SkEmbossMaskFilter::getFormat() const { 71 SkMask::Format SkEmbossMaskFilter::getFormat() const {
79 return SkMask::k3D_Format; 72 return SkMask::k3D_Format;
80 } 73 }
81 74
82 bool SkEmbossMaskFilter::filterMask(SkMask* dst, const SkMask& src, 75 bool SkEmbossMaskFilter::filterMask(SkMask* dst, const SkMask& src,
83 const SkMatrix& matrix, SkIPoint* margin) co nst { 76 const SkMatrix& matrix, SkIPoint* margin) co nst {
84 SkScalar sigma = matrix.mapRadius(fBlurSigma); 77 SkScalar sigma = matrix.mapRadius(fBlurSigma);
85 78
86 if (!SkBlurMask::BoxBlur(dst, src, sigma, SkBlurMask::kInner_Style, 79 if (!SkBlurMask::BoxBlur(dst, src, sigma, SkBlurMask::kInner_Style,
87 SkBlurMask::kLow_Quality)) { 80 SkBlurMask::kLow_Quality)) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 str->append(") "); 153 str->append(") ");
161 154
162 str->appendf("ambient: %d specular: %d ", 155 str->appendf("ambient: %d specular: %d ",
163 fLight.fAmbient, fLight.fSpecular); 156 fLight.fAmbient, fLight.fSpecular);
164 157
165 str->append("blurSigma: "); 158 str->append("blurSigma: ");
166 str->appendScalar(fBlurSigma); 159 str->appendScalar(fBlurSigma);
167 str->append(")"); 160 str->append(")");
168 } 161 }
169 #endif 162 #endif
OLDNEW
« no previous file with comments | « samplecode/SampleEmboss.cpp ('k') | src/views/SkWidgets.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698