Flutter Engine
The Flutter Engine
Namespaces | Enumerations | Functions
SkImageShader.cpp File Reference
#include "src/shaders/SkImageShader.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkColorType.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkTileMode.h"
#include "include/private/base/SkMath.h"
#include "modules/skcms/skcms.h"
#include "src/base/SkArenaAlloc.h"
#include "src/core/SkBitmapProcState.h"
#include "src/core/SkColorSpaceXformSteps.h"
#include "src/core/SkEffectPriv.h"
#include "src/core/SkImageInfoPriv.h"
#include "src/core/SkImagePriv.h"
#include "src/core/SkMipmapAccessor.h"
#include "src/core/SkPicturePriv.h"
#include "src/core/SkRasterPipeline.h"
#include "src/core/SkRasterPipelineOpContexts.h"
#include "src/core/SkRasterPipelineOpList.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkSamplingPriv.h"
#include "src/core/SkWriteBuffer.h"
#include "src/image/SkImage_Base.h"
#include <optional>
#include <tuple>
#include <utility>

Go to the source code of this file.

Namespaces

namespace  SkShaders
 

Enumerations

enum class  LegacyFilterEnum {
  kNone , kLow , kMedium , kHigh ,
  kInheritFromPaint , kUseFilterOptions , kUseCubicResampler , kLast = kUseCubicResampler
}
 

Functions

static SkTileMode optimize (SkTileMode tm, int dimension)
 
sk_sp< SkShaderSkMakeBitmapShaderForPaint (const SkPaint &paint, const SkBitmap &src, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &sampling, const SkMatrix *localMatrix, SkCopyPixelsMode mode)
 
SkRect SkModifyPaintAndDstForDrawImageRect (const SkImage *image, const SkSamplingOptions &sampling, SkRect src, SkRect dst, bool strictSrcSubset, SkPaint *paint)
 
static SkSamplingOptions tweak_sampling (SkSamplingOptions sampling, const SkMatrix &matrix)
 
SK_API sk_sp< SkShaderSkShaders::Image (sk_sp< SkImage > image, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &options, const SkMatrix *localMatrix=nullptr)
 
SK_API sk_sp< SkShaderSkShaders::RawImage (sk_sp< SkImage > image, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &options, const SkMatrix *localMatrix=nullptr)
 

Enumeration Type Documentation

◆ LegacyFilterEnum

enum class LegacyFilterEnum
strong
Enumerator
kNone 
kLow 
kMedium 
kHigh 
kInheritFromPaint 
kUseFilterOptions 
kUseCubicResampler 
kLast 

Definition at line 116 of file SkImageShader.cpp.

116 {
117 kNone,
118 kLow,
119 kMedium,
120 kHigh,
121 // this is the special value for backward compatibility
123 // this signals we should use the new SkFilterOptions
125 // use cubic and ignore FilterOptions
127
129};
@ kNone
Definition: layer.h:53

Function Documentation

◆ optimize()

static SkTileMode optimize ( SkTileMode  tm,
int  dimension 
)
static

We are faster in clamp, so always use that tiling when we can.

Definition at line 76 of file SkImageShader.cpp.

76 {
77 SkASSERT(dimension > 0);
78#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
79 // need to update frameworks/base/libs/hwui/tests/unit/SkiaBehaviorTests.cpp:55 to allow
80 // for transforming to clamp.
81 return tm;
82#else
83 // mirror and repeat on a 1px axis are the same as clamping, but decal will still transition to
84 // transparent black.
85 return (tm != SkTileMode::kDecal && dimension == 1) ? SkTileMode::kClamp : tm;
86#endif
87}
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ SkMakeBitmapShaderForPaint()

sk_sp< SkShader > SkMakeBitmapShaderForPaint ( const SkPaint paint,
const SkBitmap src,
SkTileMode  tmx,
SkTileMode  tmy,
const SkSamplingOptions sampling,
const SkMatrix localMatrix,
SkCopyPixelsMode  mode 
)

Definition at line 358 of file SkImageShader.cpp.

361 {
363 tmx, tmy, sampling, localMatrix);
364 if (!s) {
365 return nullptr;
366 }
367 if (SkColorTypeIsAlphaOnly(src.colorType()) && paint.getShader()) {
368 // Compose the image shader with the paint's shader. Alpha images+shaders should output the
369 // texture's alpha multiplied by the shader's color. DstIn (d*sa) will achieve this with
370 // the source image and dst shader (MakeBlend takes dst first, src second).
371 s = SkShaders::Blend(SkBlendMode::kDstIn, paint.refShader(), std::move(s));
372 }
373 return s;
374}
@ kDstIn
r = d * sa
static bool SkColorTypeIsAlphaOnly(SkColorType ct)
SK_SPI sk_sp< SkImage > SkMakeImageFromRasterBitmap(const SkBitmap &, SkCopyPixelsMode)
static sk_sp< SkShader > Make(sk_sp< SkImage >, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix, bool clampAsIfUnpremul=false)
const Paint & paint
Definition: color_source.cc:38
struct MyStruct s
SkSamplingOptions sampling
Definition: SkRecords.h:337
SK_API sk_sp< SkShader > Blend(SkBlendMode mode, sk_sp< SkShader > dst, sk_sp< SkShader > src)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
SkTileMode tmy
SkTileMode tmx

◆ SkModifyPaintAndDstForDrawImageRect()

SkRect SkModifyPaintAndDstForDrawImageRect ( const SkImage image,
const SkSamplingOptions sampling,
SkRect  src,
SkRect  dst,
bool  strictSrcSubset,
SkPaint paint 
)

Definition at line 376 of file SkImageShader.cpp.

381 {
382 // The paint should have already been cleaned for a regular drawImageRect, e.g. no path
383 // effect and is a fill.
385 SkASSERT(paint->getStyle() == SkPaint::kFill_Style && !paint->getPathEffect());
386
388 SkRect imgBounds = SkRect::Make(image->bounds());
389
390 SkASSERT(src.isFinite() && dst.isFinite() && dst.isSorted());
391 SkMatrix localMatrix = SkMatrix::RectToRect(src, dst);
392 if (!imgBounds.contains(src)) {
393 if (!src.intersect(imgBounds)) {
394 return SkRect::MakeEmpty(); // Nothing to draw for this entry
395 }
396 // Update dst to match smaller src
397 dst = localMatrix.mapRect(src);
398 }
399
400 bool imageIsAlphaOnly = SkColorTypeIsAlphaOnly(image->colorType());
401
402 sk_sp<SkShader> imgShader;
403 if (strictSrcSubset) {
406 sampling, &localMatrix);
407 } else {
409 sampling, &localMatrix);
410 }
411 if (!imgShader) {
412 return SkRect::MakeEmpty();
413 }
414 if (imageIsAlphaOnly && paint->getShader()) {
415 // Compose the image shader with the paint's shader. Alpha images+shaders should output the
416 // texture's alpha multiplied by the shader's color. DstIn (d*sa) will achieve this with
417 // the source image and dst shader (MakeBlend takes dst first, src second).
418 imgShader = SkShaders::Blend(SkBlendMode::kDstIn, paint->refShader(), std::move(imgShader));
419 }
420
421 paint->setShader(std::move(imgShader));
422 return dst;
423}
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
static sk_sp< SkShader > MakeSubset(sk_sp< SkImage >, const SkRect &subset, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix, bool clampAsIfUnpremul=false)
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
SkColorType colorType() const
Definition: SkImage.cpp:152
SkIRect bounds() const
Definition: SkImage.h:303
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition: SkMatrix.h:157
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkMatrix.cpp:1141
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
sk_sp< const SkImage > image
Definition: SkRecords.h:269
dst
Definition: cp.py:12
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595
bool contains(SkScalar x, SkScalar y) const
Definition: extension.cpp:19

◆ tweak_sampling()

static SkSamplingOptions tweak_sampling ( SkSamplingOptions  sampling,
const SkMatrix matrix 
)
static

Definition at line 495 of file SkImageShader.cpp.

495 {
497
498 // When the matrix is just an integer translate, bilerp == nearest neighbor.
499 if (filter == SkFilterMode::kLinear &&
500 matrix.getType() <= SkMatrix::kTranslate_Mask &&
501 matrix.getTranslateX() == (int)matrix.getTranslateX() &&
502 matrix.getTranslateY() == (int)matrix.getTranslateY()) {
503 filter = SkFilterMode::kNearest;
504 }
505
506 return SkSamplingOptions(filter, sampling.mipmap);
507}
SkFilterMode
@ kTranslate_Mask
translation SkMatrix
Definition: SkMatrix.h:193
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
SkSamplingOptions(SkFilterMode::kLinear))
const SkFilterMode filter
const SkMipmapMode mipmap