653d51867c
Optional arguments to SkCanvas calls leaked refs (but not memory) because we didn't destruct the optional objects (really, just SkPaint: other optional args are all POD). This adds Optional and PODArray, where Optional makes sure to call the destructor. I overlooked that SkPictureRecord really does call paint.computeFastBounds(). Do the same in SkRecordDraw. BUG=skia:2378 R=reed@google.com, mtklein@google.com, tomhudson@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/235983015 git-svn-id: http://skia.googlecode.com/svn/trunk@14197 2bbb7eff-a529-9590-31e7-b0007b416f81
66 lines
1.7 KiB
C++
66 lines
1.7 KiB
C++
/*
|
|
* Copyright 2014 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "Test.h"
|
|
|
|
#include "SkRecord.h"
|
|
#include "SkRecorder.h"
|
|
#include "SkRecords.h"
|
|
|
|
#include "SkEmptyShader.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>());
|
|
}
|
|
|
|
// Regression test for leaking refs held by optional arguments.
|
|
DEF_TEST(Recorder_RefLeaking, r) {
|
|
// We use SaveLayer to test:
|
|
// - its SkRect argument is optional and SkRect is POD. Just testing that that works.
|
|
// - its SkPaint argument is optional and SkPaint is not POD. The bug was here.
|
|
|
|
SkRect bounds;
|
|
SkPaint paint;
|
|
paint.setShader(SkNEW(SkEmptyShader))->unref();
|
|
|
|
REPORTER_ASSERT(r, paint.getShader()->unique());
|
|
{
|
|
SkRecord record;
|
|
SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, 1920, 1080);
|
|
recorder.saveLayer(&bounds, &paint);
|
|
REPORTER_ASSERT(r, !paint.getShader()->unique());
|
|
}
|
|
REPORTER_ASSERT(r, paint.getShader()->unique());
|
|
}
|