Chromium Code Reviews| Index: bench/ColorProfileBench.cpp |
| diff --git a/bench/ColorProfileBench.cpp b/bench/ColorProfileBench.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0709e0a0b268f1eaf751094e5ce6ecd755494e74 |
| --- /dev/null |
| +++ b/bench/ColorProfileBench.cpp |
| @@ -0,0 +1,96 @@ |
| +/* |
| + * 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 "Benchmark.h" |
| +#include "SkCanvas.h" |
| +#include "SkColorProfileFilter.h" |
| + |
| +class ColorProfileBench : public Benchmark { |
| + SkISize fSize; |
| + bool fInitialized; |
|
bsalomon
2014/10/03 19:45:00
Trivial, but this is the same as SkToBool(fCubeDat
sugoi1
2014/10/06 15:04:54
Done.
|
| + int fCubeDimension; |
| + SkData* fCubeData; |
| + |
| +public: |
| + ColorProfileBench() |
| + : fInitialized(false) |
| + , fCubeDimension(0) |
| + , fCubeData(NULL) { |
| + fSize = SkISize::Make(1024, 768); |
|
Stephen White
2014/10/03 19:40:49
Maybe we should make this 2Kx1.5K, to be closer to
sugoi1
2014/10/06 15:04:54
Done. Changed it to 2880x1800 (Curent MacBook Pro
|
| + } |
| + |
| + ~ColorProfileBench() { |
| + SkSafeUnref(fCubeData); |
| + } |
| + |
| +protected: |
| + virtual const char* onGetName() SK_OVERRIDE { |
| + return "colorprofile"; |
| + } |
| + |
| + virtual void onPreDraw() SK_OVERRIDE { |
| + if (!fInitialized) { |
| + this->makeCubeData(); |
| + fInitialized = true; |
| + } |
| + } |
| + |
| + virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| + this->test(loops, canvas, 0, 0); |
| + } |
| + |
| +private: |
| + void makeCubeData() { |
| + fCubeDimension = 32; |
| + fCubeData = SkData::NewUninitialized(sizeof(SkColor) * |
| + fCubeDimension * fCubeDimension * fCubeDimension); |
| + SkColor* pixels = (SkColor*)(fCubeData->writable_data()); |
| + SkAutoMalloc lutMemory(fCubeDimension); |
| + uint8_t* lut = (uint8_t*)lutMemory.get(); |
| + const int maxIndex = fCubeDimension - 1; |
| + for (int i = 0; i < fCubeDimension; ++i) { |
| + // Make an invert lut, but the content of |
| + // the lut shouldn't affect performance. |
| + lut[i] = ((maxIndex - i) * 255) / maxIndex; |
| + } |
| + for (int r = 0; r < fCubeDimension; ++r) { |
| + for (int g = 0; g < fCubeDimension; ++g) { |
| + for (int b = 0; b < fCubeDimension; ++b) { |
| + pixels[(fCubeDimension * ((fCubeDimension * b) + g)) + r] = |
| + SkColorSetARGB(0xFF, lut[r], lut[g], lut[b]); |
| + } |
| + } |
| + } |
| + } |
| + |
| + void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) { |
| + canvas->save(); |
| + canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), |
|
Stephen White
2014/10/03 19:40:49
Now that we have a bench, could you try it without
sugoi1
2014/10/06 15:04:54
Done.
|
| + SkIntToScalar(fSize.width()), SkIntToScalar(fSize.height()))); |
| + SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), |
| + SkIntToScalar(fSize.width()), |
| + SkIntToScalar(fSize.height())); |
| + canvas->drawRect(r, paint); |
| + canvas->restore(); |
| + } |
| + |
| + void test(const int loops, SkCanvas* canvas, int x, int y) { |
| + SkAutoTUnref<SkColorFilter> colorProfile( |
| + SkColorProfileFilter::Create(fCubeData, fCubeDimension)); |
| + SkPaint paint; |
| + paint.setColorFilter(colorProfile); |
|
Stephen White
2014/10/03 19:40:49
Presumably, the paint color will default to black
sugoi1
2014/10/06 15:04:54
Done.
|
| + |
| + for (int i = 0; i < loops; i++) { |
| + this->drawClippedRect(canvas, x, y, paint); |
| + } |
| + } |
| + |
| + typedef Benchmark INHERITED; |
| +}; |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| + |
| +DEF_BENCH( return new ColorProfileBench(); ) |