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

Commit 8750eebf authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "Support auto-dark for VectorDrawable"

parents 6ed6cedd 08ee8156
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ static jboolean setRootAlpha(JNIEnv*, jobject, jlong treePtr, jfloat alpha) {

static jfloat getRootAlpha(JNIEnv*, jobject, jlong treePtr) {
    VectorDrawable::Tree* tree = reinterpret_cast<VectorDrawable::Tree*>(treePtr);
    return tree->stagingProperties()->getRootAlpha();
    return tree->stagingProperties().getRootAlpha();
}

static void updateFullPathPropertiesAndStrokeStyles(JNIEnv*, jobject, jlong fullPathPtr,
+17 −1
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ static void applyColorTransform(ColorTransform transform, SkPaint& paint) {
        info.fColors = _colorStorage.data();
        info.fColorOffsets = _offsetStorage.data();
        SkShader::GradientType type = paint.getShader()->asAGradient(&info);
        ALOGW_IF(type, "Found gradient of type = %d", type);

        if (info.fColorCount <= 10) {
            switch (type) {
@@ -108,6 +107,22 @@ static void applyColorTransform(ColorTransform transform, SkPaint& paint) {
    }
}

static BitmapPalette paletteForColorHSV(SkColor color) {
    float hsv[3];
    SkColorToHSV(color, hsv);
    return hsv[2] >= .5f ? BitmapPalette::Light : BitmapPalette::Dark;
}

static BitmapPalette filterPalette(const SkPaint* paint, BitmapPalette palette) {
    if (palette == BitmapPalette::Unknown || !paint || !paint->getColorFilter()) {
        return palette;
    }

    SkColor color = palette == BitmapPalette::Light ? SK_ColorWHITE : SK_ColorBLACK;
    color = paint->getColorFilter()->filterColor(color);
    return paletteForColorHSV(color);
}

bool transformPaint(ColorTransform transform, SkPaint* paint) {
    // TODO
    applyColorTransform(transform, *paint);
@@ -115,6 +130,7 @@ bool transformPaint(ColorTransform transform, SkPaint* paint) {
}

bool transformPaint(ColorTransform transform, SkPaint* paint, BitmapPalette palette) {
    palette = filterPalette(paint, palette);
    bool shouldInvert = false;
    if (palette == BitmapPalette::Light && transform == ColorTransform::Dark) {
        shouldInvert = true;
+2 −1
Original line number Diff line number Diff line
@@ -50,3 +50,4 @@ X(DrawPoints)
X(DrawVertices) 
X(DrawAtlas) 
X(DrawShadowRec)
X(DrawVectorDrawable)
 No newline at end of file
+30 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#include "RecordingCanvas.h"

#include "VectorDrawable.h"

#include "SkCanvas.h"
#include "SkData.h"
#include "SkDrawShadowInfo.h"
@@ -498,6 +500,27 @@ struct DrawShadowRec final : Op {
    SkDrawShadowRec fRec;
    void draw(SkCanvas* c, const SkMatrix&) const { c->private_draw_shadow_rec(fPath, fRec); }
};

struct DrawVectorDrawable final : Op {
    static const auto kType = Type::DrawVectorDrawable;
    DrawVectorDrawable(VectorDrawableRoot* tree)
            : mRoot(tree)
            , mBounds(tree->stagingProperties().getBounds())
            , palette(tree->computePalette()) {
        // Recording, so use staging properties
        tree->getPaintFor(&paint, tree->stagingProperties());
    }

    void draw(SkCanvas* canvas, const SkMatrix&) const {
        mRoot->draw(canvas, mBounds, paint);
    }

    sp<VectorDrawableRoot> mRoot;
    SkRect mBounds;
    SkPaint paint;
    BitmapPalette palette;
};

}

template <typename T, typename... Args>
@@ -698,6 +721,9 @@ void DisplayListData::drawAtlas(const SkImage* atlas, const SkRSXform xforms[],
void DisplayListData::drawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
    this->push<DrawShadowRec>(0, path, rec);
}
void DisplayListData::drawVectorDrawable(VectorDrawableRoot* tree) {
    this->push<DrawVectorDrawable>(0, tree);
}

typedef void (*draw_fn)(const void*, SkCanvas*, const SkMatrix&);
typedef void (*void_fn)(const void*);
@@ -962,5 +988,9 @@ void RecordingCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec&
    fDL->drawShadowRec(path, rec);
}

void RecordingCanvas::drawVectorDrawable(VectorDrawableRoot* tree) {
    fDL->drawVectorDrawable(tree);
}

};  // namespace uirenderer
};  // namespace android
+3 −0
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ private:
    void drawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int,
                   SkBlendMode, const SkRect*, const SkPaint*);
    void drawShadowRec(const SkPath&, const SkDrawShadowRec&);
    void drawVectorDrawable(VectorDrawableRoot* tree);

    template <typename T, typename... Args>
    void* push(size_t, Args&&...);
@@ -205,6 +206,8 @@ public:
                     SkBlendMode, const SkRect*, const SkPaint*) override;
    void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;

    void drawVectorDrawable(VectorDrawableRoot* tree);

private:
    typedef SkCanvasVirtualEnforcer<SkNoDrawCanvas> INHERITED;

Loading