41 if (localMatrix && !localMatrix->
invert(
nullptr)) {
48static unsigned gImageFromPictureKeyNamespaceLabel;
53 uint32_t pictureID,
const SkRect& subset,
55 : fColorSpaceXYZHash(colorSpace->toXYZD50Hash())
56 , fColorSpaceTransferFnHash(colorSpace->transferFnHash())
60 , fSurfaceProps(surfaceProps)
62 static const size_t keySize =
sizeof(fColorSpaceXYZHash) +
63 sizeof(fColorSpaceTransferFnHash) +
67 sizeof(fSurfaceProps);
69 SkASSERT(
sizeof(uint32_t) * (&fEndOfStruct - &fColorSpaceXYZHash) == keySize);
70 this->init(&gImageFromPictureKeyNamespaceLabel,
76 uint32_t fColorSpaceXYZHash;
77 uint32_t fColorSpaceTransferFnHash;
91 ImageFromPictureKey fKey;
94 const Key& getKey()
const override {
return fKey; }
95 size_t bytesUsed()
const override {
97 return sizeof(fKey) + (
size_t)fImage->width() * fImage->height() * 4;
99 const char* getCategory()
const override {
return "bitmap-shader"; }
103 const ImageFromPictureRec& rec =
static_cast<const ImageFromPictureRec&
>(baseRec);
118 : fPicture(
std::move(picture))
119 , fTile(tile ? *tile : fPicture->cullRect())
127 return SkShaders::Empty();
129 return SkLocalMatrixShader::MakeWrapped<SkPictureShader>(lm,
150 bool didSerialize =
buffer.readBool();
155 unsigned legacyFilter =
buffer.read32();
169 buffer.write32((
unsigned)fTmx);
170 buffer.write32((
unsigned)fTmy);
172 buffer.write32((
unsigned)fFilter);
185 const int maxTextureSize,
189 const SkSize scaledSize = [&]() {
201 size.fWidth *= bounds.width();
202 size.fHeight *= bounds.height();
205 static const SkScalar kMaxTileArea = 2048 * 2048;
206 SkScalar tileArea = size.width() * size.height();
207 if (tileArea > kMaxTileArea) {
209 size.set(size.width() * clampScale, size.height() * clampScale);
214 if (maxTextureSize) {
215 if (size.width() > maxTextureSize || size.height() > maxTextureSize) {
216 SkScalar downScale = maxTextureSize / std::max(size.width(), size.height());
226 return {
false, {}, {}, {}, {}};
230 tileSize.
height() / bounds.height()};
248 auto canvas = surf->getCanvas();
249 canvas->concat(matrixForDraw);
250 canvas->drawPicture(pict);
251 return surf->makeImageSnapshot();
260 const int maxTextureSize_NotUsedForCPU = 0;
263 dstColorType, dstColorSpace,
264 maxTextureSize_NotUsedForCPU,
270 ImageFromPictureKey
key(
info.imageInfo.colorSpace(),
info.imageInfo.colorType(),
295 bitmapShader = this->rasterShader(mRec.
totalMatrix(),
307#ifdef SK_ENABLE_LEGACY_SHADERCONTEXT
311 rec.fMatrixRec.totalMatrix(), rec.fDstColorType, rec.fDstColorSpace, rec.fProps);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
static bool SkIsFinite(T x, Pack... values)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static int SkColorTypeMaxBitsPerChannel(SkColorType ct)
static sk_sp< SkColorSpace > ref_or_srgb(SkColorSpace *cs)
sk_sp< T > sk_ref_sp(T *obj)
#define SkScalarFloorToScalar(x)
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
SkShaderBase * as_SB(SkShader *shader)
@ kUnknown_SkPixelGeometry
static SkScalar center(float pos0, float pos1)
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
static sk_sp< SkColorSpace > MakeSRGB()
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
static SkScalar DifferentialAreaScale(const SkMatrix &m, const SkPoint &p)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
bool invert(SkMatrix *inverse) const
bool decomposeScale(SkSize *scale, SkMatrix *remaining=nullptr) const
static void AddedToCache(const SkPicture *pic)
static uint64_t MakeSharedID(uint32_t pictureID)
@ kPictureShaderFilterParam_Version
@ kNoFilterQualityShaders_Version
static void Flatten(const sk_sp< const SkPicture >, SkWriteBuffer &buffer)
static sk_sp< SkPicture > MakeFromBuffer(SkReadBuffer &buffer)
bool appendStages(const SkStageRec &, const SkShaders::MatrixRec &) const override
static sk_sp< SkShader > Make(sk_sp< SkPicture >, SkTileMode, SkTileMode, SkFilterMode, const SkMatrix *, const SkRect *)
SkFilterMode filter() const
sk_sp< SkPicture > picture() const
void flatten(SkWriteBuffer &) const override
SkPictureShader(sk_sp< SkPicture >, SkTileMode, SkTileMode, SkFilterMode, const SkRect *)
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, SkFilterMode mode, const SkMatrix *localMatrix, const SkRect *tileRect) const
uint32_t uniqueID() const
virtual SkRect cullRect() const =0
static void Add(Rec *, void *payload=nullptr)
static bool Find(const Key &key, FindVisitor, void *context)
Context * makeContext(const ContextRec &, SkArenaAlloc *) const
virtual bool appendStages(const SkStageRec &, const SkShaders::MatrixRec &) const =0
SkMatrix totalMatrix() const
SkSurfaceProps cloneWithPixelGeometry(SkPixelGeometry newPixelGeometry) const
static const uint8_t buffer[]
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
Visitor(Ts...) -> Visitor< Ts... >
constexpr int32_t width() const
constexpr int32_t height() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static CachedImageInfo Make(const SkRect &bounds, const SkMatrix &totalM, SkColorType dstColorType, SkColorSpace *dstColorSpace, const int maxTextureSize, const SkSurfaceProps &propsIn)
sk_sp< SkImage > makeImage(sk_sp< SkSurface > surf, const SkPicture *pict) const
static SkRect MakeIWH(int w, int h)
const SkSurfaceProps & fSurfaceProps
SkColorType fDstColorType