summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author John Reck <jreck@google.com> 2020-11-12 12:37:30 -0500
committer John Reck <jreck@google.com> 2020-11-12 12:44:24 -0500
commit90b0a1cc20c91694816a325a45a4498acaf4e315 (patch)
tree486fe23b4a7737e0a5e67fddc35c5a62c7d22dc2
parent012eb24033608632b5eb5f73628da9486c650863 (diff)
Verify for_each is const
Test: this Change-Id: I7ffd755b4b762f7e8608cf84b328560783162439
-rw-r--r--libs/hwui/canvas/CanvasOpBuffer.h4
-rw-r--r--libs/hwui/canvas/CanvasOpRasterizer.cpp2
-rw-r--r--libs/hwui/canvas/OpBuffer.h2
-rw-r--r--libs/hwui/tests/unit/CanvasOpTests.cpp14
4 files changed, 20 insertions, 2 deletions
diff --git a/libs/hwui/canvas/CanvasOpBuffer.h b/libs/hwui/canvas/CanvasOpBuffer.h
index b80faeb1a65b..07e079a7d57f 100644
--- a/libs/hwui/canvas/CanvasOpBuffer.h
+++ b/libs/hwui/canvas/CanvasOpBuffer.h
@@ -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>;
diff --git a/libs/hwui/canvas/CanvasOpRasterizer.cpp b/libs/hwui/canvas/CanvasOpRasterizer.cpp
index 97c418a3e8d0..25129f641c00 100644
--- a/libs/hwui/canvas/CanvasOpRasterizer.cpp
+++ b/libs/hwui/canvas/CanvasOpRasterizer.cpp
@@ -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");
diff --git a/libs/hwui/canvas/OpBuffer.h b/libs/hwui/canvas/OpBuffer.h
index 398e090b8cfa..98e385f37a6e 100644
--- a/libs/hwui/canvas/OpBuffer.h
+++ b/libs/hwui/canvas/OpBuffer.h
@@ -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
diff --git a/libs/hwui/tests/unit/CanvasOpTests.cpp b/libs/hwui/tests/unit/CanvasOpTests.cpp
index c90d1a4f8cda..84fc6e6d508a 100644
--- a/libs/hwui/tests/unit/CanvasOpTests.cpp
+++ b/libs/hwui/tests/unit/CanvasOpTests.cpp
@@ -138,6 +138,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);