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

Commit c29dffed authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Xform bitmaps to sRGB on SW and PDF canvases" into oc-dev

parents e002ce70 ea70d22d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ Canvas* Picture::beginRecording(int width, int height) {
    mWidth = width;
    mHeight = height;
    SkCanvas* canvas = mRecorder->beginRecording(SkIntToScalar(width), SkIntToScalar(height));
    return Canvas::create_canvas(canvas);
    return Canvas::create_canvas(canvas, Canvas::XformToSRGB::kDefer);
}

void Picture::endRecording() {
+5 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@

#include "CreateJavaOutputStreamAdaptor.h"

#include "SkColorSpaceXformCanvas.h"
#include "SkDocument.h"
#include "SkPicture.h"
#include "SkPictureRecorder.h"
@@ -94,8 +95,10 @@ public:

            SkCanvas* canvas = document->beginPage(page->mWidth, page->mHeight,
                    &(page->mContentRect));
            std::unique_ptr<SkCanvas> toSRGBCanvas =
                    SkCreateColorSpaceXformCanvas(canvas, SkColorSpace::MakeSRGB());

            canvas->drawPicture(page->mPicture);
            toSRGBCanvas->drawPicture(page->mPicture);

            document->endPage();
        }
@@ -128,7 +131,7 @@ static jlong nativeStartPage(JNIEnv* env, jobject thiz, jlong documentPtr,
    PdfDocument* document = reinterpret_cast<PdfDocument*>(documentPtr);
    SkCanvas* canvas = document->startPage(pageWidth, pageHeight,
            contentLeft, contentTop, contentRight, contentBottom);
    return reinterpret_cast<jlong>(Canvas::create_canvas(canvas));
    return reinterpret_cast<jlong>(Canvas::create_canvas(canvas, Canvas::XformToSRGB::kDefer));
}

static void nativeFinishPage(JNIEnv* env, jobject thiz, jlong documentPtr) {
+18 −10
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "hwui/MinikinUtils.h"
#include "pipeline/skia/AnimatedDrawables.h"

#include <SkColorSpaceXformCanvas.h>
#include <SkDrawable.h>
#include <SkDeque.h>
#include <SkDrawFilter.h>
@@ -44,18 +45,22 @@ Canvas* Canvas::create_canvas(const SkBitmap& bitmap) {
    return new SkiaCanvas(bitmap);
}

Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas) {
    return new SkiaCanvas(skiaCanvas);
Canvas* Canvas::create_canvas(SkCanvas* skiaCanvas, XformToSRGB xformToSRGB) {
    return new SkiaCanvas(skiaCanvas, xformToSRGB);
}

SkiaCanvas::SkiaCanvas() {}

SkiaCanvas::SkiaCanvas(SkCanvas* canvas)
    : mCanvas(canvas) {}
SkiaCanvas::SkiaCanvas(SkCanvas* canvas, XformToSRGB xformToSRGB)
    : mCanvas(canvas)
{
    LOG_ALWAYS_FATAL_IF(XformToSRGB::kImmediate == xformToSRGB);
}

SkiaCanvas::SkiaCanvas(const SkBitmap& bitmap) {
    mCanvasOwned = std::unique_ptr<SkCanvas>(new SkCanvas(bitmap));
    mCanvas = mCanvasOwned.get();
    mCanvasWrapper = SkCreateColorSpaceXformCanvas(mCanvasOwned.get(), SkColorSpace::MakeSRGB());
    mCanvas = mCanvasWrapper.get();
}

SkiaCanvas::~SkiaCanvas() {}
@@ -92,19 +97,22 @@ private:
};

void SkiaCanvas::setBitmap(const SkBitmap& bitmap) {
    SkCanvas* newCanvas = new SkCanvas(bitmap);
    std::unique_ptr<SkCanvas> newCanvas = std::unique_ptr<SkCanvas>(new SkCanvas(bitmap));
    std::unique_ptr<SkCanvas> newCanvasWrapper =
            SkCreateColorSpaceXformCanvas(newCanvas.get(), SkColorSpace::MakeSRGB());

    if (!bitmap.isNull()) {
        // Copy the canvas matrix & clip state.
        newCanvas->setMatrix(mCanvas->getTotalMatrix());
        newCanvasWrapper->setMatrix(mCanvas->getTotalMatrix());

        ClipCopier copier(newCanvas);
        ClipCopier copier(newCanvasWrapper.get());
        mCanvas->replayClips(&copier);
    }

    // deletes the previously owned canvas (if any)
    mCanvasOwned = std::unique_ptr<SkCanvas>(newCanvas);
    mCanvas = newCanvas;
    mCanvasOwned = std::move(newCanvas);
    mCanvasWrapper = std::move(newCanvasWrapper);
    mCanvas = mCanvasWrapper.get();

    // clean up the old save stack
    mSaveStack.reset(nullptr);
+6 −1
Original line number Diff line number Diff line
@@ -37,8 +37,12 @@ public:
     *  @param canvas SkCanvas to handle calls made to this SkiaCanvas. Must
     *      not be NULL. This constructor does not take ownership, so the caller
     *      must guarantee that it remains valid while the SkiaCanvas is valid.
     *  @param xformToSRGB Indicates if bitmaps should be xformed to the sRGB
     *      color space before drawing.  This makes sense for software rendering.
     *      For the picture case, it may make more sense to leave bitmaps as is,
     *      and handle the xform when replaying the picture.
     */
    explicit SkiaCanvas(SkCanvas* canvas);
    explicit SkiaCanvas(SkCanvas* canvas, XformToSRGB xformToSRGB);

    virtual ~SkiaCanvas();

@@ -181,6 +185,7 @@ private:

    class Clip;

    std::unique_ptr<SkCanvas> mCanvasWrapper; // might own a wrapper on the canvas
    std::unique_ptr<SkCanvas> mCanvasOwned; // might own a canvas we allocated
    SkCanvas*                 mCanvas;    // we do NOT own this canvas, it must survive us
                                          // unless it is the same as mCanvasOwned.get()
+12 −1
Original line number Diff line number Diff line
@@ -93,6 +93,15 @@ public:
    static WARN_UNUSED_RESULT Canvas* create_recording_canvas(int width, int height,
            uirenderer::RenderNode* renderNode = nullptr);

    enum class XformToSRGB {
        // Transform any Bitmaps to the sRGB color space before drawing.
        kImmediate,

        // Draw the Bitmap as is.  This likely means that we are recording and that the
        // transform can be handled at playback time.
        kDefer,
    };

    /**
     *  Create a new Canvas object which delegates to an SkCanvas.
     *
@@ -100,10 +109,12 @@ public:
     *      delegated to this object. This function will call ref() on the
     *      SkCanvas, and the returned Canvas will unref() it upon
     *      destruction.
     *  @param xformToSRGB Indicates if bitmaps should be xformed to the sRGB
     *      color space before drawing.
     *  @return new non-null Canvas Object.  The type of DisplayList produced by this canvas is
     *      determined based on  Properties::getRenderPipelineType().
     */
    static Canvas* create_canvas(SkCanvas* skiaCanvas);
    static Canvas* create_canvas(SkCanvas* skiaCanvas, XformToSRGB xformToSRGB);

    /**
     *  Provides a Skia SkCanvas interface that acts as a proxy to this Canvas.
Loading