Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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)
 

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};

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 365 of file SkImageShader.cpp.

368 {
370 tmx, tmy, sampling, localMatrix);
371 if (!s) {
372 return nullptr;
373 }
374 if (SkColorTypeIsAlphaOnly(src.colorType()) && paint.getShader()) {
375 // Compose the image shader with the paint's shader. Alpha images+shaders should output the
376 // texture's alpha multiplied by the shader's color. DstIn (d*sa) will achieve this with
377 // the source image and dst shader (MakeBlend takes dst first, src second).
378 s = SkShaders::Blend(SkBlendMode::kDstIn, paint.refShader(), std::move(s));
379 }
380 return s;
381}
@ 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
struct MyStruct s
SkTileMode tmy
SkTileMode tmx

◆ SkModifyPaintAndDstForDrawImageRect()

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

Definition at line 383 of file SkImageShader.cpp.

388 {
389 // The paint should have already been cleaned for a regular drawImageRect, e.g. no path
390 // effect and is a fill.
392 SkASSERT(paint->getStyle() == SkPaint::kFill_Style && !paint->getPathEffect());
393
395 SkRect imgBounds = SkRect::Make(image->bounds());
396
397 SkASSERT(src.isFinite() && dst.isFinite() && dst.isSorted());
398 SkMatrix localMatrix = SkMatrix::RectToRect(src, dst);
399 if (!imgBounds.contains(src)) {
400 if (!src.intersect(imgBounds)) {
401 return SkRect::MakeEmpty(); // Nothing to draw for this entry
402 }
403 // Update dst to match smaller src
404 dst = localMatrix.mapRect(src);
405 }
406
407 bool imageIsAlphaOnly = SkColorTypeIsAlphaOnly(image->colorType());
408
409 sk_sp<SkShader> imgShader;
410 if (strictSrcSubset) {
411 imgShader = SkImageShader::MakeSubset(sk_ref_sp(image), src,
413 sampling, &localMatrix);
414 } else {
416 sampling, &localMatrix);
417 }
418 if (!imgShader) {
419 return SkRect::MakeEmpty();
420 }
421 if (imageIsAlphaOnly && paint->getShader()) {
422 // Compose the image shader with the paint's shader. Alpha images+shaders should output the
423 // texture's alpha multiplied by the shader's color. DstIn (d*sa) will achieve this with
424 // the source image and dst shader (MakeBlend takes dst first, src second).
425 imgShader = SkShaders::Blend(SkBlendMode::kDstIn, paint->refShader(), std::move(imgShader));
426 }
427
428 paint->setShader(std::move(imgShader));
429 return dst;
430}
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
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
sk_sp< SkImage > image
Definition examples.cpp:29
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 502 of file SkImageShader.cpp.

502 {
504
505 // When the matrix is just an integer translate, bilerp == nearest neighbor.
506 if (filter == SkFilterMode::kLinear &&
507 matrix.getType() <= SkMatrix::kTranslate_Mask &&
508 matrix.getTranslateX() == (int)matrix.getTranslateX() &&
509 matrix.getTranslateY() == (int)matrix.getTranslateY()) {
510 filter = SkFilterMode::kNearest;
511 }
512
513 return SkSamplingOptions(filter, sampling.mipmap);
514}
SkFilterMode
@ kTranslate_Mask
translation SkMatrix
Definition SkMatrix.h:193
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258
SkSamplingOptions sampling
Definition SkRecords.h:337
const SkFilterMode filter
const SkMipmapMode mipmap