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

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

Issue 1852113003: switch maskfilters to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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 | « src/effects/SkBlurMaskFilter.cpp ('k') | src/effects/SkLayerDrawLooper.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 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkEmbossMaskFilter.h" 8 #include "SkEmbossMaskFilter.h"
9 #include "SkBlurMaskFilter.h" 9 #include "SkBlurMaskFilter.h"
10 #include "SkBlurMask.h" 10 #include "SkBlurMask.h"
11 #include "SkEmbossMask.h" 11 #include "SkEmbossMask.h"
12 #include "SkReadBuffer.h" 12 #include "SkReadBuffer.h"
13 #include "SkWriteBuffer.h" 13 #include "SkWriteBuffer.h"
14 #include "SkString.h" 14 #include "SkString.h"
15 15
16 SkMaskFilter* SkEmbossMaskFilter::Create(SkScalar blurSigma, const Light& light) { 16 sk_sp<SkMaskFilter> SkEmbossMaskFilter::Make(SkScalar blurSigma, const Light& li ght) {
17 return new SkEmbossMaskFilter(blurSigma, light); 17 return sk_sp<SkMaskFilter>(new SkEmbossMaskFilter(blurSigma, light));
18 } 18 }
19 19
20 #ifdef SK_SUPPORT_LEGACY_MASKFILTER_PTR
20 SkMaskFilter* SkBlurMaskFilter::CreateEmboss(const SkScalar direction[3], 21 SkMaskFilter* SkBlurMaskFilter::CreateEmboss(const SkScalar direction[3],
21 SkScalar ambient, SkScalar specular , 22 SkScalar ambient, SkScalar specular ,
22 SkScalar blurRadius) { 23 SkScalar blurRadius) {
23 return SkBlurMaskFilter::CreateEmboss(SkBlurMask::ConvertRadiusToSigma(blurR adius), 24 return SkBlurMaskFilter::CreateEmboss(SkBlurMask::ConvertRadiusToSigma(blurR adius),
24 direction, ambient, specular); 25 direction, ambient, specular);
25 } 26 }
27 #endif
26 28
27 SkMaskFilter* SkBlurMaskFilter::CreateEmboss(SkScalar blurSigma, const SkScalar direction[3], 29 sk_sp<SkMaskFilter> SkBlurMaskFilter::MakeEmboss(SkScalar blurSigma, const SkSca lar direction[3],
28 SkScalar ambient, SkScalar specular ) { 30 SkScalar ambient, SkScalar spec ular) {
29 if (direction == nullptr) { 31 if (direction == nullptr) {
30 return nullptr; 32 return nullptr;
31 } 33 }
32 34
33 SkEmbossMaskFilter::Light light; 35 SkEmbossMaskFilter::Light light;
34 36
35 memcpy(light.fDirection, direction, sizeof(light.fDirection)); 37 memcpy(light.fDirection, direction, sizeof(light.fDirection));
36 // ambient should be 0...1 as a scalar 38 // ambient should be 0...1 as a scalar
37 light.fAmbient = SkUnitScalarClampToByte(ambient); 39 light.fAmbient = SkUnitScalarClampToByte(ambient);
38 // specular should be 0..15.99 as a scalar 40 // specular should be 0..15.99 as a scalar
39 static const SkScalar kSpecularMultiplier = SkIntToScalar(255) / 16; 41 static const SkScalar kSpecularMultiplier = SkIntToScalar(255) / 16;
40 light.fSpecular = static_cast<U8CPU>(SkScalarPin(specular, 0, 16) * kSpecula rMultiplier + 0.5); 42 light.fSpecular = static_cast<U8CPU>(SkScalarPin(specular, 0, 16) * kSpecula rMultiplier + 0.5);
41 43
42 return SkEmbossMaskFilter::Create(blurSigma, light); 44 return SkEmbossMaskFilter::Make(blurSigma, light);
43 } 45 }
44 46
45 /////////////////////////////////////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////////////
46 48
47 static void normalize(SkScalar v[3]) { 49 static void normalize(SkScalar v[3]) {
48 SkScalar mag = SkScalarSquare(v[0]) + SkScalarSquare(v[1]) + SkScalarSquare( v[2]); 50 SkScalar mag = SkScalarSquare(v[0]) + SkScalarSquare(v[1]) + SkScalarSquare( v[2]);
49 mag = SkScalarSqrt(mag); 51 mag = SkScalarSqrt(mag);
50 52
51 for (int i = 0; i < 3; i++) { 53 for (int i = 0; i < 3; i++) {
52 v[i] /= mag; 54 v[i] /= mag;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 memcpy(dst->fImage, src.fImage, src.computeImageSize()); 112 memcpy(dst->fImage, src.fImage, src.computeImageSize());
111 113
112 return true; 114 return true;
113 } 115 }
114 116
115 sk_sp<SkFlattenable> SkEmbossMaskFilter::CreateProc(SkReadBuffer& buffer) { 117 sk_sp<SkFlattenable> SkEmbossMaskFilter::CreateProc(SkReadBuffer& buffer) {
116 Light light; 118 Light light;
117 if (buffer.readByteArray(&light, sizeof(Light))) { 119 if (buffer.readByteArray(&light, sizeof(Light))) {
118 light.fPad = 0; // for the font-cache lookup to be clean 120 light.fPad = 0; // for the font-cache lookup to be clean
119 const SkScalar sigma = buffer.readScalar(); 121 const SkScalar sigma = buffer.readScalar();
120 return sk_sp<SkFlattenable>(Create(sigma, light)); 122 return Make(sigma, light);
121 } 123 }
122 return nullptr; 124 return nullptr;
123 } 125 }
124 126
125 void SkEmbossMaskFilter::flatten(SkWriteBuffer& buffer) const { 127 void SkEmbossMaskFilter::flatten(SkWriteBuffer& buffer) const {
126 Light tmpLight = fLight; 128 Light tmpLight = fLight;
127 tmpLight.fPad = 0; // for the font-cache lookup to be clean 129 tmpLight.fPad = 0; // for the font-cache lookup to be clean
128 buffer.writeByteArray(&tmpLight, sizeof(tmpLight)); 130 buffer.writeByteArray(&tmpLight, sizeof(tmpLight));
129 buffer.writeScalar(fBlurSigma); 131 buffer.writeScalar(fBlurSigma);
130 } 132 }
(...skipping 11 matching lines...) Expand all
142 str->append(") "); 144 str->append(") ");
143 145
144 str->appendf("ambient: %d specular: %d ", 146 str->appendf("ambient: %d specular: %d ",
145 fLight.fAmbient, fLight.fSpecular); 147 fLight.fAmbient, fLight.fSpecular);
146 148
147 str->append("blurSigma: "); 149 str->append("blurSigma: ");
148 str->appendScalar(fBlurSigma); 150 str->appendScalar(fBlurSigma);
149 str->append(")"); 151 str->append(")");
150 } 152 }
151 #endif 153 #endif
OLDNEW
« no previous file with comments | « src/effects/SkBlurMaskFilter.cpp ('k') | src/effects/SkLayerDrawLooper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698