Merge "Add ShadowBench"

This commit is contained in:
John Reck
2015-10-23 15:19:47 +00:00
committed by Android (Google) Code Review
5 changed files with 140 additions and 10 deletions

View File

@@ -85,8 +85,7 @@ hwui_src_files := \
hwui_cflags := \
-DEGL_EGLEXT_PROTOTYPES -DGL_GLEXT_PROTOTYPES \
-DATRACE_TAG=ATRACE_TAG_VIEW -DLOG_TAG=\"OpenGLRenderer\" \
-Wall -Wno-unused-parameter -Wunreachable-code \
-ffast-math -O3 -Werror
-Wall -Wno-unused-parameter -Wunreachable-code -Werror
ifeq (true, $(HWUI_NEW_OPS))
hwui_src_files += \
@@ -262,7 +261,8 @@ LOCAL_STATIC_LIBRARIES := libbenchmark libbase
LOCAL_SRC_FILES += \
microbench/DisplayListCanvasBench.cpp \
microbench/LinearAllocatorBench.cpp
microbench/LinearAllocatorBench.cpp \
microbench/ShadowBench.cpp
ifeq (true, $(HWUI_NEW_OPS))
LOCAL_SRC_FILES += \

View File

@@ -217,7 +217,7 @@ static void reverseVertexArray(Vertex* polygon, int len) {
}
}
static void tessellateShadows(
void tessellateShadows(
const Matrix4* drawTransform, const Rect* localClip,
bool isCasterOpaque, const SkPath* casterPerimeter,
const Matrix4* casterTransformXY, const Matrix4* casterTransformZ,

View File

@@ -17,16 +17,22 @@
#ifndef ANDROID_HWUI_TESSELLATION_CACHE_H
#define ANDROID_HWUI_TESSELLATION_CACHE_H
#include <utils/LruCache.h>
#include <utils/Mutex.h>
#include "Debug.h"
#include "Matrix.h"
#include "Rect.h"
#include "Vector.h"
#include "thread/TaskProcessor.h"
#include "utils/Macros.h"
#include "utils/Pair.h"
#include <SkPaint.h>
#include <utils/LruCache.h>
#include <utils/Mutex.h>
#include <utils/StrongPointer.h>
class SkBitmap;
class SkCanvas;
class SkPaint;
class SkPath;
struct SkRect;
@@ -185,6 +191,13 @@ private:
}; // class TessellationCache
void tessellateShadows(
const Matrix4* drawTransform, const Rect* localClip,
bool isCasterOpaque, const SkPath* casterPerimeter,
const Matrix4* casterTransformXY, const Matrix4* casterTransformZ,
const Vector3& lightCenter, float lightRadius,
VertexBuffer& ambientBuffer, VertexBuffer& spotBuffer);
}; // namespace uirenderer
}; // namespace android

View File

@@ -135,8 +135,8 @@ public:
}
void dump() {
ALOGD("Vector3[%.2f, %.2f, %.2f]", x, y, z);
void dump(const char* label = "Vector3") const {
ALOGD("%s[%.2f, %.2f, %.2f]", label, x, y, z);
}
};

View File

@@ -0,0 +1,117 @@
/*
* 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 "Matrix.h"
#include "Rect.h"
#include "Vector.h"
#include "VertexBuffer.h"
#include "TessellationCache.h"
#include "microbench/MicroBench.h"
#include <SkPath.h>
#include <memory>
using namespace android;
using namespace android::uirenderer;
struct ShadowTestData {
Matrix4 drawTransform;
Rect localClip;
Matrix4 casterTransformXY;
Matrix4 casterTransformZ;
Vector3 lightCenter;
float lightRadius;
};
void createShadowTestData(ShadowTestData* out) {
static float SAMPLE_DRAW_TRANSFORM[] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
};
static float SAMPLE_CASTERXY[] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
32, 32, 0, 1,
};
static float SAMPLE_CASTERZ[] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
32, 32, 32, 1,
};
static Rect SAMPLE_CLIP(0, 0, 1536, 2048);
static Vector3 SAMPLE_LIGHT_CENTER{768, -400, 1600};
static float SAMPLE_LIGHT_RADIUS = 1600;
out->drawTransform.load(SAMPLE_DRAW_TRANSFORM);
out->localClip = SAMPLE_CLIP;
out->casterTransformXY.load(SAMPLE_CASTERXY);
out->casterTransformZ.load(SAMPLE_CASTERZ);
out->lightCenter = SAMPLE_LIGHT_CENTER;
out->lightRadius = SAMPLE_LIGHT_RADIUS;
}
static inline void tessellateShadows(ShadowTestData& testData, bool opaque,
const SkPath& shape, VertexBuffer* ambient, VertexBuffer* spot) {
tessellateShadows(&testData.drawTransform, &testData.localClip,
opaque, &shape, &testData.casterTransformXY,
&testData.casterTransformZ, testData.lightCenter,
testData.lightRadius, *ambient, *spot);
}
BENCHMARK_NO_ARG(BM_TessellateShadows_roundrect_opaque);
void BM_TessellateShadows_roundrect_opaque::Run(int iters) {
ShadowTestData shadowData;
createShadowTestData(&shadowData);
SkPath path;
path.reset();
path.addRoundRect(SkRect::MakeLTRB(0, 0, 100, 100), 5, 5);
StartBenchmarkTiming();
for (int i = 0; i < iters; i++) {
std::unique_ptr<VertexBuffer> ambient(new VertexBuffer);
std::unique_ptr<VertexBuffer> spot(new VertexBuffer);
tessellateShadows(shadowData, true, path, ambient.get(), spot.get());
MicroBench::DoNotOptimize(ambient.get());
MicroBench::DoNotOptimize(spot.get());
}
StopBenchmarkTiming();
}
BENCHMARK_NO_ARG(BM_TessellateShadows_roundrect_translucent);
void BM_TessellateShadows_roundrect_translucent::Run(int iters) {
ShadowTestData shadowData;
createShadowTestData(&shadowData);
SkPath path;
path.reset();
path.addRoundRect(SkRect::MakeLTRB(0, 0, 100, 100), 5, 5);
StartBenchmarkTiming();
for (int i = 0; i < iters; i++) {
std::unique_ptr<VertexBuffer> ambient(new VertexBuffer);
std::unique_ptr<VertexBuffer> spot(new VertexBuffer);
tessellateShadows(shadowData, false, path, ambient.get(), spot.get());
MicroBench::DoNotOptimize(ambient.get());
MicroBench::DoNotOptimize(spot.get());
}
StopBenchmarkTiming();
}