static void apply_morphology_pass(GrDrawContext* drawContext, const GrClip& clip, GrTexture* texture, const SkIRect& srcRect, const SkIRect& dstRect, int radius, GrMorphologyEffect::MorphologyType morphType, Gr1DKernelEffect::Direction direction) { float bounds[2] = { 0.0f, 1.0f }; SkIRect lowerSrcRect = srcRect, lowerDstRect = dstRect; SkIRect middleSrcRect = srcRect, middleDstRect = dstRect; SkIRect upperSrcRect = srcRect, upperDstRect = dstRect; if (direction == Gr1DKernelEffect::kX_Direction) { bounds[0] = (SkIntToScalar(srcRect.left()) + 0.5f) / texture->width(); bounds[1] = (SkIntToScalar(srcRect.right()) - 0.5f) / texture->width(); lowerSrcRect.fRight = srcRect.left() + radius; lowerDstRect.fRight = dstRect.left() + radius; upperSrcRect.fLeft = srcRect.right() - radius; upperDstRect.fLeft = dstRect.right() - radius; middleSrcRect.inset(radius, 0); middleDstRect.inset(radius, 0); } else { bounds[0] = (SkIntToScalar(srcRect.top()) + 0.5f) / texture->height(); bounds[1] = (SkIntToScalar(srcRect.bottom()) - 0.5f) / texture->height(); lowerSrcRect.fBottom = srcRect.top() + radius; lowerDstRect.fBottom = dstRect.top() + radius; upperSrcRect.fTop = srcRect.bottom() - radius; upperDstRect.fTop = dstRect.bottom() - radius; middleSrcRect.inset(0, radius); middleDstRect.inset(0, radius); } if (middleSrcRect.fLeft - middleSrcRect.fRight >= 0) { // radius covers srcRect; use bounds over entire draw apply_morphology_rect(drawContext, clip, texture, srcRect, dstRect, radius, morphType, bounds, direction); } else { // Draw upper and lower margins with bounds; middle without. apply_morphology_rect(drawContext, clip, texture, lowerSrcRect, lowerDstRect, radius, morphType, bounds, direction); apply_morphology_rect(drawContext, clip, texture, upperSrcRect, upperDstRect, radius, morphType, bounds, direction); apply_morphology_rect_no_bounds(drawContext, clip, texture, middleSrcRect, middleDstRect, radius, morphType, direction); } }
static void apply_morphology_pass(GrRenderTargetContext* renderTargetContext, const GrClip& clip, sk_sp<GrTextureProxy> textureProxy, const SkIRect& srcRect, const SkIRect& dstRect, int radius, GrMorphologyEffect::Type morphType, GrMorphologyEffect::Direction direction) { float bounds[2] = { 0.0f, 1.0f }; SkIRect lowerSrcRect = srcRect, lowerDstRect = dstRect; SkIRect middleSrcRect = srcRect, middleDstRect = dstRect; SkIRect upperSrcRect = srcRect, upperDstRect = dstRect; if (direction == GrMorphologyEffect::Direction::kX) { bounds[0] = SkIntToScalar(srcRect.left()) + 0.5f; bounds[1] = SkIntToScalar(srcRect.right()) - 0.5f; lowerSrcRect.fRight = srcRect.left() + radius; lowerDstRect.fRight = dstRect.left() + radius; upperSrcRect.fLeft = srcRect.right() - radius; upperDstRect.fLeft = dstRect.right() - radius; middleSrcRect.inset(radius, 0); middleDstRect.inset(radius, 0); } else { bounds[0] = SkIntToScalar(srcRect.top()) + 0.5f; bounds[1] = SkIntToScalar(srcRect.bottom()) - 0.5f; lowerSrcRect.fBottom = srcRect.top() + radius; lowerDstRect.fBottom = dstRect.top() + radius; upperSrcRect.fTop = srcRect.bottom() - radius; upperDstRect.fTop = dstRect.bottom() - radius; middleSrcRect.inset(0, radius); middleDstRect.inset(0, radius); } if (middleSrcRect.width() <= 0) { // radius covers srcRect; use bounds over entire draw apply_morphology_rect(renderTargetContext, clip, std::move(textureProxy), srcRect, dstRect, radius, morphType, bounds, direction); } else { // Draw upper and lower margins with bounds; middle without. apply_morphology_rect(renderTargetContext, clip, textureProxy, lowerSrcRect, lowerDstRect, radius, morphType, bounds, direction); apply_morphology_rect(renderTargetContext, clip, textureProxy, upperSrcRect, upperDstRect, radius, morphType, bounds, direction); apply_morphology_rect_no_bounds(renderTargetContext, clip, std::move(textureProxy), middleSrcRect, middleDstRect, radius, morphType, direction); } }