OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 7 |
8 #include "DecodeFile.h" | 8 #include "DecodeFile.h" |
9 #include "SampleCode.h" | 9 #include "SampleCode.h" |
10 #include "SkAnimTimer.h" | 10 #include "SkAnimTimer.h" |
11 #include "SkView.h" | 11 #include "SkView.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkCamera.h" | 13 #include "SkCamera.h" |
14 #include "SkEmbossMaskFilter.h" | 14 #include "SkEmbossMaskFilter.h" |
15 #include "SkGradientShader.h" | 15 #include "SkGradientShader.h" |
16 #include "SkPath.h" | 16 #include "SkPath.h" |
17 #include "SkRegion.h" | 17 #include "SkRegion.h" |
18 #include "SkShader.h" | 18 #include "SkShader.h" |
19 #include "SkUtils.h" | 19 #include "SkUtils.h" |
20 #include "SkRandom.h" | 20 #include "SkRandom.h" |
21 | 21 |
22 class CameraView : public SampleView { | 22 class CameraView : public SampleView { |
23 SkTDArray<SkShader*> fShaders; | 23 SkTArray<sk_sp<SkShader>> fShaders; |
24 int fShaderIndex; | 24 int fShaderIndex; |
25 bool fFrontFace; | 25 bool fFrontFace; |
26 public: | 26 public: |
27 CameraView() { | 27 CameraView() { |
28 fRX = fRY = fRZ = 0; | 28 fRX = fRY = fRZ = 0; |
29 fShaderIndex = 0; | 29 fShaderIndex = 0; |
30 fFrontFace = false; | 30 fFrontFace = false; |
31 | 31 |
32 for (int i = 0;; i++) { | 32 for (int i = 0;; i++) { |
33 SkString str; | 33 SkString str; |
34 str.printf("/skimages/elephant%d.jpeg", i); | 34 str.printf("/skimages/elephant%d.jpeg", i); |
35 SkBitmap bm; | 35 SkBitmap bm; |
36 if (decode_file(str.c_str(), &bm)) { | 36 if (decode_file(str.c_str(), &bm)) { |
37 SkRect src = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm
.height()) }; | 37 SkRect src = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm
.height()) }; |
38 SkRect dst = { -150, -150, 150, 150 }; | 38 SkRect dst = { -150, -150, 150, 150 }; |
39 SkMatrix matrix; | 39 SkMatrix matrix; |
40 matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); | 40 matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); |
41 | 41 |
42 SkShader* s = SkShader::MakeBitmapShader(bm, | 42 fShaders.push_back(SkShader::MakeBitmapShader(bm, |
43 SkShader::kClamp_Tile
Mode, | 43 SkShader::kClamp_Tile
Mode, |
44 SkShader::kClamp_Tile
Mode, | 44 SkShader::kClamp_Tile
Mode, |
45 &matrix).release(); | 45 &matrix)); |
46 *fShaders.append() = s; | |
47 } else { | 46 } else { |
48 break; | 47 break; |
49 } | 48 } |
50 } | 49 } |
51 this->setBGColor(0xFFDDDDDD); | 50 this->setBGColor(0xFFDDDDDD); |
52 } | 51 } |
53 | 52 |
54 virtual ~CameraView() { | |
55 fShaders.unrefAll(); | |
56 } | |
57 | |
58 protected: | 53 protected: |
59 // overrides from SkEventSink | 54 // overrides from SkEventSink |
60 bool onQuery(SkEvent* evt) override { | 55 bool onQuery(SkEvent* evt) override { |
61 if (SampleCode::TitleQ(*evt)) { | 56 if (SampleCode::TitleQ(*evt)) { |
62 SampleCode::TitleR(evt, "Camera"); | 57 SampleCode::TitleR(evt, "Camera"); |
63 return true; | 58 return true; |
64 } | 59 } |
65 return this->INHERITED::onQuery(evt); | 60 return this->INHERITED::onQuery(evt); |
66 } | 61 } |
67 | 62 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 95 |
101 private: | 96 private: |
102 SkScalar fRX, fRY, fRZ; | 97 SkScalar fRX, fRY, fRZ; |
103 typedef SampleView INHERITED; | 98 typedef SampleView INHERITED; |
104 }; | 99 }; |
105 | 100 |
106 ////////////////////////////////////////////////////////////////////////////// | 101 ////////////////////////////////////////////////////////////////////////////// |
107 | 102 |
108 static SkView* MyFactory() { return new CameraView; } | 103 static SkView* MyFactory() { return new CameraView; } |
109 static SkViewRegister reg(MyFactory); | 104 static SkViewRegister reg(MyFactory); |
OLD | NEW |