| 1 |
/* |
| 2 |
* Copyright 2014 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 "bench/RecordingBench.h" |
| 9 |
|
| 10 |
#include "include/core/SkBBHFactory.h" |
| 11 |
#include "include/core/SkData.h" |
| 12 |
#include "include/core/SkPictureRecorder.h" |
| 13 |
|
| 14 |
PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) { |
| 15 |
// Flatten the source picture in case it's trivially nested (useless for timing). |
| 16 |
SkPictureRecorder rec; |
| 17 |
pic->playback(rec.beginRecording(pic->cullRect(), nullptr /*, |
| 18 |
SkPictureRecorder::kPlaybackDrawPicture_RecordFlag*/)); |
| 19 |
fSrc = rec.finishRecordingAsPicture(); |
| 20 |
} |
| 21 |
|
| 22 |
const char* PictureCentricBench::onGetName() { |
| 23 |
return fName.c_str(); |
| 24 |
} |
| 25 |
|
| 26 |
bool PictureCentricBench::isSuitableFor(Backend backend) { |
| 27 |
return backend == Backend::kNonRendering; |
| 28 |
} |
| 29 |
|
| 30 |
SkISize PictureCentricBench::onGetSize() { |
| 31 |
return SkISize::Make(SkScalarCeilToInt(fSrc->cullRect().width()), |
| 32 |
SkScalarCeilToInt(fSrc->cullRect().height())); |
| 33 |
} |
| 34 |
|
| 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 36 |
|
| 37 |
RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH) |
| 38 |
: INHERITED(name, pic) |
| 39 |
, fUseBBH(useBBH) |
| 40 |
{} |
| 41 |
|
| 42 |
void RecordingBench::onDraw(int loops, SkCanvas*) { |
| 43 |
SkRTreeFactory factory; |
| 44 |
SkPictureRecorder recorder; |
| 45 |
while (loops --> 0) { |
| 46 |
fSrc->playback(recorder.beginRecording(fSrc->cullRect(), fUseBBH ? &factory : nullptr)); |
| 47 |
(void)recorder.finishRecordingAsPicture(); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 52 |
#include "include/core/SkSerialProcs.h" |
| 53 |
|
| 54 |
DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data) |
| 55 |
: fName(name) |
| 56 |
, fEncodedPicture(std::move(data)) |
| 57 |
{} |
| 58 |
|
| 59 |
const char* DeserializePictureBench::onGetName() { |
| 60 |
return fName.c_str(); |
| 61 |
} |
| 62 |
|
| 63 |
bool DeserializePictureBench::isSuitableFor(Backend backend) { |
| 64 |
return backend == Backend::kNonRendering; |
| 65 |
} |
| 66 |
|
| 67 |
SkISize DeserializePictureBench::onGetSize() { |
| 68 |
return SkISize::Make(128, 128); |
| 69 |
} |
| 70 |
|
| 71 |
void DeserializePictureBench::onDraw(int loops, SkCanvas*) { |
| 72 |
for (int i = 0; i < loops; ++i) { |
| 73 |
SkPicture::MakeFromData(fEncodedPicture.get()); |
| 74 |
} |
| 75 |
} |