skia2/include/core/SkPaint.h

715 lines
26 KiB
C
Raw Normal View History

/*
Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00
* Copyright 2006 The Android Open Source Project
*
Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkPaint_DEFINED
#define SkPaint_DEFINED
#include "include/core/SkBlendMode.h"
#include "include/core/SkColor.h"
#include "include/core/SkFilterQuality.h"
#include "include/core/SkRefCnt.h"
#include "include/private/SkTo.h"
class SkColorFilter;
class SkColorSpace;
struct SkRect;
class SkImageFilter;
class SkMaskFilter;
class SkPath;
class SkPathEffect;
class SkShader;
/** \class SkPaint
SkPaint controls options applied when drawing. SkPaint collects all
options outside of the SkCanvas clip and SkCanvas matrix.
Various options apply to strokes and fills, and images.
SkPaint collects effects and filters that describe single-pass and multiple-pass
algorithms that alter the drawing geometry, color, and transparency. For instance,
SkPaint does not directly implement dashing or blur, but contains the objects that do so.
*/
class SK_API SkPaint {
public:
/** Constructs SkPaint with default values.
@return default initialized SkPaint
example: https://fiddle.skia.org/c/@Paint_empty_constructor
*/
SkPaint();
/** Constructs SkPaint with default values and the given color.
Sets alpha and RGB used when stroking and filling. The color is four floating
point values, unpremultiplied. The color values are interpreted as being in
the colorSpace. If colorSpace is nullptr, then color is assumed to be in the
sRGB color space.
@param color unpremultiplied RGBA
@param colorSpace SkColorSpace describing the encoding of color
@return SkPaint with the given color
*/
explicit SkPaint(const SkColor4f& color, SkColorSpace* colorSpace = nullptr);
/** Makes a shallow copy of SkPaint. SkPathEffect, SkShader,
SkMaskFilter, SkColorFilter, and SkImageFilter are shared
between the original paint and the copy. Objects containing SkRefCnt increment
their references by one.
The referenced objects SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
and SkImageFilter cannot be modified after they are created.
This prevents objects with SkRefCnt from being modified once SkPaint refers to them.
@param paint original to copy
@return shallow copy of paint
example: https://fiddle.skia.org/c/@Paint_copy_const_SkPaint
*/
SkPaint(const SkPaint& paint);
/** Implements a move constructor to avoid increasing the reference counts
of objects referenced by the paint.
After the call, paint is undefined, and can be safely destructed.
@param paint original to move
@return content of paint
example: https://fiddle.skia.org/c/@Paint_move_SkPaint
*/
SkPaint(SkPaint&& paint);
/** Decreases SkPaint SkRefCnt of owned objects: SkPathEffect, SkShader,
SkMaskFilter, SkColorFilter, and SkImageFilter. If the
objects containing SkRefCnt go to zero, they are deleted.
*/
~SkPaint();
/** Makes a shallow copy of SkPaint. SkPathEffect, SkShader,
SkMaskFilter, SkColorFilter, and SkImageFilter are shared
between the original paint and the copy. Objects containing SkRefCnt in the
prior destination are decreased by one, and the referenced objects are deleted if the
resulting count is zero. Objects containing SkRefCnt in the parameter paint
are increased by one. paint is unmodified.
@param paint original to copy
@return content of paint
example: https://fiddle.skia.org/c/@Paint_copy_operator
*/
SkPaint& operator=(const SkPaint& paint);
/** Moves the paint to avoid increasing the reference counts
of objects referenced by the paint parameter. Objects containing SkRefCnt in the
prior destination are decreased by one; those objects are deleted if the resulting count
is zero.
After the call, paint is undefined, and can be safely destructed.
@param paint original to move
@return content of paint
example: https://fiddle.skia.org/c/@Paint_move_operator
*/
SkPaint& operator=(SkPaint&& paint);
/** Compares a and b, and returns true if a and b are equivalent. May return false
if SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
or SkImageFilter have identical contents but different pointers.
@param a SkPaint to compare
@param b SkPaint to compare
@return true if SkPaint pair are equivalent
*/
SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
/** Compares a and b, and returns true if a and b are not equivalent. May return true
if SkPathEffect, SkShader, SkMaskFilter, SkColorFilter,
or SkImageFilter have identical contents but different pointers.
@param a SkPaint to compare
@param b SkPaint to compare
@return true if SkPaint pair are not equivalent
*/
friend bool operator!=(const SkPaint& a, const SkPaint& b) {
return !(a == b);
}
/** Returns a hash generated from SkPaint values and pointers.
Identical hashes guarantee that the paints are
equivalent, but differing hashes do not guarantee that the paints have differing
contents.
If operator==(const SkPaint& a, const SkPaint& b) returns true for two paints,
their hashes are also equal.
The hash returned is platform and implementation specific.
@return a shallow hash
example: https://fiddle.skia.org/c/@Paint_getHash
*/
uint32_t getHash() const;
/** Sets all SkPaint contents to their initial values. This is equivalent to replacing
SkPaint with the result of SkPaint().
example: https://fiddle.skia.org/c/@Paint_reset
*/
void reset();
/** Returns true if pixels on the active edges of SkPath may be drawn with partial transparency.
@return antialiasing state
*/
bool isAntiAlias() const {
return SkToBool(fBitfields.fAntiAlias);
}
/** Requests, but does not require, that edge pixels draw opaque or with
partial transparency.
@param aa setting for antialiasing
*/
void setAntiAlias(bool aa) { fBitfields.fAntiAlias = static_cast<unsigned>(aa); }
/** Returns true if color error may be distributed to smooth color transition.
@return dithering state
*/
bool isDither() const {
return SkToBool(fBitfields.fDither);
}
/** Requests, but does not require, to distribute color error.
@param dither setting for ditering
*/
void setDither(bool dither) { fBitfields.fDither = static_cast<unsigned>(dither); }
/** Returns SkFilterQuality, the image filtering level. A lower setting
draws faster; a higher setting looks better when the image is scaled.
*/
SkFilterQuality getFilterQuality() const {
return (SkFilterQuality)fBitfields.fFilterQuality;
}
/** Sets SkFilterQuality, the image filtering level. A lower setting
draws faster; a higher setting looks better when the image is scaled.
Does not check to see if quality is valid.
example: https://fiddle.skia.org/c/@Color_Methods
example: https://fiddle.skia.org/c/@Paint_setFilterQuality
*/
void setFilterQuality(SkFilterQuality quality);
/** \enum SkPaint::Style
Set Style to fill, stroke, or both fill and stroke geometry.
The stroke and fill
share all paint attributes; for instance, they are drawn with the same color.
Use kStrokeAndFill_Style to avoid hitting the same pixels twice with a stroke draw and
a fill draw.
*/
enum Style : uint8_t {
kFill_Style, //!< set to fill geometry
kStroke_Style, //!< set to stroke geometry
kStrokeAndFill_Style, //!< sets to stroke and fill geometry
};
/** May be used to verify that SkPaint::Style is a legal value.
*/
static constexpr int kStyleCount = kStrokeAndFill_Style + 1;
/** Returns whether the geometry is filled, stroked, or filled and stroked.
*/
Style getStyle() const { return (Style)fBitfields.fStyle; }
/** Sets whether the geometry is filled, stroked, or filled and stroked.
Has no effect if style is not a legal SkPaint::Style value.
example: https://fiddle.skia.org/c/@Paint_setStyle
example: https://fiddle.skia.org/c/@Stroke_Width
*/
void setStyle(Style style);
/**
* Set paint's style to kStroke if true, or kFill if false.
*/
void setStroke(bool);
/** Retrieves alpha and RGB, unpremultiplied, packed into 32 bits.
Use helpers SkColorGetA(), SkColorGetR(), SkColorGetG(), and SkColorGetB() to extract
a color component.
@return unpremultiplied ARGB
*/
SkColor getColor() const { return fColor4f.toSkColor(); }
/** Retrieves alpha and RGB, unpremultiplied, as four floating point values. RGB are
are extended sRGB values (sRGB gamut, and encoded with the sRGB transfer function).
@return unpremultiplied RGBA
*/
SkColor4f getColor4f() const { return fColor4f; }
/** Sets alpha and RGB used when stroking and filling. The color is a 32-bit value,
unpremultiplied, packing 8-bit components for alpha, red, blue, and green.
@param color unpremultiplied ARGB
example: https://fiddle.skia.org/c/@Paint_setColor
*/
void setColor(SkColor color);
/** Sets alpha and RGB used when stroking and filling. The color is four floating
point values, unpremultiplied. The color values are interpreted as being in
the colorSpace. If colorSpace is nullptr, then color is assumed to be in the
sRGB color space.
@param color unpremultiplied RGBA
@param colorSpace SkColorSpace describing the encoding of color
*/
void setColor(const SkColor4f& color, SkColorSpace* colorSpace = nullptr);
void setColor4f(const SkColor4f& color, SkColorSpace* colorSpace = nullptr) {
this->setColor(color, colorSpace);
}
/** Retrieves alpha from the color used when stroking and filling.
@return alpha ranging from zero, fully transparent, to 255, fully opaque
*/
float getAlphaf() const { return fColor4f.fA; }
// Helper that scales the alpha by 255.
uint8_t getAlpha() const { return sk_float_round2int(this->getAlphaf() * 255); }
/** Replaces alpha, leaving RGB
unchanged. An out of range value triggers an assert in the debug
build. a is a value from 0.0 to 1.0.
a set to zero makes color fully transparent; a set to 1.0 makes color
fully opaque.
@param a alpha component of color
*/
void setAlphaf(float a);
// Helper that accepts an int between 0 and 255, and divides it by 255.0
void setAlpha(U8CPU a) {
this->setAlphaf(a * (1.0f / 255));
}
/** Sets color used when drawing solid fills. The color components range from 0 to 255.
The color is unpremultiplied; alpha sets the transparency independent of RGB.
@param a amount of alpha, from fully transparent (0) to fully opaque (255)
@param r amount of red, from no red (0) to full red (255)
@param g amount of green, from no green (0) to full green (255)
@param b amount of blue, from no blue (0) to full blue (255)
example: https://fiddle.skia.org/c/@Paint_setARGB
*/
void setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b);
/** Returns the thickness of the pen used by SkPaint to
outline the shape.
@return zero for hairline, greater than zero for pen thickness
*/
SkScalar getStrokeWidth() const { return fWidth; }
/** Sets the thickness of the pen used by the paint to outline the shape.
A stroke-width of zero is treated as "hairline" width. Hairlines are always exactly one
pixel wide in device space (their thickness does not change as the canvas is scaled).
Negative stroke-widths are invalid; setting a negative width will have no effect.
@param width zero thickness for hairline; greater than zero for pen thickness
example: https://fiddle.skia.org/c/@Miter_Limit
example: https://fiddle.skia.org/c/@Paint_setStrokeWidth
*/
void setStrokeWidth(SkScalar width);
/** Returns the limit at which a sharp corner is drawn beveled.
@return zero and greater miter limit
*/
SkScalar getStrokeMiter() const { return fMiterLimit; }
/** Sets the limit at which a sharp corner is drawn beveled.
Valid values are zero and greater.
Has no effect if miter is less than zero.
@param miter zero and greater miter limit
example: https://fiddle.skia.org/c/@Paint_setStrokeMiter
*/
void setStrokeMiter(SkScalar miter);
/** \enum SkPaint::Cap
Cap draws at the beginning and end of an open path contour.
*/
enum Cap {
kButt_Cap, //!< no stroke extension
kRound_Cap, //!< adds circle
kSquare_Cap, //!< adds square
kLast_Cap = kSquare_Cap, //!< largest Cap value
kDefault_Cap = kButt_Cap, //!< equivalent to kButt_Cap
};
/** May be used to verify that SkPaint::Cap is a legal value.
*/
static constexpr int kCapCount = kLast_Cap + 1;
/** \enum SkPaint::Join
Join specifies how corners are drawn when a shape is stroked. Join
affects the four corners of a stroked rectangle, and the connected segments in a
stroked path.
Choose miter join to draw sharp corners. Choose round join to draw a circle with a
radius equal to the stroke width on top of the corner. Choose bevel join to minimally
connect the thick strokes.
The fill path constructed to describe the stroked path respects the join setting but may
not contain the actual join. For instance, a fill path constructed with round joins does
not necessarily include circles at each connected segment.
*/
enum Join : uint8_t {
kMiter_Join, //!< extends to miter limit
kRound_Join, //!< adds circle
kBevel_Join, //!< connects outside edges
kLast_Join = kBevel_Join, //!< equivalent to the largest value for Join
kDefault_Join = kMiter_Join, //!< equivalent to kMiter_Join
};
/** May be used to verify that SkPaint::Join is a legal value.
*/
static constexpr int kJoinCount = kLast_Join + 1;
/** Returns the geometry drawn at the beginning and end of strokes.
*/
Cap getStrokeCap() const { return (Cap)fBitfields.fCapType; }
/** Sets the geometry drawn at the beginning and end of strokes.
example: https://fiddle.skia.org/c/@Paint_setStrokeCap_a
example: https://fiddle.skia.org/c/@Paint_setStrokeCap_b
*/
void setStrokeCap(Cap cap);
/** Returns the geometry drawn at the corners of strokes.
*/
Join getStrokeJoin() const { return (Join)fBitfields.fJoinType; }
/** Sets the geometry drawn at the corners of strokes.
example: https://fiddle.skia.org/c/@Paint_setStrokeJoin
*/
void setStrokeJoin(Join join);
/** Returns the filled equivalent of the stroked path.
@param src SkPath read to create a filled version
@param dst resulting SkPath; may be the same as src, but may not be nullptr
@param cullRect optional limit passed to SkPathEffect
@param resScale if > 1, increase precision, else if (0 < resScale < 1) reduce precision
to favor speed and size
@return true if the path represents style fill, or false if it represents hairline
*/
bool getFillPath(const SkPath& src, SkPath* dst, const SkRect* cullRect,
SkScalar resScale = 1) const;
/** Returns the filled equivalent of the stroked path.
Replaces dst with the src path modified by SkPathEffect and style stroke.
SkPathEffect, if any, is not culled. stroke width is created with default precision.
@param src SkPath read to create a filled version
@param dst resulting SkPath dst may be the same as src, but may not be nullptr
@return true if the path represents style fill, or false if it represents hairline
*/
bool getFillPath(const SkPath& src, SkPath* dst) const {
return this->getFillPath(src, dst, nullptr, 1);
}
/** Returns optional colors used when filling a path, such as a gradient.
Does not alter SkShader SkRefCnt.
@return SkShader if previously set, nullptr otherwise
*/
SkShader* getShader() const { return fShader.get(); }
/** Returns optional colors used when filling a path, such as a gradient.
Increases SkShader SkRefCnt by one.
@return SkShader if previously set, nullptr otherwise
example: https://fiddle.skia.org/c/@Paint_refShader
*/
sk_sp<SkShader> refShader() const;
/** Sets optional colors used when filling a path, such as a gradient.
Sets SkShader to shader, decreasing SkRefCnt of the previous SkShader.
Increments shader SkRefCnt by one.
@param shader how geometry is filled with color; if nullptr, color is used instead
example: https://fiddle.skia.org/c/@Color_Filter_Methods
example: https://fiddle.skia.org/c/@Paint_setShader
*/
void setShader(sk_sp<SkShader> shader);
/** Returns SkColorFilter if set, or nullptr.
Does not alter SkColorFilter SkRefCnt.
@return SkColorFilter if previously set, nullptr otherwise
*/
SkColorFilter* getColorFilter() const { return fColorFilter.get(); }
/** Returns SkColorFilter if set, or nullptr.
Increases SkColorFilter SkRefCnt by one.
@return SkColorFilter if set, or nullptr
example: https://fiddle.skia.org/c/@Paint_refColorFilter
*/
sk_sp<SkColorFilter> refColorFilter() const;
/** Sets SkColorFilter to filter, decreasing SkRefCnt of the previous
SkColorFilter. Pass nullptr to clear SkColorFilter.
Increments filter SkRefCnt by one.
@param colorFilter SkColorFilter to apply to subsequent draw
example: https://fiddle.skia.org/c/@Blend_Mode_Methods
example: https://fiddle.skia.org/c/@Paint_setColorFilter
*/
void setColorFilter(sk_sp<SkColorFilter> colorFilter);
/** Returns SkBlendMode.
By default, returns SkBlendMode::kSrcOver.
@return mode used to combine source color with destination color
*/
SkBlendMode getBlendMode() const { return (SkBlendMode)fBitfields.fBlendMode; }
/** Returns true if SkBlendMode is SkBlendMode::kSrcOver, the default.
@return true if SkBlendMode is SkBlendMode::kSrcOver
*/
bool isSrcOver() const { return (SkBlendMode)fBitfields.fBlendMode == SkBlendMode::kSrcOver; }
/** Sets SkBlendMode to mode.
Does not check for valid input.
@param mode SkBlendMode used to combine source color and destination
*/
void setBlendMode(SkBlendMode mode) { fBitfields.fBlendMode = (unsigned)mode; }
/** Returns SkPathEffect if set, or nullptr.
Does not alter SkPathEffect SkRefCnt.
@return SkPathEffect if previously set, nullptr otherwise
*/
SkPathEffect* getPathEffect() const { return fPathEffect.get(); }
/** Returns SkPathEffect if set, or nullptr.
Increases SkPathEffect SkRefCnt by one.
@return SkPathEffect if previously set, nullptr otherwise
example: https://fiddle.skia.org/c/@Paint_refPathEffect
*/
sk_sp<SkPathEffect> refPathEffect() const;
/** Sets SkPathEffect to pathEffect, decreasing SkRefCnt of the previous
SkPathEffect. Pass nullptr to leave the path geometry unaltered.
Increments pathEffect SkRefCnt by one.
@param pathEffect replace SkPath with a modification when drawn
example: https://fiddle.skia.org/c/@Mask_Filter_Methods
example: https://fiddle.skia.org/c/@Paint_setPathEffect
*/
void setPathEffect(sk_sp<SkPathEffect> pathEffect);
/** Returns SkMaskFilter if set, or nullptr.
Does not alter SkMaskFilter SkRefCnt.
@return SkMaskFilter if previously set, nullptr otherwise
*/
SkMaskFilter* getMaskFilter() const { return fMaskFilter.get(); }
/** Returns SkMaskFilter if set, or nullptr.
Increases SkMaskFilter SkRefCnt by one.
@return SkMaskFilter if previously set, nullptr otherwise
example: https://fiddle.skia.org/c/@Paint_refMaskFilter
*/
sk_sp<SkMaskFilter> refMaskFilter() const;
/** Sets SkMaskFilter to maskFilter, decreasing SkRefCnt of the previous
SkMaskFilter. Pass nullptr to clear SkMaskFilter and leave SkMaskFilter effect on
mask alpha unaltered.
Increments maskFilter SkRefCnt by one.
@param maskFilter modifies clipping mask generated from drawn geometry
example: https://fiddle.skia.org/c/@Paint_setMaskFilter
example: https://fiddle.skia.org/c/@Typeface_Methods
*/
void setMaskFilter(sk_sp<SkMaskFilter> maskFilter);
/** Returns SkImageFilter if set, or nullptr.
Does not alter SkImageFilter SkRefCnt.
@return SkImageFilter if previously set, nullptr otherwise
*/
SkImageFilter* getImageFilter() const { return fImageFilter.get(); }
/** Returns SkImageFilter if set, or nullptr.
Increases SkImageFilter SkRefCnt by one.
@return SkImageFilter if previously set, nullptr otherwise
example: https://fiddle.skia.org/c/@Paint_refImageFilter
*/
sk_sp<SkImageFilter> refImageFilter() const;
/** Sets SkImageFilter to imageFilter, decreasing SkRefCnt of the previous
SkImageFilter. Pass nullptr to clear SkImageFilter, and remove SkImageFilter effect
on drawing.
Increments imageFilter SkRefCnt by one.
@param imageFilter how SkImage is sampled when transformed
example: https://fiddle.skia.org/c/@Paint_setImageFilter
*/
void setImageFilter(sk_sp<SkImageFilter> imageFilter);
/** Returns true if SkPaint prevents all drawing;
otherwise, the SkPaint may or may not allow drawing.
Returns true if, for example, SkBlendMode combined with alpha computes a
new alpha of zero.
@return true if SkPaint prevents all drawing
example: https://fiddle.skia.org/c/@Paint_nothingToDraw
*/
bool nothingToDraw() const;
/** (to be made private)
Returns true if SkPaint does not include elements requiring extensive computation
to compute SkBaseDevice bounds of drawn geometry. For instance, SkPaint with SkPathEffect
always returns false.
@return true if SkPaint allows for fast computation of bounds
*/
Reland of Implement canComputeFastBounds() for image filters. (patchset #1 id:1 of https://codereview.chromium.org/1300403003/ ) Reason for revert: The Mac compile issue was fixed here: https://chromium.googlesource.com/chromium/src/+/fdd331a42ae0b9a6909a121020735161ab61c6e5 Original issue's description: > Revert of Implement canComputeFastBounds() for image filters. (patchset #8 id:130001 of https://codereview.chromium.org/1296943002/ ) > > Reason for revert: > This causes a syntax error. > > http://build.chromium.org/p/tryserver.chromium.mac/builders/mac_chromium_compile_dbg_ng/builds/87819/steps/compile%20%28with%20patch%29/logs/stdio > > Original issue's description: > > Implement canComputeFastBounds() for image filters. > > > > Image filters have never implemented this check, which means that > > filters which affect transparent black falsely claim they can compute > > their bounds. > > > > Implemented an affectsTransparentBlack() virtual for image > > filters, and a similar helper function for color filters. > > > > This will affect the following GMs: imagefiltersscaled > > (lighting, perlin noise now filter to clip), > > colorfilterimagefilter (new test case), imagefiltersclipped > > (perlin noise now filters to clip). > > > > Note: I de-inlined SkPaint::canComputeFastBounds() to avoid adding > > a dependency from SkPaint.h to SkImageFilter.h.h. Skia benches show > > no impact from this change, but will watch the perf bots carefully. > > > > BUG=4212 > > > > Committed: https://skia.googlesource.com/skia/+/915881fe743f9a789037695f543bc6ea189cd0cb > > TBR=reed@google.com,senorblanco@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=4212 > > Committed: https://skia.googlesource.com/skia/+/12d8472d31ea5edb636d7d5214db253570115c40 TBR=reed@google.com,herb@google.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=4212 Review URL: https://codereview.chromium.org/1301823005
2015-08-20 18:10:41 +00:00
bool canComputeFastBounds() const;
/** (to be made private)
Only call this if canComputeFastBounds() returned true. This takes a
raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
effects in the paint (e.g. stroking). If needed, it uses the storage
parameter. It returns the adjusted bounds that can then be used
for SkCanvas::quickReject tests.
The returned SkRect will either be orig or storage, thus the caller
should not rely on storage being set to the result, but should always
use the returned value. It is legal for orig and storage to be the same
SkRect.
For example:
if (!path.isInverseFillType() && paint.canComputeFastBounds()) {
SkRect storage;
if (canvas->quickReject(paint.computeFastBounds(path.getBounds(), &storage))) {
return; // do not draw the path
}
}
// draw the path
@param orig geometry modified by SkPaint when drawn
@param storage computed bounds of geometry; may not be nullptr
@return fast computed bounds
*/
const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const {
// Things like stroking, etc... will do math on the bounds rect, assuming that it's sorted.
SkASSERT(orig.isSorted());
SkPaint::Style style = this->getStyle();
// ultra fast-case: filling with no effects that affect geometry
if (kFill_Style == style) {
uintptr_t effects = 0;
effects |= reinterpret_cast<uintptr_t>(this->getMaskFilter());
effects |= reinterpret_cast<uintptr_t>(this->getPathEffect());
effects |= reinterpret_cast<uintptr_t>(this->getImageFilter());
if (!effects) {
return orig;
}
}
return this->doComputeFastBounds(orig, storage, style);
}
/** (to be made private)
@param orig geometry modified by SkPaint when drawn
@param storage computed bounds of geometry
@return fast computed bounds
*/
const SkRect& computeFastStrokeBounds(const SkRect& orig,
SkRect* storage) const {
return this->doComputeFastBounds(orig, storage, kStroke_Style);
}
/** (to be made private)
Computes the bounds, overriding the SkPaint SkPaint::Style. This can be used to
account for additional width required by stroking orig, without
altering SkPaint::Style set to fill.
@param orig geometry modified by SkPaint when drawn
@param storage computed bounds of geometry
@param style overrides SkPaint::Style
@return fast computed bounds
*/
const SkRect& doComputeFastBounds(const SkRect& orig, SkRect* storage,
Style style) const;
private:
sk_sp<SkPathEffect> fPathEffect;
sk_sp<SkShader> fShader;
sk_sp<SkMaskFilter> fMaskFilter;
sk_sp<SkColorFilter> fColorFilter;
sk_sp<SkImageFilter> fImageFilter;
SkColor4f fColor4f;
SkScalar fWidth;
SkScalar fMiterLimit;
Merge tomhudson and mtklein SkPaint shrinking approaches. I think this is cherry picking the best parts of both our CLs. We've got dirty bit tracking from Tom's, picture format stability from Mike's, etc. Paints are typically 1/3 their original size when flattened in the dictionary. bench_record on my desktop looks promising. Generally, looks faster. (Best in monospace.) a/b skp before after 0.83 desk_techcrunch.skp 0.29 0.24 0.83 tabl_gamedeksiam.skp 0.52 0.43 0.87 desk_carsvg.skp 0.4 0.35 0.87 desk_googlehome.skp 0.038 0.033 0.87 desk_pokemonwiki.skp 3.9 3.4 0.88 desk_fontwipe.skp 0.0089 0.0078 0.88 desk_googlespreadsheet.skp 0.16 0.14 0.89 desk_jsfiddlebigcar.skp 0.027 0.024 0.89 desk_tigersvg.skp 0.038 0.034 0.89 desk_weather.skp 0.19 0.17 0.89 tabl_engadget.skp 0.37 0.33 0.89 tabl_googleblog.skp 0.28 0.25 0.9 desk_facebook.skp 0.2 0.18 0.91 desk_mapsvg.skp 0.45 0.41 0.91 desk_youtube.skp 0.22 0.2 0.92 desk_forecastio.skp 0.12 0.11 0.92 desk_googlespreadsheetdashed.skp 0.49 0.45 0.92 desk_gws.skp 0.13 0.12 0.92 desk_pinterest.skp 0.037 0.034 0.92 desk_twitter.skp 0.25 0.23 0.92 tabl_culturalsolutions.skp 0.26 0.24 0.92 tabl_gspro.skp 0.072 0.066 0.92 tabl_mercurynews.skp 0.26 0.24 0.93 desk_booking.skp 0.46 0.43 0.93 desk_chalkboard.skp 0.28 0.26 0.93 desk_linkedin.skp 0.14 0.13 0.93 desk_mobilenews.skp 0.28 0.26 0.93 tabl_cuteoverload.skp 0.46 0.43 0.93 tabl_deviantart.skp 0.15 0.14 0.93 tabl_gmail.skp 0.029 0.027 0.93 tabl_googlecalendar.skp 0.15 0.14 0.93 tabl_mlb.skp 0.15 0.14 0.94 desk_blogger.skp 0.18 0.17 0.94 desk_jsfiddlehumperclip.skp 0.034 0.032 0.94 desk_wordpress.skp 0.33 0.31 0.94 desk_wowwiki.skp 0.94 0.88 0.94 desk_yahooanswers.skp 0.17 0.16 0.94 desk_youtubetvvideo.skp 0.017 0.016 0.94 tabl_sahadan.skp 0.093 0.087 0.94 tabl_worldjournal.skp 0.35 0.33 0.95 desk_css3gradients.skp 0.21 0.2 0.95 desk_gmailthread.skp 0.19 0.18 0.95 tabl_cnet.skp 0.42 0.4 0.95 tabl_mozilla.skp 1.9 1.8 0.95 tabl_pravda.skp 0.19 0.18 0.96 mobi_wikipedia.skp 0.55 0.53 0.96 tabl_cnn.skp 0.48 0.46 0.96 tabl_nofolo.skp 0.05 0.048 0.97 desk_googleplus.skp 0.29 0.28 0.97 tabl_frantzen.skp 0.059 0.057 0.97 tabl_onlinewsj.skp 0.38 0.37 0.97 tabl_slashdot.skp 0.1 0.097 0.97 tabl_vnexpress.skp 0.29 0.28 0.99 desk_amazon.skp 0.088 0.087 1 desk_baidu.skp 0.097 0.099 1 desk_ebay.skp 0.18 0.18 1 desk_espn.skp 0.24 0.24 1 desk_oldinboxapp.skp 0.026 0.026 1 desk_rectangletransition.skp 0.014 0.014 1 desk_samoasvg.skp 0.23 0.24 1 desk_yahoogames.skp 0.029 0.029 1 desk_yahoosports.skp 0.0033 0.0033 1 desk_youtubetvbrowse.skp 0.01 0.01 1 tabl_androidpolice.skp 0.65 0.65 1 tabl_digg.skp 0.33 0.33 1 tabl_hsfi.skp 0.32 0.32 1 tabl_nytimes.skp 0.22 0.22 1 tabl_techmeme.skp 0.069 0.072 1 tabl_ukwsj.skp 0.35 0.35 1.1 desk_sfgate.skp 0.25 0.28 BUG=skia:2190,skia:2194 Committed: http://code.google.com/p/skia/source/detail?r=13487 Committed: http://code.google.com/p/skia/source/detail?r=13496 R=tomhudson@google.com, reed@google.com, mtklein@google.com, robertphillips@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/158913005 git-svn-id: http://skia.googlecode.com/svn/trunk@13536 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-21 18:18:05 +00:00
union {
struct {
unsigned fAntiAlias : 1;
unsigned fDither : 1;
unsigned fCapType : 2;
unsigned fJoinType : 2;
unsigned fStyle : 2;
unsigned fFilterQuality : 2;
unsigned fBlendMode : 8; // only need 5-6?
unsigned fPadding : 14; // 14==32-1-1-2-2-2-2-8
} fBitfields;
uint32_t fBitfieldsUInt;
Merge tomhudson and mtklein SkPaint shrinking approaches. I think this is cherry picking the best parts of both our CLs. We've got dirty bit tracking from Tom's, picture format stability from Mike's, etc. Paints are typically 1/3 their original size when flattened in the dictionary. bench_record on my desktop looks promising. Generally, looks faster. (Best in monospace.) a/b skp before after 0.83 desk_techcrunch.skp 0.29 0.24 0.83 tabl_gamedeksiam.skp 0.52 0.43 0.87 desk_carsvg.skp 0.4 0.35 0.87 desk_googlehome.skp 0.038 0.033 0.87 desk_pokemonwiki.skp 3.9 3.4 0.88 desk_fontwipe.skp 0.0089 0.0078 0.88 desk_googlespreadsheet.skp 0.16 0.14 0.89 desk_jsfiddlebigcar.skp 0.027 0.024 0.89 desk_tigersvg.skp 0.038 0.034 0.89 desk_weather.skp 0.19 0.17 0.89 tabl_engadget.skp 0.37 0.33 0.89 tabl_googleblog.skp 0.28 0.25 0.9 desk_facebook.skp 0.2 0.18 0.91 desk_mapsvg.skp 0.45 0.41 0.91 desk_youtube.skp 0.22 0.2 0.92 desk_forecastio.skp 0.12 0.11 0.92 desk_googlespreadsheetdashed.skp 0.49 0.45 0.92 desk_gws.skp 0.13 0.12 0.92 desk_pinterest.skp 0.037 0.034 0.92 desk_twitter.skp 0.25 0.23 0.92 tabl_culturalsolutions.skp 0.26 0.24 0.92 tabl_gspro.skp 0.072 0.066 0.92 tabl_mercurynews.skp 0.26 0.24 0.93 desk_booking.skp 0.46 0.43 0.93 desk_chalkboard.skp 0.28 0.26 0.93 desk_linkedin.skp 0.14 0.13 0.93 desk_mobilenews.skp 0.28 0.26 0.93 tabl_cuteoverload.skp 0.46 0.43 0.93 tabl_deviantart.skp 0.15 0.14 0.93 tabl_gmail.skp 0.029 0.027 0.93 tabl_googlecalendar.skp 0.15 0.14 0.93 tabl_mlb.skp 0.15 0.14 0.94 desk_blogger.skp 0.18 0.17 0.94 desk_jsfiddlehumperclip.skp 0.034 0.032 0.94 desk_wordpress.skp 0.33 0.31 0.94 desk_wowwiki.skp 0.94 0.88 0.94 desk_yahooanswers.skp 0.17 0.16 0.94 desk_youtubetvvideo.skp 0.017 0.016 0.94 tabl_sahadan.skp 0.093 0.087 0.94 tabl_worldjournal.skp 0.35 0.33 0.95 desk_css3gradients.skp 0.21 0.2 0.95 desk_gmailthread.skp 0.19 0.18 0.95 tabl_cnet.skp 0.42 0.4 0.95 tabl_mozilla.skp 1.9 1.8 0.95 tabl_pravda.skp 0.19 0.18 0.96 mobi_wikipedia.skp 0.55 0.53 0.96 tabl_cnn.skp 0.48 0.46 0.96 tabl_nofolo.skp 0.05 0.048 0.97 desk_googleplus.skp 0.29 0.28 0.97 tabl_frantzen.skp 0.059 0.057 0.97 tabl_onlinewsj.skp 0.38 0.37 0.97 tabl_slashdot.skp 0.1 0.097 0.97 tabl_vnexpress.skp 0.29 0.28 0.99 desk_amazon.skp 0.088 0.087 1 desk_baidu.skp 0.097 0.099 1 desk_ebay.skp 0.18 0.18 1 desk_espn.skp 0.24 0.24 1 desk_oldinboxapp.skp 0.026 0.026 1 desk_rectangletransition.skp 0.014 0.014 1 desk_samoasvg.skp 0.23 0.24 1 desk_yahoogames.skp 0.029 0.029 1 desk_yahoosports.skp 0.0033 0.0033 1 desk_youtubetvbrowse.skp 0.01 0.01 1 tabl_androidpolice.skp 0.65 0.65 1 tabl_digg.skp 0.33 0.33 1 tabl_hsfi.skp 0.32 0.32 1 tabl_nytimes.skp 0.22 0.22 1 tabl_techmeme.skp 0.069 0.072 1 tabl_ukwsj.skp 0.35 0.35 1.1 desk_sfgate.skp 0.25 0.28 BUG=skia:2190,skia:2194 Committed: http://code.google.com/p/skia/source/detail?r=13487 Committed: http://code.google.com/p/skia/source/detail?r=13496 R=tomhudson@google.com, reed@google.com, mtklein@google.com, robertphillips@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/158913005 git-svn-id: http://skia.googlecode.com/svn/trunk@13536 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-02-21 18:18:05 +00:00
};
};
#endif