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

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

Merge "Verify for_each is const"

parents 42f01ac5 90b0a1cc
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -46,6 +46,10 @@ public:
    const SkMatrix& transform() const { return mTransform; }

    CanvasOp<T>* operator->() noexcept { return &mImpl; }
    const CanvasOp<T>* operator->() const noexcept { return &mImpl; }

    CanvasOp<T>& op() noexcept { return mImpl; }
    const CanvasOp<T>& op() const noexcept { return mImpl; }
};

extern template class OpBuffer<CanvasOpType, CanvasOpContainer>;
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ void rasterizeCanvasBuffer(const CanvasOpBuffer& source, SkCanvas* destination)
    std::vector<SkMatrix> globalMatrixStack;
    SkMatrix& currentGlobalTransform = globalMatrixStack.emplace_back(SkMatrix::I());

    source.for_each([&]<CanvasOpType T>(CanvasOpContainer<T> * op) {
    source.for_each([&]<CanvasOpType T>(const CanvasOpContainer<T> * op) {
        if constexpr (T == CanvasOpType::BeginZ || T == CanvasOpType::EndZ) {
            // Do beginZ or endZ
            LOG_ALWAYS_FATAL("TODO");
+1 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ private:
        using F_PTR = decltype(&f);
        using THUNK = void (*)(F_PTR, void*);
        static constexpr auto jump = std::array<THUNK, sizeof...(I)>{[](F_PTR fp, void* t) {
            (*fp)(reinterpret_cast<ItemContainer<static_cast<ItemTypes>(I)>*>(t));
            (*fp)(reinterpret_cast<const ItemContainer<static_cast<ItemTypes>(I)>*>(t));
        }...};

        // Do the actual iteration of each item
+14 −0
Original line number Diff line number Diff line
@@ -141,6 +141,20 @@ TEST(CanvasOp, lifecycleCheckMove) {
    EXPECT_EQ(tracker.alive(), 0);
}

TEST(CanvasOp, verifyConst) {
    CanvasOpBuffer buffer;
    buffer.push<Op::DrawColor>({
        .color = SkColors::kBlack,
        .mode = SkBlendMode::kSrcOver,
    });
    buffer.for_each([](auto op) {
        static_assert(std::is_const_v<std::remove_reference_t<decltype(*op)>>,
                "Expected container to be const");
        static_assert(std::is_const_v<std::remove_reference_t<decltype(op->op())>>,
                "Expected op to be const");
    });
}

TEST(CanvasOp, simplePush) {
    CanvasOpBuffer buffer;
    EXPECT_EQ(buffer.size(), 0);