14a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck/* 24a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * Copyright (C) 2015 The Android Open Source Project 34a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * 44a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * Licensed under the Apache License, Version 2.0 (the "License"); 54a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * you may not use this file except in compliance with the License. 64a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * You may obtain a copy of the License at 74a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * 84a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * http://www.apache.org/licenses/LICENSE-2.0 94a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * 104a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * Unless required by applicable law or agreed to in writing, software 114a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * distributed under the License is distributed on an "AS IS" BASIS, 124a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * See the License for the specific language governing permissions and 144a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck * limitations under the License. 154a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck */ 164a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 170418afa362630e69bd853121770b115750ee46a4John Reck#include <benchmark/benchmark.h> 184a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 194a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck#include "DisplayList.h" 20b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craik#if HWUI_NEW_OPS 21b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craik#include "RecordingCanvas.h" 22b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craik#else 234a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck#include "DisplayListCanvas.h" 24b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craik#endif 258160f20b0aca8c6595d4b385d673f59b6bcd16a4Chris Craik#include "tests/common/TestUtils.h" 264a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 274a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reckusing namespace android; 284a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reckusing namespace android::uirenderer; 294a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 30b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craik#if HWUI_NEW_OPS 31b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craiktypedef RecordingCanvas TestCanvas; 32b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craik#else 33b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craiktypedef DisplayListCanvas TestCanvas; 34b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craik#endif 35b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craik 360418afa362630e69bd853121770b115750ee46a4John Reckvoid BM_DisplayList_alloc(benchmark::State& benchState) { 370418afa362630e69bd853121770b115750ee46a4John Reck while (benchState.KeepRunning()) { 38003cc3dec8e2a92e51086fbcd5ee1bb236efa701Chris Craik auto displayList = new DisplayList(); 390418afa362630e69bd853121770b115750ee46a4John Reck benchmark::DoNotOptimize(displayList); 40003cc3dec8e2a92e51086fbcd5ee1bb236efa701Chris Craik delete displayList; 414a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck } 424a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck} 430418afa362630e69bd853121770b115750ee46a4John ReckBENCHMARK(BM_DisplayList_alloc); 444a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 450418afa362630e69bd853121770b115750ee46a4John Reckvoid BM_DisplayList_alloc_theoretical(benchmark::State& benchState) { 460418afa362630e69bd853121770b115750ee46a4John Reck while (benchState.KeepRunning()) { 47003cc3dec8e2a92e51086fbcd5ee1bb236efa701Chris Craik auto displayList = new char[sizeof(DisplayList)]; 480418afa362630e69bd853121770b115750ee46a4John Reck benchmark::DoNotOptimize(displayList); 49003cc3dec8e2a92e51086fbcd5ee1bb236efa701Chris Craik delete[] displayList; 504a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck } 514a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck} 520418afa362630e69bd853121770b115750ee46a4John ReckBENCHMARK(BM_DisplayList_alloc_theoretical); 534a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 540418afa362630e69bd853121770b115750ee46a4John Reckvoid BM_DisplayListCanvas_record_empty(benchmark::State& benchState) { 55b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craik TestCanvas canvas(100, 100); 5681a1d2a15927b06b84359f839ab03ac8a20970bdChris Craik delete canvas.finishRecording(); 574a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 580418afa362630e69bd853121770b115750ee46a4John Reck while (benchState.KeepRunning()) { 596f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger canvas.resetRecording(100, 100); 600418afa362630e69bd853121770b115750ee46a4John Reck benchmark::DoNotOptimize(&canvas); 6181a1d2a15927b06b84359f839ab03ac8a20970bdChris Craik delete canvas.finishRecording(); 624a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck } 634a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck} 640418afa362630e69bd853121770b115750ee46a4John ReckBENCHMARK(BM_DisplayListCanvas_record_empty); 654a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 660418afa362630e69bd853121770b115750ee46a4John Reckvoid BM_DisplayListCanvas_record_saverestore(benchmark::State& benchState) { 67b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craik TestCanvas canvas(100, 100); 6881a1d2a15927b06b84359f839ab03ac8a20970bdChris Craik delete canvas.finishRecording(); 694a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 700418afa362630e69bd853121770b115750ee46a4John Reck while (benchState.KeepRunning()) { 716f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger canvas.resetRecording(100, 100); 72eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita canvas.save(SaveFlags::MatrixClip); 73eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita canvas.save(SaveFlags::MatrixClip); 740418afa362630e69bd853121770b115750ee46a4John Reck benchmark::DoNotOptimize(&canvas); 754a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck canvas.restore(); 764a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck canvas.restore(); 7781a1d2a15927b06b84359f839ab03ac8a20970bdChris Craik delete canvas.finishRecording(); 784a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck } 794a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck} 800418afa362630e69bd853121770b115750ee46a4John ReckBENCHMARK(BM_DisplayListCanvas_record_saverestore); 814a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 820418afa362630e69bd853121770b115750ee46a4John Reckvoid BM_DisplayListCanvas_record_translate(benchmark::State& benchState) { 83b565df13a9e5c7b1d7d93bdfa4a793752d66d3ccChris Craik TestCanvas canvas(100, 100); 8481a1d2a15927b06b84359f839ab03ac8a20970bdChris Craik delete canvas.finishRecording(); 854a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 860418afa362630e69bd853121770b115750ee46a4John Reck while (benchState.KeepRunning()) { 876f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger canvas.resetRecording(100, 100); 884a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck canvas.scale(10, 10); 890418afa362630e69bd853121770b115750ee46a4John Reck benchmark::DoNotOptimize(&canvas); 9081a1d2a15927b06b84359f839ab03ac8a20970bdChris Craik delete canvas.finishRecording(); 914a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck } 924a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck} 930418afa362630e69bd853121770b115750ee46a4John ReckBENCHMARK(BM_DisplayListCanvas_record_translate); 944a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 95b36af87f8275f4b982906f88193ec27600f2746aChris Craik/** 96b36af87f8275f4b982906f88193ec27600f2746aChris Craik * Simulate a simple view drawing a background, overlapped by an image. 97b36af87f8275f4b982906f88193ec27600f2746aChris Craik * 98b36af87f8275f4b982906f88193ec27600f2746aChris Craik * Note that the recording commands are intentionally not perfectly efficient, as the 99b36af87f8275f4b982906f88193ec27600f2746aChris Craik * View system frequently produces unneeded save/restores. 100b36af87f8275f4b982906f88193ec27600f2746aChris Craik */ 1010418afa362630e69bd853121770b115750ee46a4John Reckvoid BM_DisplayListCanvas_record_simpleBitmapView(benchmark::State& benchState) { 102b36af87f8275f4b982906f88193ec27600f2746aChris Craik TestCanvas canvas(100, 100); 103b36af87f8275f4b982906f88193ec27600f2746aChris Craik delete canvas.finishRecording(); 104b36af87f8275f4b982906f88193ec27600f2746aChris Craik 105b36af87f8275f4b982906f88193ec27600f2746aChris Craik SkPaint rectPaint; 106b36af87f8275f4b982906f88193ec27600f2746aChris Craik SkBitmap iconBitmap = TestUtils::createSkBitmap(80, 80); 107b36af87f8275f4b982906f88193ec27600f2746aChris Craik 1080418afa362630e69bd853121770b115750ee46a4John Reck while (benchState.KeepRunning()) { 1096f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger canvas.resetRecording(100, 100); 110b36af87f8275f4b982906f88193ec27600f2746aChris Craik { 111eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita canvas.save(SaveFlags::MatrixClip); 112b36af87f8275f4b982906f88193ec27600f2746aChris Craik canvas.drawRect(0, 0, 100, 100, rectPaint); 113b36af87f8275f4b982906f88193ec27600f2746aChris Craik canvas.restore(); 114b36af87f8275f4b982906f88193ec27600f2746aChris Craik } 115b36af87f8275f4b982906f88193ec27600f2746aChris Craik { 116eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita canvas.save(SaveFlags::MatrixClip); 117b36af87f8275f4b982906f88193ec27600f2746aChris Craik canvas.translate(10, 10); 118b36af87f8275f4b982906f88193ec27600f2746aChris Craik canvas.drawBitmap(iconBitmap, 0, 0, nullptr); 119b36af87f8275f4b982906f88193ec27600f2746aChris Craik canvas.restore(); 120b36af87f8275f4b982906f88193ec27600f2746aChris Craik } 1210418afa362630e69bd853121770b115750ee46a4John Reck benchmark::DoNotOptimize(&canvas); 122b36af87f8275f4b982906f88193ec27600f2746aChris Craik delete canvas.finishRecording(); 123b36af87f8275f4b982906f88193ec27600f2746aChris Craik } 124b36af87f8275f4b982906f88193ec27600f2746aChris Craik} 1250418afa362630e69bd853121770b115750ee46a4John ReckBENCHMARK(BM_DisplayListCanvas_record_simpleBitmapView); 126b36af87f8275f4b982906f88193ec27600f2746aChris Craik 1274a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reckclass NullClient: public CanvasStateClient { 1284a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck void onViewportInitialized() override {} 1294a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) {} 1304a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck GLuint getTargetFbo() const override { return 0; } 1314a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck}; 1324a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 1330418afa362630e69bd853121770b115750ee46a4John Reckvoid BM_CanvasState_saverestore(benchmark::State& benchState) { 1344a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck NullClient client; 1354a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck CanvasState state(client); 1364a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); 1374a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 1380418afa362630e69bd853121770b115750ee46a4John Reck while (benchState.KeepRunning()) { 139eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita state.save(SaveFlags::MatrixClip); 140eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita state.save(SaveFlags::MatrixClip); 1410418afa362630e69bd853121770b115750ee46a4John Reck benchmark::DoNotOptimize(&state); 1424a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck state.restore(); 1434a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck state.restore(); 1444a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck } 1454a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck} 1460418afa362630e69bd853121770b115750ee46a4John ReckBENCHMARK(BM_CanvasState_saverestore); 1474a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 1480418afa362630e69bd853121770b115750ee46a4John Reckvoid BM_CanvasState_init(benchmark::State& benchState) { 1494a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck NullClient client; 1504a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck CanvasState state(client); 1514a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); 1524a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 1530418afa362630e69bd853121770b115750ee46a4John Reck while (benchState.KeepRunning()) { 1544a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); 1550418afa362630e69bd853121770b115750ee46a4John Reck benchmark::DoNotOptimize(&state); 1564a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck } 1574a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck} 1580418afa362630e69bd853121770b115750ee46a4John ReckBENCHMARK(BM_CanvasState_init); 1594a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 1600418afa362630e69bd853121770b115750ee46a4John Reckvoid BM_CanvasState_translate(benchmark::State& benchState) { 1614a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck NullClient client; 1624a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck CanvasState state(client); 1634a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck state.initializeSaveStack(100, 100, 0, 0, 100, 100, Vector3()); 1644a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck 1650418afa362630e69bd853121770b115750ee46a4John Reck while (benchState.KeepRunning()) { 1664a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck state.translate(5, 5, 0); 1670418afa362630e69bd853121770b115750ee46a4John Reck benchmark::DoNotOptimize(&state); 1684a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck state.translate(-5, -5, 0); 1694a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck } 1704a4bc892e826849bd58606d99408f1bfbceddc3bJohn Reck} 1710418afa362630e69bd853121770b115750ee46a4John ReckBENCHMARK(BM_CanvasState_translate); 172