| 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" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 void onDraw(int loops, SkCanvas* canvas) override { | 42 void onDraw(int loops, SkCanvas* canvas) override { |
| 43 this->test(loops, canvas); | 43 this->test(loops, canvas); |
| 44 } | 44 } |
| 45 | 45 |
| 46 SkIPoint onGetSize() override { | 46 SkIPoint onGetSize() override { |
| 47 return SkIPoint::Make(fSize.width(), fSize.height()); | 47 return SkIPoint::Make(fSize.width(), fSize.height()); |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 static SkShader* MakeLinear(const SkISize& size) { | 51 static sk_sp<SkShader> MakeLinear(const SkISize& size) { |
| 52 const SkPoint pts[2] = { | 52 const SkPoint pts[2] = { |
| 53 { 0, 0 }, | 53 { 0, 0 }, |
| 54 { SkIntToScalar(size.width()), SkIntToScalar(size.height()) } | 54 { SkIntToScalar(size.width()), SkIntToScalar(size.height()) } |
| 55 }; | 55 }; |
| 56 static const SkColor colors[] = { SK_ColorYELLOW, SK_ColorBLUE }; | 56 static const SkColor colors[] = { SK_ColorYELLOW, SK_ColorBLUE }; |
| 57 return SkGradientShader::CreateLinear( | 57 return SkGradientShader::MakeLinear( |
| 58 pts, colors, nullptr, 2, SkShader::kRepeat_TileMode, 0, &SkMatrix::I
()); | 58 pts, colors, nullptr, 2, SkShader::kRepeat_TileMode, 0, &SkMatrix::I
()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void make_bitmap() { | 61 void make_bitmap() { |
| 62 fBitmap.allocN32Pixels(fSize.width(), fSize.height()); | 62 fBitmap.allocN32Pixels(fSize.width(), fSize.height()); |
| 63 SkCanvas canvas(fBitmap); | 63 SkCanvas canvas(fBitmap); |
| 64 canvas.clear(0x00000000); | 64 canvas.clear(0x00000000); |
| 65 SkPaint paint; | 65 SkPaint paint; |
| 66 paint.setAntiAlias(true); | 66 paint.setAntiAlias(true); |
| 67 SkShader* shader = MakeLinear(fSize); | 67 paint.setShader(MakeLinear(fSize)); |
| 68 paint.setShader(shader); | |
| 69 SkRect r = { 0, 0, SkIntToScalar(fSize.width()), SkIntToScalar(fSize.hei
ght()) }; | 68 SkRect r = { 0, 0, SkIntToScalar(fSize.width()), SkIntToScalar(fSize.hei
ght()) }; |
| 70 canvas.drawRect(r, paint); | 69 canvas.drawRect(r, paint); |
| 71 shader->unref(); | |
| 72 } | 70 } |
| 73 | 71 |
| 74 void makeCubeData() { | 72 void makeCubeData() { |
| 75 fCubeDimension = 32; | 73 fCubeDimension = 32; |
| 76 fCubeData = SkData::NewUninitialized(sizeof(SkColor) * | 74 fCubeData = SkData::NewUninitialized(sizeof(SkColor) * |
| 77 fCubeDimension * fCubeDimension * fCubeDimension); | 75 fCubeDimension * fCubeDimension * fCubeDimension); |
| 78 SkColor* pixels = (SkColor*)(fCubeData->writable_data()); | 76 SkColor* pixels = (SkColor*)(fCubeData->writable_data()); |
| 79 SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension); | 77 SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension); |
| 80 uint8_t* lut = lutMemory.get(); | 78 uint8_t* lut = lutMemory.get(); |
| 81 const int maxIndex = fCubeDimension - 1; | 79 const int maxIndex = fCubeDimension - 1; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 103 canvas->drawBitmap(fBitmap, 0, 0, &paint); | 101 canvas->drawBitmap(fBitmap, 0, 0, &paint); |
| 104 } | 102 } |
| 105 } | 103 } |
| 106 | 104 |
| 107 typedef Benchmark INHERITED; | 105 typedef Benchmark INHERITED; |
| 108 }; | 106 }; |
| 109 | 107 |
| 110 /////////////////////////////////////////////////////////////////////////////// | 108 /////////////////////////////////////////////////////////////////////////////// |
| 111 | 109 |
| 112 DEF_BENCH( return new ColorCubeBench(); ) | 110 DEF_BENCH( return new ColorCubeBench(); ) |
| OLD | NEW |