| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "Benchmark.h" | 7 #include "Benchmark.h" |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkColorCubeFilter.h" | 9 #include "SkColorCubeFilter.h" |
| 10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
| 11 #include "SkTemplates.h" |
| 11 | 12 |
| 12 class ColorCubeBench : public Benchmark { | 13 class ColorCubeBench : public Benchmark { |
| 13 SkISize fSize; | 14 SkISize fSize; |
| 14 int fCubeDimension; | 15 int fCubeDimension; |
| 15 SkData* fCubeData; | 16 SkData* fCubeData; |
| 16 SkBitmap fBitmap; | 17 SkBitmap fBitmap; |
| 17 | 18 |
| 18 public: | 19 public: |
| 19 ColorCubeBench() | 20 ColorCubeBench() |
| 20 : fCubeDimension(0) | 21 : fCubeDimension(0) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 SkRect r = { 0, 0, SkIntToScalar(fSize.width()), SkIntToScalar(fSize.hei
ght()) }; | 69 SkRect r = { 0, 0, SkIntToScalar(fSize.width()), SkIntToScalar(fSize.hei
ght()) }; |
| 69 canvas.drawRect(r, paint); | 70 canvas.drawRect(r, paint); |
| 70 shader->unref(); | 71 shader->unref(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void makeCubeData() { | 74 void makeCubeData() { |
| 74 fCubeDimension = 32; | 75 fCubeDimension = 32; |
| 75 fCubeData = SkData::NewUninitialized(sizeof(SkColor) * | 76 fCubeData = SkData::NewUninitialized(sizeof(SkColor) * |
| 76 fCubeDimension * fCubeDimension * fCubeDimension); | 77 fCubeDimension * fCubeDimension * fCubeDimension); |
| 77 SkColor* pixels = (SkColor*)(fCubeData->writable_data()); | 78 SkColor* pixels = (SkColor*)(fCubeData->writable_data()); |
| 78 SkAutoMalloc lutMemory(fCubeDimension); | 79 SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension); |
| 79 uint8_t* lut = (uint8_t*)lutMemory.get(); | 80 uint8_t* lut = lutMemory.get(); |
| 80 const int maxIndex = fCubeDimension - 1; | 81 const int maxIndex = fCubeDimension - 1; |
| 81 for (int i = 0; i < fCubeDimension; ++i) { | 82 for (int i = 0; i < fCubeDimension; ++i) { |
| 82 // Make an invert lut, but the content of | 83 // Make an invert lut, but the content of |
| 83 // the lut shouldn't affect performance. | 84 // the lut shouldn't affect performance. |
| 84 lut[i] = ((maxIndex - i) * 255) / maxIndex; | 85 lut[i] = ((maxIndex - i) * 255) / maxIndex; |
| 85 } | 86 } |
| 86 for (int r = 0; r < fCubeDimension; ++r) { | 87 for (int r = 0; r < fCubeDimension; ++r) { |
| 87 for (int g = 0; g < fCubeDimension; ++g) { | 88 for (int g = 0; g < fCubeDimension; ++g) { |
| 88 for (int b = 0; b < fCubeDimension; ++b) { | 89 for (int b = 0; b < fCubeDimension; ++b) { |
| 89 pixels[(fCubeDimension * ((fCubeDimension * b) + g)) + r] = | 90 pixels[(fCubeDimension * ((fCubeDimension * b) + g)) + r] = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 102 canvas->drawBitmap(fBitmap, 0, 0, &paint); | 103 canvas->drawBitmap(fBitmap, 0, 0, &paint); |
| 103 } | 104 } |
| 104 } | 105 } |
| 105 | 106 |
| 106 typedef Benchmark INHERITED; | 107 typedef Benchmark INHERITED; |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 /////////////////////////////////////////////////////////////////////////////// | 110 /////////////////////////////////////////////////////////////////////////////// |
| 110 | 111 |
| 111 DEF_BENCH( return new ColorCubeBench(); ) | 112 DEF_BENCH( return new ColorCubeBench(); ) |
| OLD | NEW |