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

Commit 1db141f9 authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Create proxy between Skia's SkCanvas and the framework Canvas.

This enables Picture.java to be replayed into HWUI in addition
to extending the Skia testing suite to HWUI.

Bug: 19011232
Change-Id: Id27ac03eec817b0784763e62ab8413a07b3b8cb2
parent 728dace1
Loading
Loading
Loading
Loading
+0 −5
Original line number Original line Diff line number Diff line
@@ -122,11 +122,6 @@ public class Picture {
     * @param canvas  The picture is drawn to this canvas
     * @param canvas  The picture is drawn to this canvas
     */
     */
    public void draw(Canvas canvas) {
    public void draw(Canvas canvas) {
        if (canvas.isHardwareAccelerated()) {
            throw new IllegalArgumentException(
                    "Picture playback is only supported on software canvas.");
        }

        if (mRecordingCanvas != null) {
        if (mRecordingCanvas != null) {
            endRecording();
            endRecording();
        }
        }
+1 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ LOCAL_SRC_FILES := \
    ResourceCache.cpp \
    ResourceCache.cpp \
    ShadowTessellator.cpp \
    ShadowTessellator.cpp \
    SkiaCanvas.cpp \
    SkiaCanvas.cpp \
    SkiaCanvasProxy.cpp \
    SkiaShader.cpp \
    SkiaShader.cpp \
    Snapshot.cpp \
    Snapshot.cpp \
    SpotShadow.cpp \
    SpotShadow.cpp \
+8 −8
Original line number Original line Diff line number Diff line
@@ -42,14 +42,14 @@ public:
     */
     */
    static Canvas* create_canvas(SkCanvas* skiaCanvas);
    static Canvas* create_canvas(SkCanvas* skiaCanvas);


    // TODO: enable HWUI to either create similar canvas wrapper or subclass
    /**
    //       directly from Canvas
     *  Provides a Skia SkCanvas interface that acts as a proxy to this Canvas.
    //static Canvas* create_canvas(uirenderer::Renderer* renderer);
     *  It is useful for testing and clients (e.g. Picture/Movie) that expect to

     *  draw their contents into an SkCanvas.
    // TODO: this is a temporary affordance until all necessary logic can be
     *
    //       moved within this interface! Further, the return value should
     *  Further, the returned SkCanvas should NOT be unref'd and is valid until
    //       NOT be unref'd and is valid until this canvas is destroyed or a
     *  this canvas is destroyed or a new bitmap is set.
    //       new bitmap is set.
     */
    virtual SkCanvas* asSkCanvas() = 0;
    virtual SkCanvas* asSkCanvas() = 0;


    virtual void setBitmap(SkBitmap* bitmap, bool copyState) = 0;
    virtual void setBitmap(SkBitmap* bitmap, bool copyState) = 0;
+10 −0
Original line number Original line Diff line number Diff line
@@ -59,6 +59,7 @@ DisplayListData* DisplayListRenderer::finishRecording() {
    mPathMap.clear();
    mPathMap.clear();
    DisplayListData* data = mDisplayListData;
    DisplayListData* data = mDisplayListData;
    mDisplayListData = nullptr;
    mDisplayListData = nullptr;
    mSkiaCanvasProxy.reset(nullptr);
    return data;
    return data;
}
}


@@ -94,6 +95,15 @@ void DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
    mDisplayListData->functors.add(functor);
    mDisplayListData->functors.add(functor);
}
}


SkCanvas* DisplayListRenderer::asSkCanvas() {
    LOG_ALWAYS_FATAL_IF(!mDisplayListData,
            "attempting to get an SkCanvas when we are not recording!");
    if (!mSkiaCanvasProxy) {
        mSkiaCanvasProxy.reset(new SkiaCanvasProxy(this));
    }
    return mSkiaCanvasProxy.get();
}

int DisplayListRenderer::save(SkCanvas::SaveFlags flags) {
int DisplayListRenderer::save(SkCanvas::SaveFlags flags) {
    addStateOp(new (alloc()) SaveOp((int) flags));
    addStateOp(new (alloc()) SaveOp((int) flags));
    return mState.save((int) flags);
    return mState.save((int) flags);
+4 −4
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@
#include "Canvas.h"
#include "Canvas.h"
#include "CanvasState.h"
#include "CanvasState.h"
#include "DisplayList.h"
#include "DisplayList.h"
#include "SkiaCanvasProxy.h"
#include "RenderNode.h"
#include "RenderNode.h"
#include "Renderer.h"
#include "Renderer.h"
#include "ResourceCache.h"
#include "ResourceCache.h"
@@ -136,10 +137,8 @@ public:
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// android/graphics/Canvas interface
// android/graphics/Canvas interface
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
    virtual SkCanvas* asSkCanvas() override {
    virtual SkCanvas* asSkCanvas() override;
        LOG_ALWAYS_FATAL("DisplayListRenderer has no SkCanvas");

        return nullptr;
    }
    virtual void setBitmap(SkBitmap* bitmap, bool copyState) override {
    virtual void setBitmap(SkBitmap* bitmap, bool copyState) override {
        LOG_ALWAYS_FATAL("DisplayListRenderer is not backed by a bitmap.");
        LOG_ALWAYS_FATAL("DisplayListRenderer is not backed by a bitmap.");
    }
    }
@@ -244,6 +243,7 @@ public:
private:
private:


    CanvasState mState;
    CanvasState mState;
    std::unique_ptr<SkiaCanvasProxy> mSkiaCanvasProxy;


    enum DeferredBarrierType {
    enum DeferredBarrierType {
        kBarrier_None,
        kBarrier_None,
Loading