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

Commit 2f69d6d4 authored by John Reck's avatar John Reck
Browse files

Support transform'd GraphicBuffers

Bug: 28428955
Change-Id: I23e2fc9b96a67c7cfda42d9d7319e478194a7fa7
parent f3a51d65
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -471,18 +471,19 @@ GlopBuilder& GlopBuilder::setFillTextureLayer(Layer& layer, float alpha) {
    return *this;
    return *this;
}
}


GlopBuilder& GlopBuilder::setFillExternalTexture(Texture& texture) {
GlopBuilder& GlopBuilder::setFillExternalTexture(Texture& texture, Matrix4& textureTransform) {
    TRIGGER_STAGE(kFillStage);
    TRIGGER_STAGE(kFillStage);
    REQUIRE_STAGES(kMeshStage | kRoundRectClipStage);
    REQUIRE_STAGES(kMeshStage | kRoundRectClipStage);


    mOutGlop->fill.texture = { &texture,
    mOutGlop->fill.texture = { &texture,
            GL_TEXTURE_EXTERNAL_OES, GL_LINEAR, GL_CLAMP_TO_EDGE,
            GL_TEXTURE_EXTERNAL_OES, GL_LINEAR, GL_CLAMP_TO_EDGE,
            nullptr };
            &textureTransform };


    setFill(SK_ColorWHITE, 1.0f, SkXfermode::kSrc_Mode, Blend::ModeOrderSwap::NoSwap,
    setFill(SK_ColorWHITE, 1.0f, SkXfermode::kSrc_Mode, Blend::ModeOrderSwap::NoSwap,
            nullptr, nullptr);
            nullptr, nullptr);


    mDescription.modulate = mOutGlop->fill.color.a < 1.0f;
    mDescription.modulate = mOutGlop->fill.color.a < 1.0f;
    mDescription.hasTextureTransform = true;
    return *this;
    return *this;
}
}


+1 −1
Original line number Original line Diff line number Diff line
@@ -73,7 +73,7 @@ public:
    // TODO: Texture should probably know and own its target.
    // TODO: Texture should probably know and own its target.
    // setFillLayer() forces it to GL_TEXTURE which isn't always correct.
    // setFillLayer() forces it to GL_TEXTURE which isn't always correct.
    // Similarly setFillLayer normally forces its own wrap & filter mode
    // Similarly setFillLayer normally forces its own wrap & filter mode
    GlopBuilder& setFillExternalTexture(Texture& texture);
    GlopBuilder& setFillExternalTexture(Texture& texture, Matrix4& textureTransform);


    GlopBuilder& setTransform(const Snapshot& snapshot, const int transformFlags) {
    GlopBuilder& setTransform(const Snapshot& snapshot, const int transformFlags) {
        return setTransform(*snapshot.transform, transformFlags);
        return setTransform(*snapshot.transform, transformFlags);
+2 −0
Original line number Original line Diff line number Diff line
@@ -236,6 +236,8 @@ public:


    static const Matrix4& identity();
    static const Matrix4& identity();


    void invalidateType() { mType = kTypeUnknown; }

private:
private:
    mutable uint8_t mType;
    mutable uint8_t mType;


+6 −3
Original line number Original line Diff line number Diff line
@@ -101,7 +101,10 @@ CopyResult Readback::copySurfaceInto(renderthread::RenderThread& renderThread,
    // Setup the source
    // Setup the source
    sp<GraphicBuffer> sourceBuffer;
    sp<GraphicBuffer> sourceBuffer;
    sp<Fence> sourceFence;
    sp<Fence> sourceFence;
    status_t err = surface.getLastQueuedBuffer(&sourceBuffer, &sourceFence);
    Matrix4 texTransform;
    status_t err = surface.getLastQueuedBuffer(&sourceBuffer, &sourceFence,
            texTransform.data);
    texTransform.invalidateType();
    if (err != NO_ERROR) {
    if (err != NO_ERROR) {
        ALOGW("Failed to get last queued buffer, error = %d", err);
        ALOGW("Failed to get last queued buffer, error = %d", err);
        return CopyResult::UnknownError;
        return CopyResult::UnknownError;
@@ -163,8 +166,8 @@ CopyResult Readback::copySurfaceInto(renderthread::RenderThread& renderThread,
        Glop glop;
        Glop glop;
        GlopBuilder(renderState, caches, &glop)
        GlopBuilder(renderState, caches, &glop)
                .setRoundRectClipState(nullptr)
                .setRoundRectClipState(nullptr)
                .setMeshTexturedUvQuad(nullptr, Rect(0, 1, 1, 0)) // TODO: simplify with VBO
                .setMeshTexturedUnitQuad(nullptr)
                .setFillExternalTexture(sourceTexture)
                .setFillExternalTexture(sourceTexture, texTransform)
                .setTransform(Matrix4::identity(), TransformFlags::None)
                .setTransform(Matrix4::identity(), TransformFlags::None)
                .setModelViewMapUnitToRect(destRect)
                .setModelViewMapUnitToRect(destRect)
                .build();
                .build();
+34 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Environment;
import android.view.Gravity;
import android.view.Gravity;
import android.view.PixelCopy;
import android.view.PixelCopy;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.SurfaceView;
import android.view.View;
import android.view.View;
@@ -87,9 +88,42 @@ public class GetBitmapSurfaceViewActivity extends Activity implements SurfaceHol
            android.util.Log.e("TextureView", "Cannot set preview texture target!", t);
            android.util.Log.e("TextureView", "Cannot set preview texture target!", t);
        }
        }


        setCameraDisplayOrientation(this, 0, mCamera);
        mCamera.startPreview();
        mCamera.startPreview();
    }
    }


    public static void setCameraDisplayOrientation(Activity activity,
            int cameraId, android.hardware.Camera camera) {
        android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
        android.hardware.Camera.getCameraInfo(cameraId, info);
        int rotation = activity.getWindowManager().getDefaultDisplay()
                .getRotation();
        int degrees = 0;
        switch (rotation) {
            case Surface.ROTATION_0:
                degrees = 0;
                break;
            case Surface.ROTATION_90:
                degrees = 90;
                break;
            case Surface.ROTATION_180:
                degrees = 180;
                break;
            case Surface.ROTATION_270:
                degrees = 270;
                break;
        }

        int result;
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            result = (info.orientation + degrees) % 360;
            result = (360 - result) % 360; // compensate the mirror
        } else { // back-facing
            result = (info.orientation - degrees + 360) % 360;
        }
        camera.setDisplayOrientation(result);
    }

    @Override
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    }
    }