blob: 3d5cda49295decdabcbcd50410ed4d988cf35f19 [file] [log] [blame]
tomhudsond968a6f2015-03-26 11:28:06 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "nanobenchAndroid.h"
9
10#include "AnimationContext.h"
11#include "IContextFactory.h"
12#include "SkiaCanvasProxy.h"
13#include "android/rect.h"
14#include "android/native_window.h"
15#include "renderthread/TimeLord.h"
16
tomhudson573ae012015-03-27 12:22:01 -070017/* These functions are only compiled in the Android Framework. */
tomhudsond968a6f2015-03-26 11:28:06 -070018
19HWUITarget::HWUITarget(const Config& c, Benchmark* bench) : Target(c) { }
20
21void HWUITarget::setup() {
tomhudson573ae012015-03-27 12:22:01 -070022 this->renderer.proxy->fence();
tomhudsond968a6f2015-03-26 11:28:06 -070023}
24
25SkCanvas* HWUITarget::beginTiming(SkCanvas* canvas) {
tomhudson573ae012015-03-27 12:22:01 -070026 SkCanvas* targetCanvas = this->renderer.prepareToDraw();
tomhudsond968a6f2015-03-26 11:28:06 -070027 if (targetCanvas) {
28 this->fc.reset(targetCanvas);
29 canvas = &this->fc;
30 // This might minimally distort timing, but canvas isn't valid outside the timer.
31 canvas->clear(SK_ColorWHITE);
tomhudson573ae012015-03-27 12:22:01 -070032 }
33
tomhudsond968a6f2015-03-26 11:28:06 -070034 return canvas;
35}
36
37void HWUITarget::endTiming() {
tomhudson573ae012015-03-27 12:22:01 -070038 this->renderer.finishDrawing();
tomhudsond968a6f2015-03-26 11:28:06 -070039}
40
41void HWUITarget::fence() {
tomhudson573ae012015-03-27 12:22:01 -070042 this->renderer.proxy->fence();
tomhudsond968a6f2015-03-26 11:28:06 -070043}
44
45bool HWUITarget::needsFrameTiming() const {
46 return true;
47}
48
49bool HWUITarget::init(SkImageInfo info, Benchmark* bench) {
tomhudson573ae012015-03-27 12:22:01 -070050 this->renderer.initialize({bench->getSize().x(), bench->getSize().y()});
tomhudsond968a6f2015-03-26 11:28:06 -070051 return true;
52}
53
54bool HWUITarget::capturePixels(SkBitmap* bmp) {
tomhudson573ae012015-03-27 12:22:01 -070055 return this->renderer.capturePixels(bmp);
tomhudsond968a6f2015-03-26 11:28:06 -070056}
57
58