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

Commit 4170db32 authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Fix CtsViewTestCases when running on swiftshader emulators.

Test: CtsViewTestCases
Bug: 64478761
Change-Id: Ie85d25054c2f426cc88cf512c166c175b894a8fe
parent 6335b6ee
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -134,9 +134,24 @@ bool SkiaOpenGLPipeline::copyLayerInto(DeferredLayerUpdater* deferredLayer, SkBi
    deferredLayer->updateTexImage();
    deferredLayer->apply();

    SkCanvas canvas(*bitmap);
    /* This intermediate surface is present to work around a bug in SwiftShader that
     * prevents us from reading the contents of the layer's texture directly. The
     * workaround involves first rendering that texture into an intermediate buffer and
     * then reading from the intermediate buffer into the bitmap.
     */
    sk_sp<SkSurface> tmpSurface = SkSurface::MakeRenderTarget(mRenderThread.getGrContext(),
            SkBudgeted::kYes, bitmap->info());

    Layer* layer = deferredLayer->backingLayer();
    return LayerDrawable::DrawLayer(mRenderThread.getGrContext(), &canvas, layer);
    if (LayerDrawable::DrawLayer(mRenderThread.getGrContext(), tmpSurface->getCanvas(), layer)) {
        sk_sp<SkImage> tmpImage = tmpSurface->makeImageSnapshot();
        if (tmpImage->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0)) {
            bitmap->notifyPixelsChanged();
            return true;
        }
    }

    return false;
}

static Layer* createLayer(RenderState& renderState, uint32_t layerWidth, uint32_t layerHeight,
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include "SkiaOpenGLReadback.h"

#include "DeviceInfo.h"
#include "Matrix.h"
#include "Properties.h"
#include <SkCanvas.h>
@@ -65,6 +66,18 @@ CopyResult SkiaOpenGLReadback::copyImageInto(EGLImageKHR eglImage, const Matrix4
        break;
    }

    /* Ideally, we would call grContext->caps()->isConfigRenderable(...). We
     * currently can't do that since some devices (i.e. SwiftShader) supports all
     * the appropriate half float extensions, but only allow the buffer to be read
     * back as full floats.  We can relax this extension if Skia implements support
     * for reading back float buffers (skbug.com/6945).
     */
    if (pixelConfig == kRGBA_half_GrPixelConfig &&
            !DeviceInfo::get()->extensions().hasFloatTextures()) {
        ALOGW("Can't copy surface into bitmap, RGBA_F16 config is not supported");
        return CopyResult::DestinationInvalid;
    }

    GrBackendTexture backendTexture(imgWidth, imgHeight, pixelConfig, externalTexture);

    CopyResult copyResult = CopyResult::UnknownError;