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 sk_sp<SkShader> MakeLinear(const SkISize& size) { | 51 static 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::MakeLinear( | 57 return SkGradientShader::CreateLinear( |
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 paint.setShader(MakeLinear(fSize)); | 67 SkShader* shader = MakeLinear(fSize); |
| 68 paint.setShader(shader); |
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); |
| 71 shader->unref(); |
70 } | 72 } |
71 | 73 |
72 void makeCubeData() { | 74 void makeCubeData() { |
73 fCubeDimension = 32; | 75 fCubeDimension = 32; |
74 fCubeData = SkData::NewUninitialized(sizeof(SkColor) * | 76 fCubeData = SkData::NewUninitialized(sizeof(SkColor) * |
75 fCubeDimension * fCubeDimension * fCubeDimension); | 77 fCubeDimension * fCubeDimension * fCubeDimension); |
76 SkColor* pixels = (SkColor*)(fCubeData->writable_data()); | 78 SkColor* pixels = (SkColor*)(fCubeData->writable_data()); |
77 SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension); | 79 SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension); |
78 uint8_t* lut = lutMemory.get(); | 80 uint8_t* lut = lutMemory.get(); |
79 const int maxIndex = fCubeDimension - 1; | 81 const int maxIndex = fCubeDimension - 1; |
(...skipping 21 matching lines...) Expand all Loading... |
101 canvas->drawBitmap(fBitmap, 0, 0, &paint); | 103 canvas->drawBitmap(fBitmap, 0, 0, &paint); |
102 } | 104 } |
103 } | 105 } |
104 | 106 |
105 typedef Benchmark INHERITED; | 107 typedef Benchmark INHERITED; |
106 }; | 108 }; |
107 | 109 |
108 /////////////////////////////////////////////////////////////////////////////// | 110 /////////////////////////////////////////////////////////////////////////////// |
109 | 111 |
110 DEF_BENCH( return new ColorCubeBench(); ) | 112 DEF_BENCH( return new ColorCubeBench(); ) |
OLD | NEW |