76 info.makeColorType(ct),
82bool valid_client_provided_image(
const SkImage* clientProvided,
85 if (!clientProvided ||
86 !
as_IB(clientProvided)->isGraphiteBacked() ||
94 if ((origChannels & clientChannels) != origChannels) {
99 auto graphiteImage =
static_cast<const Image*
>(clientProvided);
101 SKGPU_LOG_E(
"Client provided image must have a TopLeft origin.");
121#
if defined(GRAPHITE_USE_APPROX_FIT_FOR_FILTERS)
138 paint.setShader(std::move(blurEffect));
140 return device->snapSpecial(subset);
158 builder.uniform(
"kernel") = kernel;
162 input->makeSubset(srcRect)->asShader(tileMode,
166 return eval_blur(recorder,
builder.makeShader(), dstRect,
167 input->colorType(), std::move(outCS), outProps);
184 builder.uniform(
"offsetsAndKernel") = offsetsAndKernel;
188 input->makeSubset(srcRect)->asShader(tileMode,
192 return eval_blur(recorder,
builder.makeShader(), dstRect,
193 input->colorType(), std::move(outCS), outProps);
210 if (kernelArea <= kMaxBlurSamples && radiusX > 0 && radiusY > 0) {
212 return blur_2d(recorder, sigma, {radiusX, radiusY}, std::move(input), srcRect, tileMode,
213 dstRect, std::move(outCS), outProps);
217 SkIRect intermediateDstRect = dstRect;
220 intermediateDstRect.
outset(0, radiusY);
226 input = blur_1d(recorder, sigma.
width(), radiusX, {1.f, 0.f},
227 std::move(input), srcRect, tileMode, intermediateDstRect,
233 dstRect.
offset(-intermediateDstRect.
left(), -intermediateDstRect.
top());
237 input = blur_1d(recorder, sigma.
height(), radiusY, {0.f, 1.f},
238 std::move(input), srcRect, tileMode, dstRect, outCS, outProps);
255 auto inputImage = input->asImage();
262 srcRect.
makeOffset(input->subset().topLeft()),
263 inputImage->imageInfo().makeWH(targetSrcWidth, targetSrcHeight),
264 SkImage::RescaleGamma::kLinear,
265 SkImage::RescaleMode::kRepeatedLinear);
272 (dstRect.
top() - srcRect.
top()) * sy,
280 auto scaledOutput = blur_impl(
284 SkSpecialImages::MakeGraphite(recorder,
286 std::move(scaledInput),
298 auto scaledOutputImage = scaledOutput->asImage();
301 scaledOutputImage.get(),
302 scaledOutput->subset(),
303 scaledOutputImage->imageInfo().makeWH(dstRect.
width(), dstRect.
height()),
304 SkImage::RescaleGamma::kLinear,
305 SkImage::RescaleMode::kLinear);
310 SkIRect outputDstRect = outputImage->bounds();
311 return SkSpecialImages::MakeGraphite(recorder,
313 std::move(outputImage),
320class PromiseLazyInstantiateCallback {
323 GraphitePromiseTextureFulfillProc fulfillProc,
324 GraphitePromiseTextureFulfillContext fulfillContext,
325 GraphitePromiseTextureReleaseProc textureReleaseProc)
326 : fReleaseHelper(
std::move(releaseHelper))
327 , fFulfillProc(fulfillProc)
328 , fFulfillContext(fulfillContext)
329 , fTextureReleaseProc(textureReleaseProc) {
331 PromiseLazyInstantiateCallback(PromiseLazyInstantiateCallback&&) =
default;
332 PromiseLazyInstantiateCallback(
const PromiseLazyInstantiateCallback&) {
337 PromiseLazyInstantiateCallback& operator=(PromiseLazyInstantiateCallback&&) =
default;
338 PromiseLazyInstantiateCallback& operator=(
const PromiseLazyInstantiateCallback&) {
345 auto [ backendTexture, textureReleaseCtx ] = fFulfillProc(fFulfillContext);
346 if (!backendTexture.isValid()) {
347 SKGPU_LOG_W(
"FulfillProc returned an invalid backend texture");
356 SKGPU_LOG_W(
"Failed to wrap BackendTexture returned by fulfill proc");
360 texture->setReleaseCallback(std::move(textureReleaseCB));
382 if (
bitmap.dimensions().area() <= 1) {
383 mipmapped = Mipmapped::kNo;
389 if (!textureInfo.isValid()) {
398 if (ct !=
bitmap.info().colorType()) {
412 int mipLevelCount = (mipmapped == Mipmapped::kYes) ?
418 std::vector<MipLevel> texels;
419 if (mipLevelCount == 1) {
420 texels.resize(mipLevelCount);
421 texels[0].fPixels = bmpToUpload.
getPixels();
422 texels[0].fRowBytes = bmpToUpload.
rowBytes();
431 SkASSERT(mipLevelCount == mipmaps->countLevels() + 1);
432 texels.resize(mipLevelCount);
434 texels[0].fPixels = bmpToUpload.
getPixels();
435 texels[0].fRowBytes = bmpToUpload.
rowBytes();
437 for (
int i = 1; i < mipLevelCount; ++i) {
439 mipmaps->getLevel(i - 1, &generatedMipLevel);
440 texels[i].fPixels = generatedMipLevel.
fPixmap.
addr();
449 bmpToUpload.
dimensions(), textureInfo, budgeted);
454 SkASSERT(mipmapped == Mipmapped::kNo || proxy->mipmapped() == Mipmapped::kYes);
460 recorder, proxy, colorInfo, colorInfo, texels,
463 SKGPU_LOG_E(
"MakeBitmapProxyView: Could not create UploadInstance");
473 return {{std::move(proxy), swizzle}, ct};
482 GraphitePromiseTextureFulfillProc fulfillProc,
483 GraphitePromiseTextureFulfillContext fulfillContext,
484 GraphitePromiseTextureReleaseProc textureReleaseProc) {
492 PromiseLazyInstantiateCallback
callback{std::move(releaseHelper), fulfillProc,
493 fulfillContext, textureReleaseProc};
506 auto mm = requiredProps.
fMipmapped ? Mipmapped::kYes : Mipmapped::kNo;
513 return sk_make_sp<skgpu::graphite::Image>(std::move(view), colorInfo.
makeColorType(ct));
521 size_t colorSize = 0;
526 info.mipmapped() == Mipmapped::kYes);
530 size_t bytesPerPixel =
info.bytesPerPixel();
532 colorSize = (size_t)dimensions.
width() * dimensions.
height() * bytesPerPixel;
535 size_t finalSize = colorSize *
info.numSamples();
537 if (
info.mipmapped() == Mipmapped::kYes) {
538 finalSize += colorSize/3;
551 "width", srcIRect.
width(),
"height", srcIRect.
height());
553 "width", dstInfo.
width(),
"height", dstInfo.
height());
557 sk_sp<SkSurface> dst = make_renderable_scratch_surface(recorder, dstInfo, &surfaceProps);
567 auto srcGraphiteImage =
reinterpret_cast<const graphite::Image*
>(srcImage);
570 if (!imageView.
proxy()) {
579 if (finalSize == srcIRect.
size()) {
580 rescaleGamma = Image::RescaleGamma::kSrc;
581 rescaleMode = Image::RescaleMode::kNearest;
592 if (rescaleGamma == Image::RescaleGamma::kLinear &&
598 tempInput->imageInfo().colorType(),
600 std::move(linearGamma));
601 tempOutput = make_renderable_scratch_surface(recorder, gammaDstInfo, &surfaceProps);
605 SkCanvas* gammaDst = tempOutput->getCanvas();
614 srcRect = gammaDstRect;
620 if (rescaleMode != Image::RescaleMode::kNearest &&
621 rescaleMode != Image::RescaleMode::kLinear) {
623 nextDims.
fWidth = std::max((srcRect.
width() + 1)/2, (
float)finalSize.
width());
624 }
else if (srcRect.
width() < finalSize.
width()) {
635 if (nextDims == finalSize) {
637 stepDstRect = dstRect;
640 tempOutput = make_renderable_scratch_surface(recorder, nextInfo, &surfaceProps);
644 stepDstRect =
SkRect::Make(tempOutput->imageInfo().dimensions());
648 if (rescaleMode == Image::RescaleMode::kRepeatedCubic) {
651 samplingOptions = (rescaleMode == Image::RescaleMode::kNearest) ?
657 tempOutput->getCanvas()->drawImageRect(tempInput, srcRect, stepDstRect, samplingOptions,
690 for (
int i = 0; i < 2; ++i) {
691 scratchSurfaces[i] = make_renderable_scratch_surface(
694 std::max(1, srcSize.
height() >> (i + 1))),
696 if (!scratchSurfaces[i]) {
701 for (
int mipLevel = 1; srcSize.
width() > 1 || srcSize.
height() > 1; ++mipLevel) {
703 std::max(srcSize.
height() >> 1, 1));
705 Surface* scratchSurface = scratchSurfaces[(mipLevel - 1) & 1].get();
717 Flush(scratchSurface);
720 static_cast<const Surface*
>(scratchSurface)->readSurfaceView().refProxy(),
728 recorder->
priv().
add(std::move(copyTask));
730 scratchImg = scratchSurface->
asImage();
741 ? Mipmapped::kYes : Mipmapped::kNo;
743 if (imageIn->
dimensions().
area() <= 1 && mipmapped == Mipmapped::kYes) {
744 mipmapped = Mipmapped::kNo;
749 if (
as_IB(imageIn)->isGraphiteBacked()) {
754 if (mipmapped == Mipmapped::kYes && !
result->hasMipmaps()) {
755 mipmapped = Mipmapped::kNo;
761 recorder, imageIn, {mipmapped == Mipmapped::kYes});
763 if (!valid_client_provided_image(
764 result.get(), imageIn, {mipmapped == Mipmapped::kYes})) {
774 return {
result, sampling };
789 auto gi =
reinterpret_cast<const Image*
>(
image);
820 , fRecorder(recorder) {}
829 std::move(colorSpace));
833 skgpu::Mipmapped::kNo,
834#
if defined(GRAPHITE_USE_APPROX_FIT_FOR_FILTERS)
839 props ? *props : this->surfaceProps(),
844 return SkSpecialImages::MakeGraphite(fRecorder, subset,
image, this->surfaceProps());
855 proxy->textureInfo());
856 return sk_make_sp<skgpu::graphite::Image>(
861 const SkBlurEngine* getBlurEngine()
const override {
return this; }
871 float maxSigma()
const override {
877 bool supportsOnlyDecalTiling()
const override {
return false; }
883 const SkIRect& dstRect)
const override {
885 "sigmaX", sigma.
width(),
"sigmaY", sigma.
height());
888 return skgpu::graphite::blur_impl(fRecorder, sigma, std::move(src), srcRect, tileMode,
889 dstRect,
sk_ref_sp(cs), this->surfaceProps());
902 return sk_make_sp<GraphiteBackend>(recorder, surfaceProps,
colorType);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
#define SKGPU_LOG_E(fmt,...)
#define SKGPU_LOG_W(fmt,...)
static sk_sp< Effect > Create()
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kUnknown_SkColorType
uninitialized
size_t SkCompressedFormatDataSize(SkTextureCompressionType compressionType, SkISize dimensions, bool mipmapped)
#define sk_float_ceil2int(x)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static uint32_t SkColorTypeChannelFlags(SkColorType ct)
static bool SkColorTypeIsAlphaOnly(SkColorType ct)
static bool SkImageInfoIsValid(const SkImageInfo &info)
static SkImage_Base * as_IB(SkImage *image)
sk_sp< T > sk_ref_sp(T *obj)
#define SK_ScalarInfinity
static constexpr bool SkToBool(const T &x)
#define TRACE_EVENT_SCOPE_THREAD
SkISize dimensions() const
const SkPixmap & pixmap() const
SkColorType colorType() const
const SkImageInfo & info() const
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
SkColorInfo makeAlphaType(SkAlphaType newAlphaType) const
SkColorInfo makeColorType(SkColorType newColorType) const
SkColorType colorType() const
bool gammaIsLinear() const
sk_sp< SkColorSpace > makeLinearGamma() const
const SkImageInfo & imageInfo() const
SkISize dimensions() const
SkAlphaType alphaType() const
SkColorType colorType() const
static SkM44 Translate(SkScalar x, SkScalar y, SkScalar z=0)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
static SkMipmap * Build(const SkPixmap &src, SkDiscardableFactoryProc, bool computeContents=true)
static int ComputeLevelCount(int baseWidth, int baseHeight)
SkColorType colorType() const
const void * addr() const
static SkSamplingOptions AnisoFallback(bool imageIsMipped)
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)
static constexpr Swizzle Concat(const Swizzle &a, const Swizzle &b)
skgpu::Swizzle getReadSwizzle(SkColorType, const TextureInfo &) const
virtual TextureInfo getDefaultStorageTextureInfo(SkColorType) const =0
virtual bool isStorage(const TextureInfo &) const =0
SkColorType getRenderableColorType(SkColorType) const
virtual TextureInfo getDefaultSampledTextureInfo(SkColorType, Mipmapped mipmapped, Protected, Renderable) const =0
bool areColorTypeAndTextureInfoCompatible(SkColorType, const TextureInfo &) const
static sk_sp< CopyTextureToTextureTask > Make(sk_sp< TextureProxy > srcProxy, SkIRect srcRect, sk_sp< TextureProxy > dstProxy, SkIPoint dstPoint, int dstLevel=0)
static sk_sp< Device > Make(Recorder *recorder, sk_sp< TextureProxy >, SkISize deviceSize, const SkColorInfo &, const SkSurfaceProps &, LoadOp initialLoadOp, bool registerWithRecorder=true)
virtual sk_sp< SkImage > findOrCreate(Recorder *recorder, const SkImage *image, SkImage::RequiredProperties)=0
const TextureProxyView & textureProxyView() const
static sk_sp< TextureProxy > CreateCachedProxy(Recorder *, const SkBitmap &, Mipmapped=skgpu::Mipmapped::kNo)
Protected isProtected() const
const Caps * caps() const
ResourceProvider * resourceProvider()
ImageProvider * clientImageProvider()
sk_sp< Image > asImage() const
static sk_sp< Surface > MakeScratch(Recorder *recorder, const SkImageInfo &info, Budgeted budgeted=Budgeted::kYes, Mipmapped mipmapped=Mipmapped::kNo, SkBackingFit backingFit=SkBackingFit::kApprox)
TextureProxy * proxy() const
static sk_sp< TextureProxy > Make(const Caps *, ResourceProvider *, SkISize dimensions, const TextureInfo &, skgpu::Budgeted)
static sk_sp< TextureProxy > MakeLazy(const Caps *, SkISize dimensions, const TextureInfo &, skgpu::Budgeted, Volatile, LazyInstantiateCallback &&)
static UploadInstance Make(Recorder *, sk_sp< TextureProxy > targetProxy, const SkColorInfo &srcColorInfo, const SkColorInfo &dstColorInfo, SkSpan< const MipLevel > levels, const SkIRect &dstRect, std::unique_ptr< ConditionalUploadContext >)
static sk_sp< UploadTask > Make(UploadList *)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
void * GraphitePromiseTextureFulfillContext
std::tuple< skgpu::graphite::BackendTexture, GraphitePromiseTextureReleaseContext >(*)(GraphitePromiseTextureFulfillContext) GraphitePromiseTextureFulfillProc
void(*)(GraphitePromiseTextureReleaseContext) GraphitePromiseTextureReleaseProc
SK_API sk_sp< SkImage > AsImage(sk_sp< const SkSurface >)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
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 Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
bool GenerateMipmaps(Recorder *recorder, sk_sp< TextureProxy > texture, const SkColorInfo &colorInfo)
SkColorType ComputeShaderCoverageMaskTargetFormat(const Caps *caps)
sk_sp< SkImage > RescaleImage(Recorder *recorder, const SkImage *srcImage, SkIRect srcIRect, const SkImageInfo &dstInfo, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode)
std::tuple< TextureProxyView, SkColorType > MakeBitmapProxyView(Recorder *recorder, const SkBitmap &bitmap, sk_sp< SkMipmap > mipmapsIn, Mipmapped mipmapped, Budgeted budgeted)
void Flush(sk_sp< SkSurface > surface)
sk_sp< SkImage > MakeFromBitmap(Recorder *recorder, const SkColorInfo &colorInfo, const SkBitmap &bitmap, sk_sp< SkMipmap > mipmaps, Budgeted budgeted, SkImage::RequiredProperties requiredProps)
sk_sp< TextureProxy > MakePromiseImageLazyProxy(const Caps *caps, SkISize dimensions, TextureInfo textureInfo, Volatile isVolatile, sk_sp< RefCntedCallback > releaseHelper, GraphitePromiseTextureFulfillProc fulfillProc, GraphitePromiseTextureFulfillContext fulfillContext, GraphitePromiseTextureReleaseProc textureReleaseProc)
std::pair< sk_sp< SkImage >, SkSamplingOptions > GetGraphiteBacked(Recorder *recorder, const SkImage *imageIn, SkSamplingOptions sampling)
size_t ComputeSize(SkISize dimensions, const TextureInfo &info)
TextureProxyView AsView(const SkImage *image)
static constexpr int kMaxBlurSamples
static constexpr float kMaxLinearBlurSigma
void Compute2DBlurOffsets(SkISize radius, std::array< SkV4, kMaxBlurSamples/2 > &offsets)
const SkRuntimeEffect * GetLinearBlur1DEffect(int radius)
int BlurSigmaRadius(float sigma)
constexpr int BlurKernelWidth(int radius)
void Compute2DBlurKernel(SkSize sigma, SkISize radius, SkSpan< float > kernel)
const SkRuntimeEffect * GetBlur2DEffect(const SkISize &radii)
void Compute1DBlurLinearKernel(float sigma, int radius, std::array< SkV4, kMaxBlurSamples/2 > &offsetsAndKernel)
static constexpr SkCubicResampler CatmullRom()
SkIRect makeOutset(int32_t dx, int32_t dy) const
bool intersect(const SkIRect &r)
constexpr int32_t top() const
constexpr SkISize size() const
constexpr int32_t height() const
static constexpr SkIRect MakeSize(const SkISize &size)
constexpr int32_t width() const
void offset(int32_t dx, int32_t dy)
constexpr SkIRect makeOffset(int32_t dx, int32_t dy) const
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
void outset(int32_t dx, int32_t dy)
constexpr int32_t left() const
static constexpr SkISize Make(int32_t w, int32_t h)
constexpr int32_t width() const
constexpr int32_t height() const
constexpr int64_t area() const
const SkColorInfo & colorInfo() const
SkImageInfo makeDimensions(SkISize newSize) const
SkColorSpace * colorSpace() const
SkISize dimensions() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static SkRect Make(const SkISize &size)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
void roundOut(SkIRect *dst) const
constexpr float height() const
constexpr float width() const
const SkMipmapMode mipmap
#define TRACE_EVENT0(category_group, name)
#define TRACE_EVENT_INSTANT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)