Verify for_each is const

Test: this
Change-Id: I7ffd755b4b762f7e8608cf84b328560783162439
diff --git a/libs/hwui/canvas/CanvasOpBuffer.h b/libs/hwui/canvas/CanvasOpBuffer.h
index b80faeb..07e079a 100644
--- a/libs/hwui/canvas/CanvasOpBuffer.h
+++ b/libs/hwui/canvas/CanvasOpBuffer.h
@@ -46,6 +46,10 @@
     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>;
diff --git a/libs/hwui/canvas/CanvasOpRasterizer.cpp b/libs/hwui/canvas/CanvasOpRasterizer.cpp
index 97c418a..25129f6 100644
--- a/libs/hwui/canvas/CanvasOpRasterizer.cpp
+++ b/libs/hwui/canvas/CanvasOpRasterizer.cpp
@@ -32,7 +32,7 @@
     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");
diff --git a/libs/hwui/canvas/OpBuffer.h b/libs/hwui/canvas/OpBuffer.h
index 398e090..98e385f 100644
--- a/libs/hwui/canvas/OpBuffer.h
+++ b/libs/hwui/canvas/OpBuffer.h
@@ -156,7 +156,7 @@
         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
diff --git a/libs/hwui/tests/unit/CanvasOpTests.cpp b/libs/hwui/tests/unit/CanvasOpTests.cpp
index c90d1a4..84fc6e6 100644
--- a/libs/hwui/tests/unit/CanvasOpTests.cpp
+++ b/libs/hwui/tests/unit/CanvasOpTests.cpp
@@ -138,6 +138,20 @@
     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);