Home | History | Annotate | Download | only in microbench
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <benchmark/benchmark.h>
     18 
     19 #include "GammaFontRenderer.h"
     20 #include "tests/common/TestUtils.h"
     21 
     22 #include <SkPaint.h>
     23 
     24 using namespace android;
     25 using namespace android::uirenderer;
     26 
     27 void BM_FontRenderer_precache_cachehits(benchmark::State& state) {
     28     TestUtils::runOnRenderThread([&state](renderthread::RenderThread& thread) {
     29         SkPaint paint;
     30         paint.setTextSize(20);
     31         paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
     32         GammaFontRenderer gammaFontRenderer;
     33         FontRenderer& fontRenderer = gammaFontRenderer.getFontRenderer();
     34         fontRenderer.setFont(&paint, SkMatrix::I());
     35 
     36         std::vector<glyph_t> glyphs;
     37         std::vector<float> positions;
     38         float totalAdvance;
     39         uirenderer::Rect bounds;
     40         TestUtils::layoutTextUnscaled(paint, "This is a test",
     41                 &glyphs, &positions, &totalAdvance, &bounds);
     42 
     43         fontRenderer.precache(&paint, glyphs.data(), glyphs.size(), SkMatrix::I());
     44 
     45         while (state.KeepRunning()) {
     46             fontRenderer.precache(&paint, glyphs.data(), glyphs.size(), SkMatrix::I());
     47         }
     48     });
     49 }
     50 BENCHMARK(BM_FontRenderer_precache_cachehits);
     51