644629c1c7
Adds "grresourcecache_add" and "grresourcecache_find" bench tests to test GrResourceCache::add and GrResourceCache::find. The tests work only with GPU backends, since GrResourceCache needs an GrGpu. Modifies bench tests to override SkBenchmark::isSuitableFor(Backend) function that specifies what kind of backend the test is inteded for. This replaces the previous "fIsRendering" flag that would indicate test that did no rendering. Adds SkCanvas::getGrContext() call to get the GrContext that the canvas ends up drawing to. The member function solves a common use-case that is also used in the benchmark added here. R=mtklein@google.com, bsalomon@google.com Author: kkinnunen@nvidia.com Review URL: https://codereview.chromium.org/73643005 git-svn-id: http://skia.googlecode.com/svn/trunk@12334 2bbb7eff-a529-9590-31e7-b0007b416f81
203 lines
4.7 KiB
C++
203 lines
4.7 KiB
C++
/*
|
|
* Copyright 2012 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
#include "SkBenchmark.h"
|
|
#include "SkRefCnt.h"
|
|
#include "SkThread.h"
|
|
#include "SkWeakRefCnt.h"
|
|
#include <memory>
|
|
|
|
enum {
|
|
M = 2
|
|
};
|
|
|
|
class RefCntBench_Stack : public SkBenchmark {
|
|
public:
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
return backend == kNonRendering_Backend;
|
|
}
|
|
|
|
protected:
|
|
virtual const char* onGetName() {
|
|
return "ref_cnt_stack";
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas*) {
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
|
SkRefCnt ref;
|
|
for (int j = 0; j < M; ++j) {
|
|
ref.ref();
|
|
ref.unref();
|
|
}
|
|
}
|
|
}
|
|
|
|
private:
|
|
typedef SkBenchmark INHERITED;
|
|
};
|
|
|
|
class PlacedRefCnt : public SkRefCnt {
|
|
public:
|
|
SK_DECLARE_INST_COUNT(PlacedRefCnt)
|
|
|
|
PlacedRefCnt() : SkRefCnt() { }
|
|
void operator delete(void*) { }
|
|
|
|
private:
|
|
typedef SkRefCnt INHERITED;
|
|
};
|
|
|
|
SK_DEFINE_INST_COUNT(PlacedRefCnt)
|
|
|
|
class RefCntBench_Heap : public SkBenchmark {
|
|
public:
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
return backend == kNonRendering_Backend;
|
|
}
|
|
|
|
protected:
|
|
virtual const char* onGetName() {
|
|
return "ref_cnt_heap";
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas*) {
|
|
char memory[sizeof(PlacedRefCnt)];
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
|
PlacedRefCnt* ref = new (memory) PlacedRefCnt();
|
|
for (int j = 0; j < M; ++j) {
|
|
ref->ref();
|
|
ref->unref();
|
|
}
|
|
ref->unref();
|
|
}
|
|
}
|
|
|
|
private:
|
|
typedef SkBenchmark INHERITED;
|
|
};
|
|
|
|
class RefCntBench_New : public SkBenchmark {
|
|
public:
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
return backend == kNonRendering_Backend;
|
|
}
|
|
|
|
protected:
|
|
virtual const char* onGetName() {
|
|
return "ref_cnt_new";
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas*) {
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
|
SkRefCnt* ref = new SkRefCnt();
|
|
for (int j = 0; j < M; ++j) {
|
|
ref->ref();
|
|
ref->unref();
|
|
}
|
|
ref->unref();
|
|
}
|
|
}
|
|
|
|
private:
|
|
typedef SkBenchmark INHERITED;
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class WeakRefCntBench_Stack : public SkBenchmark {
|
|
public:
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
return backend == kNonRendering_Backend;
|
|
}
|
|
|
|
protected:
|
|
virtual const char* onGetName() {
|
|
return "ref_cnt_stack_weak";
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas*) {
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
|
SkWeakRefCnt ref;
|
|
for (int j = 0; j < M; ++j) {
|
|
ref.ref();
|
|
ref.unref();
|
|
}
|
|
}
|
|
}
|
|
|
|
private:
|
|
typedef SkBenchmark INHERITED;
|
|
};
|
|
|
|
class PlacedWeakRefCnt : public SkWeakRefCnt {
|
|
public:
|
|
PlacedWeakRefCnt() : SkWeakRefCnt() { }
|
|
void operator delete(void*) { }
|
|
};
|
|
|
|
class WeakRefCntBench_Heap : public SkBenchmark {
|
|
public:
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
return backend == kNonRendering_Backend;
|
|
}
|
|
|
|
protected:
|
|
virtual const char* onGetName() {
|
|
return "ref_cnt_heap_weak";
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas*) {
|
|
char memory[sizeof(PlacedWeakRefCnt)];
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
|
PlacedWeakRefCnt* ref = new (memory) PlacedWeakRefCnt();
|
|
for (int j = 0; j < M; ++j) {
|
|
ref->ref();
|
|
ref->unref();
|
|
}
|
|
ref->unref();
|
|
}
|
|
}
|
|
|
|
private:
|
|
typedef SkBenchmark INHERITED;
|
|
};
|
|
|
|
class WeakRefCntBench_New : public SkBenchmark {
|
|
public:
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
return backend == kNonRendering_Backend;
|
|
}
|
|
|
|
protected:
|
|
virtual const char* onGetName() {
|
|
return "ref_cnt_new_weak";
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas*) {
|
|
for (int i = 0; i < this->getLoops(); ++i) {
|
|
SkWeakRefCnt* ref = new SkWeakRefCnt();
|
|
for (int j = 0; j < M; ++j) {
|
|
ref->ref();
|
|
ref->unref();
|
|
}
|
|
ref->unref();
|
|
}
|
|
}
|
|
|
|
private:
|
|
typedef SkBenchmark INHERITED;
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_BENCH( return new RefCntBench_Stack(); )
|
|
DEF_BENCH( return new RefCntBench_Heap(); )
|
|
DEF_BENCH( return new RefCntBench_New(); )
|
|
|
|
DEF_BENCH( return new WeakRefCntBench_Stack(); )
|
|
DEF_BENCH( return new WeakRefCntBench_Heap(); )
|
|
DEF_BENCH( return new WeakRefCntBench_New(); )
|