skia2/tests/RecorderTest.cpp
commit-bot@chromium.org d9ce2be6b2 SkRecordDraw: skip draw ops when the clip is empty
- Adds tests for SkRecordDraw's two main features: cull- and clip- based skipping.
   - Adds full SkCanvas semantic mode to SkRecorder, so it can be used as a target for SkRecordDraw.

BUG=skia:2378
R=fmalita@chromium.org, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/231653002

git-svn-id: http://skia.googlecode.com/svn/trunk@14124 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-04-09 23:30:28 +00:00

37 lines
825 B
C++

#include "Test.h"
#include "SkRecord.h"
#include "SkRecorder.h"
#include "SkRecords.h"
#define COUNT(T) + 1
static const int kRecordTypes = SK_RECORD_TYPES(COUNT);
#undef COUNT
// Tallies the types of commands it sees into a histogram.
class Tally {
public:
Tally() { sk_bzero(&fHistogram, sizeof(fHistogram)); }
template <typename T>
void operator()(const T&) { ++fHistogram[T::kType]; }
template <typename T>
int count() const { return fHistogram[T::kType]; }
private:
int fHistogram[kRecordTypes];
};
DEF_TEST(Recorder, r) {
SkRecord record;
SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080);
recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
Tally tally;
record.visit(tally);
REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>());
}