Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e17fc7af authored by Greg Daniel's avatar Greg Daniel Committed by Android (Google) Code Review
Browse files

Merge "Move uses of SkSurface::makeImageSnapshot to makeTemporaryImage." into main

parents 8d8cb623 cfdc5b65
Loading
Loading
Loading
Loading
+25 −12
Original line number Diff line number Diff line
@@ -838,8 +838,7 @@ void SkiaRenderEngine::drawLayersInternal(
            LOG_ALWAYS_FATAL_IF(activeSurface == dstSurface);
            LOG_ALWAYS_FATAL_IF(canvas == dstCanvas);

            // save a snapshot of the activeSurface to use as input to the blur shaders
            blurInput = activeSurface->makeImageSnapshot();
            blurInput = activeSurface->makeTemporaryImage();

            // blit the offscreen framebuffer into the destination AHB. This ensures that
            // even if the blurred image does not cover the screen (for example, during
@@ -853,12 +852,9 @@ void SkiaRenderEngine::drawLayersInternal(
                    dstCanvas->drawAnnotation(SkRect::Make(dstCanvas->imageInfo().dimensions()),
                                              String8::format("SurfaceID|%" PRId64, id).c_str(),
                                              nullptr);
                    dstCanvas->drawImage(blurInput, 0, 0, SkSamplingOptions(), &paint);
                } else {
                    activeSurface->draw(dstCanvas, 0, 0, SkSamplingOptions(), &paint);
                }
                dstCanvas->drawImage(blurInput, 0, 0, SkSamplingOptions(), &paint);
            }

            // assign dstCanvas to canvas and ensure that the canvas state is up to date
            canvas = dstCanvas;
            surfaceAutoSaveRestore.replace(canvas);
@@ -891,12 +887,6 @@ void SkiaRenderEngine::drawLayersInternal(
        if (mBlurFilter && layerHasBlur(layer, ctModifiesAlpha)) {
            std::unordered_map<uint32_t, sk_sp<SkImage>> cachedBlurs;

            // if multiple layers have blur, then we need to take a snapshot now because
            // only the lowest layer will have blurImage populated earlier
            if (!blurInput) {
                blurInput = activeSurface->makeImageSnapshot();
            }

            // rect to be blurred in the coordinate space of blurInput
            SkRect blurRect = canvas->getTotalMatrix().mapRect(bounds.rect());

@@ -920,6 +910,29 @@ void SkiaRenderEngine::drawLayersInternal(

            // TODO(b/182216890): Filter out empty layers earlier
            if (blurRect.width() > 0 && blurRect.height() > 0) {
                // if multiple layers have blur, then we need to take a snapshot now because
                // only the lowest layer will have blurImage populated earlier
                if (!blurInput) {
                    bool requiresCrossFadeWithBlurInput = false;
                    if (layer.backgroundBlurRadius > 0 &&
                        layer.backgroundBlurRadius < mBlurFilter->getMaxCrossFadeRadius()) {
                        requiresCrossFadeWithBlurInput = true;
                    }
                    for (auto region : layer.blurRegions) {
                        if (region.blurRadius < mBlurFilter->getMaxCrossFadeRadius()) {
                            requiresCrossFadeWithBlurInput = true;
                        }
                    }
                    if (requiresCrossFadeWithBlurInput) {
                        // If we require cross fading with the blur input, we need to make sure we
                        // make a copy of the surface to the image since we will be writing to the
                        // surface while sampling the blurInput.
                        blurInput = activeSurface->makeImageSnapshot();
                    } else {
                        blurInput = activeSurface->makeTemporaryImage();
                    }
                }

                if (layer.backgroundBlurRadius > 0) {
                    SFTRACE_NAME("BackgroundBlur");
                    auto blurredImage = mBlurFilter->generate(context, layer.backgroundBlurRadius,
+2 −0
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@ void BlurFilter::drawBlurRegion(SkCanvas* canvas, const SkRRect& effectRegion,
                                                     linearSampling, &blurMatrix);

    if (blurRadius < mMaxCrossFadeRadius) {
        LOG_ALWAYS_FATAL_IF(!input);

        // For sampling Skia's API expects the inverse of what logically seems appropriate. In this
        // case you might expect the matrix to simply be the canvas matrix.
        SkMatrix inputMatrix;
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ sk_sp<SkImage> GaussianBlurFilter::generate(SkiaGpuContext* context, const uint3
            SkSamplingOptions{SkFilterMode::kLinear, SkMipmapMode::kNone},
            &paint,
            SkCanvas::SrcRectConstraint::kFast_SrcRectConstraint);
    return surface->makeImageSnapshot();
    return surface->makeTemporaryImage();
}

} // namespace skia
+3 −3
Original line number Diff line number Diff line
@@ -167,14 +167,14 @@ sk_sp<SkImage> KawaseBlurDualFilter::generate(SkiaGpuContext* context, const uin
    }
    // Next the remaining downscale blur passes.
    for (int i = 0; i < filterPasses; i++) {
        blurInto(surfaces[i + 1], surfaces[i]->makeImageSnapshot(), kWeights[1 + i] * step, 1.0f);
        blurInto(surfaces[i + 1], surfaces[i]->makeTemporaryImage(), kWeights[1 + i] * step, 1.0f);
    }
    // Finally blur+upscale back to our original size.
    for (int i = filterPasses - 1; i >= 0; i--) {
        blurInto(surfaces[i], surfaces[i + 1]->makeImageSnapshot(), kWeights[4 - i] * step,
        blurInto(surfaces[i], surfaces[i + 1]->makeTemporaryImage(), kWeights[4 - i] * step,
                 std::min(1.0f, filterDepth - i));
    }
    return surfaces[0]->makeImageSnapshot();
    return surfaces[0]->makeTemporaryImage();
}

} // namespace skia
+1 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ static sk_sp<SkImage> makeImage(SkSurface* surface, SkRuntimeShaderBuilder* buil
    paint.setShader(std::move(shader));
    paint.setBlendMode(SkBlendMode::kSrc);
    surface->getCanvas()->drawPaint(paint);
    return surface->makeImageSnapshot();
    return surface->makeTemporaryImage();
}

sk_sp<SkImage> KawaseBlurFilter::generate(SkiaGpuContext* context, const uint32_t blurRadius,
Loading