Image filters: refactor input GPU processing into filterInputGPU().

(analog of CPU version here: https://codereview.chromium.org/1404743005/)

No change in behaviour; this is a straight refactoring.

BUG=skia:3194

Review URL: https://codereview.chromium.org/1393283008
This commit is contained in:
senorblanco 2015-10-16 11:35:14 -07:00 committed by Commit bot
parent 80803ff615
commit 9a70b6ef59
7 changed files with 26 additions and 29 deletions

View File

@ -248,11 +248,13 @@ public:
*/
static void WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result);
/**
* Recursively evaluate this filter on the GPU. If the filter has no GPU
* implementation, it will be processed in software and uploaded to the GPU.
*/
bool getInputResultGPU(SkImageFilter::Proxy* proxy, const SkBitmap& src, const Context&,
// Helper function which invokes GPU filter processing on the
// input at the specified "index". If the input is null, it leaves
// "result" and "offset" untouched, and returns true. If the input
// has a GPU implementation, it will be invoked directly.
// Otherwise, the filter will be processed in software and
// uploaded to the GPU.
bool filterInputGPU(int index, SkImageFilter::Proxy* proxy, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const;
#endif

View File

@ -329,8 +329,7 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Cont
SkBitmap input = src;
SkASSERT(fInputCount == 1);
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (this->getInput(0) &&
!this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) {
return false;
}
GrTexture* srcTexture = input.getTexture();
@ -466,18 +465,22 @@ void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBit
result->setPixelRef(new SkGrPixelRef(info, texture))->unref();
}
bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy,
bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy,
const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
SkImageFilter* input = this->getInput(index);
if (!input) {
return true;
}
// Ensure that GrContext calls under filterImage and filterImageGPU below will see an identity
// matrix with no clip and that the matrix, clip, and render target set before this function was
// called are restored before we return to the caller.
GrContext* context = src.getTexture()->getContext();
if (this->canFilterImageGPU()) {
return this->filterImageGPU(proxy, src, ctx, result, offset);
if (input->canFilterImageGPU()) {
return input->filterImageGPU(proxy, src, ctx, result, offset);
} else {
if (this->filterImage(proxy, src, ctx, result, offset)) {
if (input->filterImage(proxy, src, ctx, result, offset)) {
if (!result->getTexture()) {
const SkImageInfo info = result->info();
if (kUnknown_SkColorType == info.colorType()) {

View File

@ -194,8 +194,7 @@ bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
#if SK_SUPPORT_GPU
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (this->getInput(0) &&
!this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) {
return false;
}
SkIRect rect;

View File

@ -384,15 +384,12 @@ bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
SkBitmap* result, SkIPoint* offset) const {
SkBitmap colorBM = src;
SkIPoint colorOffset = SkIPoint::Make(0, 0);
if (this->getColorInput() &&
!this->getColorInput()->getInputResultGPU(proxy, src, ctx, &colorBM, &colorOffset)) {
if (!this->filterInputGPU(1, proxy, src, ctx, &colorBM, &colorOffset)) {
return false;
}
SkBitmap displacementBM = src;
SkIPoint displacementOffset = SkIPoint::Make(0, 0);
if (this->getDisplacementInput() &&
!this->getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displacementBM,
&displacementOffset)) {
if (!this->filterInputGPU(0, proxy, src, ctx, &displacementBM, &displacementOffset)) {
return false;
}
SkIRect bounds;

View File

@ -361,8 +361,7 @@ bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy,
SkIPoint* offset) const {
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (this->getInput(0) &&
!this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) {
return false;
}
SkIRect bounds;

View File

@ -612,8 +612,7 @@ bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate,
SkIPoint* offset) const {
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (this->getInput(0) &&
!this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) {
return false;
}
SkIRect bounds;

View File

@ -130,8 +130,7 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
SkIPoint* offset) const {
SkBitmap background = src;
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
if (this->getInput(0) &&
!this->getInput(0)->getInputResultGPU(proxy, src, ctx, &background, &backgroundOffset)) {
if (!this->filterInputGPU(0, proxy, src, ctx, &background, &backgroundOffset)) {
return false;
}
@ -143,8 +142,7 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
SkBitmap foreground = src;
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
if (this->getInput(1) &&
!this->getInput(1)->getInputResultGPU(proxy, src, ctx, &foreground, &foregroundOffset)) {
if (!this->filterInputGPU(1, proxy, src, ctx, &foreground, &foregroundOffset)) {
return false;
}
GrTexture* foregroundTex = foreground.getTexture();