Add initial benchmarks for CanvasOp

Also some minor other tweaks

Test: this
Change-Id: Idb8a5955839893ff000de87d4899fd130ede061c
diff --git a/libs/hwui/tests/microbench/CanvasOpBench.cpp b/libs/hwui/tests/microbench/CanvasOpBench.cpp
new file mode 100644
index 0000000..ef5749e
--- /dev/null
+++ b/libs/hwui/tests/microbench/CanvasOpBench.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <benchmark/benchmark.h>
+
+#include "DisplayList.h"
+#include "hwui/Paint.h"
+#include "canvas/CanvasOpBuffer.h"
+#include "canvas/CanvasFrontend.h"
+#include "tests/common/TestUtils.h"
+
+using namespace android;
+using namespace android::uirenderer;
+
+void BM_CanvasOpBuffer_alloc(benchmark::State& benchState) {
+    while (benchState.KeepRunning()) {
+        auto displayList = new CanvasOpBuffer();
+        benchmark::DoNotOptimize(displayList);
+        delete displayList;
+    }
+}
+BENCHMARK(BM_CanvasOpBuffer_alloc);
+
+void BM_CanvasOpBuffer_record_saverestore(benchmark::State& benchState) {
+    CanvasFrontend<CanvasOpBuffer> canvas(100, 100);
+    while (benchState.KeepRunning()) {
+        canvas.reset(100, 100);
+        canvas.save(SaveFlags::MatrixClip);
+        canvas.save(SaveFlags::MatrixClip);
+        benchmark::DoNotOptimize(&canvas);
+        canvas.restore();
+        canvas.restore();
+        canvas.finish();
+    }
+}
+BENCHMARK(BM_CanvasOpBuffer_record_saverestore);
+
+void BM_CanvasOpBuffer_record_saverestoreWithReuse(benchmark::State& benchState) {
+    CanvasFrontend<CanvasOpBuffer> canvas(100, 100);
+
+    while (benchState.KeepRunning()) {
+        canvas.reset(100, 100);
+        canvas.save(SaveFlags::MatrixClip);
+        canvas.save(SaveFlags::MatrixClip);
+        benchmark::DoNotOptimize(&canvas);
+        canvas.restore();
+        canvas.restore();
+    }
+}
+BENCHMARK(BM_CanvasOpBuffer_record_saverestoreWithReuse);
+
+void BM_CanvasOpBuffer_record_simpleBitmapView(benchmark::State& benchState) {
+    CanvasFrontend<CanvasOpBuffer> canvas(100, 100);
+
+    Paint rectPaint;
+    sk_sp<Bitmap> iconBitmap(TestUtils::createBitmap(80, 80));
+
+    while (benchState.KeepRunning()) {
+        canvas.reset(100, 100);
+        {
+            canvas.save(SaveFlags::MatrixClip);
+            canvas.draw(CanvasOp<CanvasOpType::DrawRect> {
+                    .rect = SkRect::MakeWH(100, 100),
+                    .paint = rectPaint,
+            });
+            canvas.restore();
+        }
+        {
+            canvas.save(SaveFlags::MatrixClip);
+            canvas.translate(10, 10);
+            canvas.draw(CanvasOp<CanvasOpType::DrawImage> {
+                    iconBitmap,
+                    0,
+                    0,
+                    SkPaint{}
+            });
+            canvas.restore();
+        }
+        benchmark::DoNotOptimize(&canvas);
+        canvas.finish();
+    }
+}
+BENCHMARK(BM_CanvasOpBuffer_record_simpleBitmapView);
diff --git a/libs/hwui/tests/microbench/RenderNodeBench.cpp b/libs/hwui/tests/microbench/RenderNodeBench.cpp
index 206dcd5..011939a 100644
--- a/libs/hwui/tests/microbench/RenderNodeBench.cpp
+++ b/libs/hwui/tests/microbench/RenderNodeBench.cpp
@@ -30,3 +30,29 @@
     }
 }
 BENCHMARK(BM_RenderNode_create);
+
+void BM_RenderNode_recordSimple(benchmark::State& state) {
+    sp<RenderNode> node = new RenderNode();
+    std::unique_ptr<Canvas> canvas(Canvas::create_recording_canvas(100, 100));
+    delete canvas->finishRecording();
+
+    while (state.KeepRunning()) {
+        canvas->resetRecording(100, 100, node.get());
+        canvas->drawColor(0x00000000, SkBlendMode::kSrcOver);
+        node->setStagingDisplayList(canvas->finishRecording());
+    }
+}
+BENCHMARK(BM_RenderNode_recordSimple);
+
+void BM_RenderNode_recordSimpleWithReuse(benchmark::State& state) {
+    sp<RenderNode> node = new RenderNode();
+    std::unique_ptr<Canvas> canvas(Canvas::create_recording_canvas(100, 100));
+    delete canvas->finishRecording();
+
+    while (state.KeepRunning()) {
+        canvas->resetRecording(100, 100, node.get());
+        canvas->drawColor(0x00000000, SkBlendMode::kSrcOver);
+        canvas->finishRecording()->reuseDisplayList(node.get());
+    }
+}
+BENCHMARK(BM_RenderNode_recordSimpleWithReuse);
\ No newline at end of file
diff --git a/libs/hwui/tests/unit/SkiaDisplayListTests.cpp b/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
index 2d34b09..c63f008 100644
--- a/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
+++ b/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
@@ -84,7 +84,7 @@
 
     // attach a displayList for reuse
     SkiaDisplayList skiaDL;
-    ASSERT_TRUE(skiaDL.reuseDisplayList(renderNode.get(), nullptr));
+    ASSERT_TRUE(skiaDL.reuseDisplayList(renderNode.get()));
 
     // detach the list that you just attempted to reuse
     availableList = renderNode->detachAvailableList();