Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: bench/SkBlend_optsBench.cpp

Issue 1998113003: Make LinearSrcOverBench not crash in constructor when resource path is missing (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/SkBlend_optsBench.cpp
diff --git a/bench/SkBlend_optsBench.cpp b/bench/SkBlend_optsBench.cpp
index 9c34d49f34bc3b60b68321ef1fca748858f34a16..08c3d7fd4b870536ca2c0eae16f645d8ff0bc94e 100644
--- a/bench/SkBlend_optsBench.cpp
+++ b/bench/SkBlend_optsBench.cpp
@@ -93,20 +93,10 @@ public:
template <typename Blender>
class LinearSrcOverBench : public Benchmark {
public:
- LinearSrcOverBench(const char* fileName) {
+ LinearSrcOverBench(const char* fileName) : fFileName(fileName) {
fName = "LinearSrcOver";
fName.append(fileName);
fName.append(Blender::Name());
-
- sk_sp<SkImage> image = GetResourceAsImage(fileName);
- SkBitmap bm;
- if (!as_IB(image)->getROPixels(&bm)) {
- SkFAIL("Could not read resource");
- }
- bm.peekPixels(&fPixmap);
- fCount = fPixmap.rowBytesAsPixels();
- fDst.reset(fCount);
- memset(fDst.get(), 0, fPixmap.rowBytes());
}
protected:
@@ -114,6 +104,21 @@ protected:
return backend == kNonRendering_Backend && Blender::WorksOnCpu();
}
const char* onGetName() override { return fName.c_str(); }
+
+ void onPreDraw(SkCanvas*) override {
+ if (!fPixmap.addr()) {
+ sk_sp<SkImage> image = GetResourceAsImage(fFileName.c_str());
+ SkBitmap bm;
+ if (!as_IB(image)->getROPixels(&bm)) {
+ SkFAIL("Could not read resource");
+ }
+ bm.peekPixels(&fPixmap);
+ fCount = fPixmap.rowBytesAsPixels();
+ fDst.reset(fCount);
+ memset(fDst.get(), 0, fPixmap.rowBytes());
+ }
+ }
+
void onDraw(int loops, SkCanvas*) override {
SkASSERT(fPixmap.colorType() == kN32_SkColorType);
@@ -139,6 +144,7 @@ protected:
private:
int fCount;
SkAutoTArray<uint32_t> fDst;
+ SkString fFileName;
SkString fName;
SkPixmap fPixmap;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698