Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
SkEmbossMaskFilter Class Reference

#include <SkEmbossMaskFilter.h>

Inheritance diagram for SkEmbossMaskFilter:
SkMaskFilterBase SkMaskFilter SkFlattenable SkRefCnt SkRefCntBase

Classes

struct  Light
 

Public Member Functions

SkMask::Format getFormat () const override
 
bool filterMask (SkMaskBuilder *dst, const SkMask &src, const SkMatrix &, SkIPoint *margin) const override
 
SkMaskFilterBase::Type type () const override
 
- Public Member Functions inherited from SkMaskFilterBase
virtual SkMask::Format getFormat () const =0
 
virtual bool filterMask (SkMaskBuilder *dst, const SkMask &src, const SkMatrix &, SkIPoint *margin) const =0
 
virtual Type type () const =0
 
virtual void computeFastBounds (const SkRect &src, SkRect *dest) const
 
virtual bool asABlur (BlurRec *) const
 
virtual sk_sp< SkImageFilterasImageFilter (const SkMatrix &ctm) const
 
SkFlattenable::Type getFlattenableType () const override
 
- Public Member Functions inherited from SkMaskFilter
SkRect approximateFilteredBounds (const SkRect &src) const
 
- Public Member Functions inherited from SkFlattenable
 SkFlattenable ()
 
virtual Factory getFactory () const =0
 
virtual const char * getTypeName () const =0
 
virtual void flatten (SkWriteBuffer &) const
 
virtual Type getFlattenableType () const =0
 
sk_sp< SkDataserialize (const SkSerialProcs *=nullptr) const
 
size_t serialize (void *memory, size_t memory_size, const SkSerialProcs *=nullptr) const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< SkMaskFilterMake (SkScalar blurSigma, const Light &light)
 
- Static Public Member Functions inherited from SkMaskFilterBase
static SkFlattenable::Type GetFlattenableType ()
 
- Static Public Member Functions inherited from SkMaskFilter
static sk_sp< SkMaskFilterMakeBlur (SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
 
static sk_sp< SkMaskFilterDeserialize (const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
 
- Static Public Member Functions inherited from SkFlattenable
static Factory NameToFactory (const char name[])
 
static const char * FactoryToName (Factory)
 
static void Register (const char name[], Factory)
 
static sk_sp< SkFlattenableDeserialize (Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
 

Protected Member Functions

 SkEmbossMaskFilter (SkScalar blurSigma, const Light &light)
 
void flatten (SkWriteBuffer &) const override
 
- Protected Member Functions inherited from SkMaskFilterBase
 SkMaskFilterBase ()
 
virtual FilterReturn filterRectsToNine (const SkRect[], int count, const SkMatrix &, const SkIRect &clipBounds, SkTLazy< NinePatch > *) const
 
virtual FilterReturn filterRRectToNine (const SkRRect &, const SkMatrix &, const SkIRect &clipBounds, SkTLazy< NinePatch > *) const
 

Additional Inherited Members

- Public Types inherited from SkMaskFilterBase
enum class  Type {
  kBlur , kEmboss , kSDF , kShader ,
  kTable
}
 
- Public Types inherited from SkFlattenable
enum  Type {
  kSkColorFilter_Type , kSkBlender_Type , kSkDrawable_Type , kSkDrawLooper_Type ,
  kSkImageFilter_Type , kSkMaskFilter_Type , kSkPathEffect_Type , kSkShader_Type
}
 
typedef sk_sp< SkFlattenable >(* Factory) (SkReadBuffer &)
 
- Protected Types inherited from SkMaskFilterBase
enum  FilterReturn { kFalse_FilterReturn , kTrue_FilterReturn , kUnimplemented_FilterReturn }
 

Detailed Description

This mask filter creates a 3D emboss look, by specifying a light and blur amount.

Definition at line 30 of file SkEmbossMaskFilter.h.

Constructor & Destructor Documentation

◆ SkEmbossMaskFilter()

SkEmbossMaskFilter::SkEmbossMaskFilter ( SkScalar  blurSigma,
const Light light 
)
protected

Definition at line 66 of file SkEmbossMaskFilter.cpp.

67 : fLight(light), fBlurSigma(blurSigma)
68{
69 SkASSERT(fBlurSigma > 0);
70 SkASSERT(SkIsFinite(fLight.fDirection, 3));
71}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool SkIsFinite(T x, Pack... values)

Member Function Documentation

◆ filterMask()

bool SkEmbossMaskFilter::filterMask ( SkMaskBuilder dst,
const SkMask src,
const SkMatrix ,
SkIPoint margin 
) const
overridevirtual

Create a new mask by filter the src mask. If src.fImage == null, then do not allocate or create the dst image but do fill out the other fields in dstMask. If you do allocate a dst image, use SkMask::AllocImage() If this returns false, dst mask is ignored.

Parameters
dstthe result of the filter. If src.fImage == null, dst should not allocate its image
srcthe original image to be filtered.
matrixthe CTM
marginif not null, return the buffer dx/dy need when calculating the effect. Used when drawing a clipped object to know how much larger to allocate the src before applying the filter. If returning false, ignore this parameter.
Returns
true if the dst mask was correctly created.

Implements SkMaskFilterBase.

Definition at line 77 of file SkEmbossMaskFilter.cpp.

78 {
79 if (src.fFormat != SkMask::kA8_Format) {
80 return false;
81 }
82
83 SkScalar sigma = matrix.mapRadius(fBlurSigma);
84
86 return false;
87 }
88
89 dst->format() = SkMask::k3D_Format;
90 if (margin) {
91 margin->set(SkScalarCeilToInt(3*sigma), SkScalarCeilToInt(3*sigma));
92 }
93
94 if (src.fImage == nullptr) {
95 return true;
96 }
97
98 // create a larger buffer for the other two channels (should force fBlur to do this for us)
99
100 {
101 uint8_t* alphaPlane = dst->image();
102 size_t planeSize = dst->computeImageSize();
103 if (0 == planeSize) {
104 return false; // too big to allocate, abort
105 }
106 dst->image() = SkMaskBuilder::AllocImage(planeSize * 3);
107 memcpy(dst->image(), alphaPlane, planeSize);
108 SkMaskBuilder::FreeImage(alphaPlane);
109 }
110
111 // run the light direction through the matrix...
112 Light light = fLight;
113 matrix.mapVectors((SkVector*)(void*)light.fDirection,
114 (SkVector*)(void*)fLight.fDirection, 1);
115
116 // now restore the length of the XY component
117 // cast to SkVector so we can call setLength (this double cast silences alias warnings)
118 SkVector* vec = (SkVector*)(void*)light.fDirection;
119 vec->setLength(light.fDirection[0],
120 light.fDirection[1],
121 SkPoint::Length(fLight.fDirection[0], fLight.fDirection[1]));
122
124
125 // restore original alpha
126 memcpy(dst->image(), src.fImage, src.computeImageSize());
127
128 return true;
129}
@ kInner_SkBlurStyle
fuzzy inside, nothing outside
Definition: SkBlurTypes.h:15
#define SkScalarCeilToInt(x)
Definition: SkScalar.h:36
static bool BoxBlur(SkMaskBuilder *dst, const SkMask &src, SkScalar sigma, SkBlurStyle style, SkIPoint *margin=nullptr)
Definition: SkBlurMask.cpp:116
static void Emboss(SkMaskBuilder *mask, const SkEmbossMaskFilter::Light &)
float SkScalar
Definition: extension.cpp:12
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
dst
Definition: cp.py:12
void set(int32_t x, int32_t y)
Definition: SkPoint_impl.h:65
static void FreeImage(void *image)
Definition: SkMask.cpp:57
static uint8_t * AllocImage(size_t bytes, AllocType=kUninit_Alloc)
Definition: SkMask.cpp:45
@ k3D_Format
3 8bit per pixl planes: alpha, mul, add
Definition: SkMask.h:29
@ kA8_Format
8bits per pixel mask (e.g. antialiasing)
Definition: SkMask.h:28
bool setLength(float length)
Definition: SkPoint.cpp:30
static float Length(float x, float y)
Definition: SkPoint.cpp:79

◆ flatten()

void SkEmbossMaskFilter::flatten ( SkWriteBuffer ) const
overrideprotectedvirtual

Override this if your subclass needs to record data that it will need to recreate itself from its CreateProc (returned by getFactory()).

DEPRECATED public : will move to protected ... use serialize() instead

Reimplemented from SkFlattenable.

Definition at line 141 of file SkEmbossMaskFilter.cpp.

141 {
142 Light tmpLight = fLight;
143 tmpLight.fPad = 0; // for the font-cache lookup to be clean
144 buffer.writeByteArray(&tmpLight, sizeof(tmpLight));
145 buffer.writeScalar(fBlurSigma);
146}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ getFormat()

SkMask::Format SkEmbossMaskFilter::getFormat ( ) const
overridevirtual

Returns the format of the resulting mask that this subclass will return when its filterMask() method is called.

Implements SkMaskFilterBase.

Definition at line 73 of file SkEmbossMaskFilter.cpp.

73 {
74 return SkMask::k3D_Format;
75}

◆ Make()

sk_sp< SkMaskFilter > SkEmbossMaskFilter::Make ( SkScalar  blurSigma,
const Light light 
)
static

Definition at line 27 of file SkEmbossMaskFilter.cpp.

27 {
28 if (!SkIsFinite(blurSigma) || blurSigma <= 0) {
29 return nullptr;
30 }
31
32 SkPoint3 lightDir{light.fDirection[0], light.fDirection[1], light.fDirection[2]};
33 if (!lightDir.normalize()) {
34 return nullptr;
35 }
36 Light newLight = light;
37 newLight.fDirection[0] = lightDir.x();
38 newLight.fDirection[1] = lightDir.y();
39 newLight.fDirection[2] = lightDir.z();
40
41 return sk_sp<SkMaskFilter>(new SkEmbossMaskFilter(blurSigma, newLight));
42}
SkEmbossMaskFilter(SkScalar blurSigma, const Light &light)
SkScalar x() const
Definition: SkPoint3.h:24

◆ type()

SkMaskFilterBase::Type SkEmbossMaskFilter::type ( ) const
inlineoverridevirtual

Implements SkMaskFilterBase.

Definition at line 47 of file SkEmbossMaskFilter.h.


The documentation for this class was generated from the following files: