Skip to content

Commit

Permalink
Reland "Migrate SkImage::makeWithFilter to GrRecordingContext"
Browse files Browse the repository at this point in the history
This reverts commit d13b97f.

Reason for revert: Fixed chromium canary

Original change's description:
> Revert "Migrate SkImage::makeWithFilter to GrRecordingContext"
>
> This reverts commit 7f0129d.
>
> Reason for revert: Broke Chrome roll
>
> Original change's description:
> > Migrate SkImage::makeWithFilter to GrRecordingContext
> >
> > The staging flag landed in Chrome CL 2307531.
> >
> > Bug: skia:104662
> > Change-Id: I8a483bfb83e890bb0566cd252a464a6add89df4f
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304003
> > Reviewed-by: Robert Phillips <[email protected]>
> > Reviewed-by: Brian Salomon <[email protected]>
> > Commit-Queue: Adlai Holler <[email protected]>
>
> [email protected],[email protected],[email protected]
>
> Change-Id: I280dbffa26da71d53872266e62fa3bcaa3c00989
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:104662
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304802
> Reviewed-by: Adlai Holler <[email protected]>
> Commit-Queue: Adlai Holler <[email protected]>

[email protected],[email protected],[email protected]


Bug: skia:104662
Change-Id: I815677659f776966b1c7e362ce3df444834dd482
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304803
Reviewed-by: Robert Phillips <[email protected]>
Commit-Queue: Robert Phillips <[email protected]>
Auto-Submit: Adlai Holler <[email protected]>
  • Loading branch information
Adlai-Holler authored and Skia Commit-Bot committed Jul 22, 2020
1 parent 0137355 commit 247835b
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 83 deletions.
8 changes: 4 additions & 4 deletions bench/ImageFilterDAGBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class ImageMakeWithFilterDAGBench : public Benchmark {
SkIPoint offset = SkIPoint::Make(0, 0);
SkIRect discardSubset;

auto direct = GrAsDirectContext(canvas->recordingContext());
auto dContext = GrAsDirectContext(canvas->recordingContext());
// makeWithFilter will only use the GPU backend if the image is already a texture
sk_sp<SkImage> image = fImage->makeTextureImage(direct);
sk_sp<SkImage> image = fImage->makeTextureImage(dContext);
if (!image) {
image = fImage;
}
Expand All @@ -90,8 +90,8 @@ class ImageMakeWithFilterDAGBench : public Benchmark {

// But measure makeWithFilter() per loop since that's the focus of this benchmark
for (int j = 0; j < loops; j++) {
image = image->makeWithFilter(mergeFilter.get(), subset, subset, &discardSubset,
&offset);
image = image->makeWithFilter(dContext, mergeFilter.get(), subset, subset,
&discardSubset, &offset);
SkASSERT(image && image->dimensions() == fImage->dimensions());
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/Image_makeWithFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ void draw(SkCanvas* canvas) {
clipBounds.outset(60, 60);
SkIRect outSubset;
SkIPoint offset;
sk_sp<SkImage> filtered(image->makeWithFilter(offsetFilter.get(), subset, clipBounds,
&outSubset, &offset));
sk_sp<SkImage> filtered(image->makeWithFilter(canvas->recordingContext(), offsetFilter.get(),
subset, clipBounds, &outSubset, &offset));
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
Expand Down
24 changes: 13 additions & 11 deletions gm/imagemakewithfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,29 +271,29 @@ class ImageMakeWithFilterGM : public skiagm::GM {
// code paths (otherwise they may choose to do CPU filtering then upload)
sk_sp<SkImage> mainImage, auxImage;

auto recording = canvas->recordingContext();
if (recording) {
// In a DDL context, we can't use the GPU code paths and we will drop the work – skip.
auto direct = GrAsDirectContext(recording);
if (!direct) {
auto rContext = canvas->recordingContext();
// In a DDL context, we can't use the GPU code paths and we will drop the work – skip.
auto dContext = GrAsDirectContext(rContext);
if (rContext) {
if (!dContext) {
*errorMsg = "Requires a direct context.";
return DrawResult::kSkip;
}
if (direct->abandoned()) {
if (dContext->abandoned()) {
*errorMsg = "Direct context abandoned.";
return DrawResult::kSkip;
}
mainImage = fMainImage->makeTextureImage(direct);
auxImage = fAuxImage->makeTextureImage(direct);
mainImage = fMainImage->makeTextureImage(dContext);
auxImage = fAuxImage->makeTextureImage(dContext);
} else {
mainImage = fMainImage;
auxImage = fAuxImage;
}
if (!mainImage || !auxImage) {
return DrawResult::kFail;
}
SkASSERT(mainImage && (mainImage->isTextureBacked() || !recording));
SkASSERT(auxImage && (auxImage->isTextureBacked() || !recording));
SkASSERT(mainImage && (mainImage->isTextureBacked() || !rContext));
SkASSERT(auxImage && (auxImage->isTextureBacked() || !rContext));

SkScalar MARGIN = SkIntToScalar(40);
SkScalar DX = mainImage->width() + MARGIN;
Expand Down Expand Up @@ -376,7 +376,9 @@ class ImageMakeWithFilterGM : public skiagm::GM {
SkIRect outSubset;
SkIPoint offset;

result = mainImage->makeWithFilter(filter.get(), subset, clip, &outSubset, &offset);
auto rContext = canvas->recordingContext();
result = mainImage->makeWithFilter(rContext, filter.get(), subset, clip,
&outSubset, &offset);

SkASSERT(result);
SkASSERT(mainImage->isTextureBacked() == result->isTextureBacked());
Expand Down
12 changes: 6 additions & 6 deletions include/core/SkImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class GrContext;
class GrDirectContext;
class GrRecordingContext;
class GrContextThreadSafeProxy;
class GrRecordingContext;

struct SkYUVAIndex;

Expand Down Expand Up @@ -1253,7 +1252,8 @@ class SK_API SkImage : public SkRefCnt {
is required storage for the actual bounds of the filtered SkImage. offset is
required storage for translation of returned SkImage.
Returns nullptr if SkImage could not be created. If nullptr is returned, outSubset
Returns nullptr if SkImage could not be created or if the recording context provided doesn't
match the GPU context in which the image was created. If nullptr is returned, outSubset
and offset are undefined.
Useful for animation of SkImageFilter that varies size from frame to frame.
Expand All @@ -1262,24 +1262,24 @@ class SK_API SkImage : public SkRefCnt {
of GPU texture returned. offset translates the returned SkImage to keep subsequent
animation frames aligned with respect to each other.
@param context the GrContext in play - if it exists
@param context the GrRecordingContext in play - if it exists
@param filter how SkImage is sampled when transformed
@param subset bounds of SkImage processed by filter
@param clipBounds expected bounds of filtered SkImage
@param outSubset storage for returned SkImage bounds
@param offset storage for returned SkImage translation
@return filtered SkImage, or nullptr
*/
sk_sp<SkImage> makeWithFilter(GrContext* context,
sk_sp<SkImage> makeWithFilter(GrRecordingContext* context,
const SkImageFilter* filter, const SkIRect& subset,
const SkIRect& clipBounds, SkIRect* outSubset,
SkIPoint* offset) const;

/** To be deprecated.
*/
#ifdef SK_IMAGE_MAKE_WITH_FILTER_LEGACY_API
sk_sp<SkImage> makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
const SkIRect& clipBounds, SkIRect* outSubset,
SkIPoint* offset) const;
#endif

/** Defines a callback function, taking one parameter of type GrBackendTexture with
no return value. Function is called when back-end texture is to be released.
Expand Down
38 changes: 24 additions & 14 deletions src/image/SkImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,26 +348,24 @@ sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize&
std::move(colorSpace)));
}

sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
const SkIRect& clipBounds, SkIRect* outSubset,
SkIPoint* offset) const {
GrContext* context = as_IB(this)->context();

return this->makeWithFilter(context, filter, subset, clipBounds, outSubset, offset);
}
sk_sp<SkImage> SkImage::makeWithFilter(GrRecordingContext* rContext, const SkImageFilter* filter,
const SkIRect& subset, const SkIRect& clipBounds,
SkIRect* outSubset, SkIPoint* offset) const {

sk_sp<SkImage> SkImage::makeWithFilter(GrContext* grContext,
const SkImageFilter* filter, const SkIRect& subset,
const SkIRect& clipBounds, SkIRect* outSubset,
SkIPoint* offset) const {
if (!filter || !outSubset || !offset || !this->bounds().contains(subset)) {
return nullptr;
}
sk_sp<SkSpecialImage> srcSpecialImage =
sk_sp<SkSpecialImage> srcSpecialImage;
#if SK_SUPPORT_GPU
SkSpecialImage::MakeFromImage(grContext, subset, sk_ref_sp(const_cast<SkImage*>(this)));
auto myContext = as_IB(this)->context();
if (myContext && !myContext->priv().matches(rContext)) {
return nullptr;
}
srcSpecialImage = SkSpecialImage::MakeFromImage(rContext, subset,
sk_ref_sp(const_cast<SkImage*>(this)));
#else
SkSpecialImage::MakeFromImage(nullptr, subset, sk_ref_sp(const_cast<SkImage*>(this)));
srcSpecialImage = SkSpecialImage::MakeFromImage(nullptr, subset,
sk_ref_sp(const_cast<SkImage*>(this)));
#endif
if (!srcSpecialImage) {
return nullptr;
Expand Down Expand Up @@ -412,6 +410,18 @@ sk_sp<SkImage> SkImage::makeWithFilter(GrContext* grContext,
return result->asImage();
}

#ifdef SK_IMAGE_MAKE_WITH_FILTER_LEGACY_API
sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
const SkIRect& clipBounds, SkIRect* outSubset,
SkIPoint* offset) const {
GrRecordingContext* rContext = nullptr;
#if SK_SUPPORT_GPU
rContext = as_IB(this)->context();
#endif
return this->makeWithFilter(rContext, filter, subset, clipBounds, outSubset, offset);
}
#endif

bool SkImage::isLazyGenerated() const {
return as_IB(this)->onIsLazyGenerated();
}
Expand Down
Loading

0 comments on commit 247835b

Please sign in to comment.