Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 #include "Benchmark.h" | |
| 8 #include "SkCanvas.h" | |
| 9 #include "SkColorProfileFilter.h" | |
| 10 | |
| 11 class ColorProfileBench : public Benchmark { | |
| 12 SkISize fSize; | |
| 13 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.
| |
| 14 int fCubeDimension; | |
| 15 SkData* fCubeData; | |
| 16 | |
| 17 public: | |
| 18 ColorProfileBench() | |
| 19 : fInitialized(false) | |
| 20 , fCubeDimension(0) | |
| 21 , fCubeData(NULL) { | |
| 22 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
| |
| 23 } | |
| 24 | |
| 25 ~ColorProfileBench() { | |
| 26 SkSafeUnref(fCubeData); | |
| 27 } | |
| 28 | |
| 29 protected: | |
| 30 virtual const char* onGetName() SK_OVERRIDE { | |
| 31 return "colorprofile"; | |
| 32 } | |
| 33 | |
| 34 virtual void onPreDraw() SK_OVERRIDE { | |
| 35 if (!fInitialized) { | |
| 36 this->makeCubeData(); | |
| 37 fInitialized = true; | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | |
| 42 this->test(loops, canvas, 0, 0); | |
| 43 } | |
| 44 | |
| 45 private: | |
| 46 void makeCubeData() { | |
| 47 fCubeDimension = 32; | |
| 48 fCubeData = SkData::NewUninitialized(sizeof(SkColor) * | |
| 49 fCubeDimension * fCubeDimension * fCubeDimension); | |
| 50 SkColor* pixels = (SkColor*)(fCubeData->writable_data()); | |
| 51 SkAutoMalloc lutMemory(fCubeDimension); | |
| 52 uint8_t* lut = (uint8_t*)lutMemory.get(); | |
| 53 const int maxIndex = fCubeDimension - 1; | |
| 54 for (int i = 0; i < fCubeDimension; ++i) { | |
| 55 // Make an invert lut, but the content of | |
| 56 // the lut shouldn't affect performance. | |
| 57 lut[i] = ((maxIndex - i) * 255) / maxIndex; | |
| 58 } | |
| 59 for (int r = 0; r < fCubeDimension; ++r) { | |
| 60 for (int g = 0; g < fCubeDimension; ++g) { | |
| 61 for (int b = 0; b < fCubeDimension; ++b) { | |
| 62 pixels[(fCubeDimension * ((fCubeDimension * b) + g)) + r] = | |
| 63 SkColorSetARGB(0xFF, lut[r], lut[g], lut[b]); | |
| 64 } | |
| 65 } | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) { | |
| 70 canvas->save(); | |
| 71 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.
| |
| 72 SkIntToScalar(fSize.width()), SkIntToScalar(fSize.heigh t()))); | |
| 73 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), | |
| 74 SkIntToScalar(fSize.width()), | |
| 75 SkIntToScalar(fSize.height())); | |
| 76 canvas->drawRect(r, paint); | |
| 77 canvas->restore(); | |
| 78 } | |
| 79 | |
| 80 void test(const int loops, SkCanvas* canvas, int x, int y) { | |
| 81 SkAutoTUnref<SkColorFilter> colorProfile( | |
| 82 SkColorProfileFilter::Create(fCubeData, fCubeDimension)); | |
| 83 SkPaint paint; | |
| 84 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.
| |
| 85 | |
| 86 for (int i = 0; i < loops; i++) { | |
| 87 this->drawClippedRect(canvas, x, y, paint); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 typedef Benchmark INHERITED; | |
| 92 }; | |
| 93 | |
| 94 /////////////////////////////////////////////////////////////////////////////// | |
| 95 | |
| 96 DEF_BENCH( return new ColorProfileBench(); ) | |
| OLD | NEW |