| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
| 10 #include "SkView.h" | 10 #include "SkView.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 const SkPaint* paint) { | 23 const SkPaint* paint) { |
| 24 canvas->drawAtlas(atlas, xform, tex, colors, count, SkXfermode::kModulate_Mo
de, cull, paint); | 24 canvas->drawAtlas(atlas, xform, tex, colors, count, SkXfermode::kModulate_Mo
de, cull, paint); |
| 25 } | 25 } |
| 26 | 26 |
| 27 static void draw_atlas_sim(SkCanvas* canvas, SkImage* atlas, const SkRSXform xfo
rm[], | 27 static void draw_atlas_sim(SkCanvas* canvas, SkImage* atlas, const SkRSXform xfo
rm[], |
| 28 const SkRect tex[], const SkColor colors[], int count
, const SkRect* cull, | 28 const SkRect tex[], const SkColor colors[], int count
, const SkRect* cull, |
| 29 const SkPaint* paint) { | 29 const SkPaint* paint) { |
| 30 for (int i = 0; i < count; ++i) { | 30 for (int i = 0; i < count; ++i) { |
| 31 SkMatrix matrix; | 31 SkMatrix matrix; |
| 32 matrix.setRSXform(xform[i]); | 32 matrix.setRSXform(xform[i]); |
| 33 | 33 |
| 34 canvas->save(); | 34 canvas->save(); |
| 35 canvas->concat(matrix); | 35 canvas->concat(matrix); |
| 36 canvas->drawImageRect(atlas, tex[i], tex[i].makeOffset(-tex[i].x(), -tex
[i].y()), paint, | 36 canvas->drawImageRect(atlas, tex[i], tex[i].makeOffset(-tex[i].x(), -tex
[i].y()), paint, |
| 37 SkCanvas::kFast_SrcRectConstraint); | 37 SkCanvas::kFast_SrcRectConstraint); |
| 38 canvas->restore(); | 38 canvas->restore(); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 static sk_sp<SkImage> make_atlas(int atlasSize, int cellSize) { | 42 static sk_sp<SkImage> make_atlas(int atlasSize, int cellSize) { |
| 43 SkImageInfo info = SkImageInfo::MakeN32Premul(atlasSize, atlasSize); | 43 SkImageInfo info = SkImageInfo::MakeN32Premul(atlasSize, atlasSize); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 fAlpha += fDAlpha; | 112 fAlpha += fDAlpha; |
| 113 if (fAlpha > 1) { | 113 if (fAlpha > 1) { |
| 114 fAlpha = 1; | 114 fAlpha = 1; |
| 115 fDAlpha = -fDAlpha; | 115 fDAlpha = -fDAlpha; |
| 116 } else if (fAlpha < 0) { | 116 } else if (fAlpha < 0) { |
| 117 fAlpha = 0; | 117 fAlpha = 0; |
| 118 fDAlpha = -fDAlpha; | 118 fDAlpha = -fDAlpha; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 SkRSXform asRSXform() const { | 122 SkRSXform asRSXform() const { |
| 123 return SkRSXform::MakeFromRadians(fScale, fRadian, fCenter.x(), fCen
ter.y(), | 123 return SkRSXform::MakeFromRadians(fScale, fRadian, fCenter.x(), fCen
ter.y(), |
| 124 SkScalarHalf(kCellSize), SkScalarH
alf(kCellSize)); | 124 SkScalarHalf(kCellSize), SkScalarH
alf(kCellSize)); |
| 125 } | 125 } |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 DrawAtlasProc fProc; | 128 DrawAtlasProc fProc; |
| 129 | 129 |
| 130 enum { | 130 enum { |
| 131 N = 256, | 131 N = 256, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 144 SkRandom rand; | 144 SkRandom rand; |
| 145 fAtlas = make_atlas(kAtlasSize, kCellSize); | 145 fAtlas = make_atlas(kAtlasSize, kCellSize); |
| 146 const SkScalar kMaxSpeed = 5; | 146 const SkScalar kMaxSpeed = 5; |
| 147 const SkScalar cell = SkIntToScalar(kCellSize); | 147 const SkScalar cell = SkIntToScalar(kCellSize); |
| 148 int i = 0; | 148 int i = 0; |
| 149 for (int y = 0; y < kAtlasSize; y += kCellSize) { | 149 for (int y = 0; y < kAtlasSize; y += kCellSize) { |
| 150 for (int x = 0; x < kAtlasSize; x += kCellSize) { | 150 for (int x = 0; x < kAtlasSize; x += kCellSize) { |
| 151 const SkScalar sx = SkIntToScalar(x); | 151 const SkScalar sx = SkIntToScalar(x); |
| 152 const SkScalar sy = SkIntToScalar(y); | 152 const SkScalar sy = SkIntToScalar(y); |
| 153 fTex[i].setXYWH(sx, sy, cell, cell); | 153 fTex[i].setXYWH(sx, sy, cell, cell); |
| 154 | 154 |
| 155 fRec[i].fCenter.set(sx + cell/2, sy + 3*cell/4); | 155 fRec[i].fCenter.set(sx + cell/2, sy + 3*cell/4); |
| 156 fRec[i].fVelocity.fX = rand.nextSScalar1() * kMaxSpeed; | 156 fRec[i].fVelocity.fX = rand.nextSScalar1() * kMaxSpeed; |
| 157 fRec[i].fVelocity.fY = rand.nextSScalar1() * kMaxSpeed; | 157 fRec[i].fVelocity.fY = rand.nextSScalar1() * kMaxSpeed; |
| 158 fRec[i].fScale = 1; | 158 fRec[i].fScale = 1; |
| 159 fRec[i].fDScale = rand.nextSScalar1() / 16; | 159 fRec[i].fDScale = rand.nextSScalar1() / 16; |
| 160 fRec[i].fRadian = 0; | 160 fRec[i].fRadian = 0; |
| 161 fRec[i].fDRadian = rand.nextSScalar1() / 8; | 161 fRec[i].fDRadian = rand.nextSScalar1() / 8; |
| 162 fRec[i].fAlpha = rand.nextUScalar1(); | 162 fRec[i].fAlpha = rand.nextUScalar1(); |
| 163 fRec[i].fDAlpha = rand.nextSScalar1() / 10; | 163 fRec[i].fDAlpha = rand.nextSScalar1() / 10; |
| 164 i += 1; | 164 i += 1; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 182 colors[i] = SkColorSetARGB((int)(fRec[i].fAlpha * 0xFF), 0xFF, 0
xFF, 0xFF); | 182 colors[i] = SkColorSetARGB((int)(fRec[i].fAlpha * 0xFF), 0xFF, 0
xFF, 0xFF); |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 SkPaint paint; | 185 SkPaint paint; |
| 186 paint.setFilterQuality(kLow_SkFilterQuality); | 186 paint.setFilterQuality(kLow_SkFilterQuality); |
| 187 | 187 |
| 188 const SkRect cull = this->getBounds(); | 188 const SkRect cull = this->getBounds(); |
| 189 const SkColor* colorsPtr = fUseColors ? colors : nullptr; | 189 const SkColor* colorsPtr = fUseColors ? colors : nullptr; |
| 190 fProc(canvas, fAtlas.get(), xform, fTex, colorsPtr, N, &cull, &paint); | 190 fProc(canvas, fAtlas.get(), xform, fTex, colorsPtr, N, &cull, &paint); |
| 191 } | 191 } |
| 192 | 192 |
| 193 SkRect onGetBounds() override { | 193 SkRect onGetBounds() override { |
| 194 const SkScalar border = kMaxScale * kCellSize; | 194 const SkScalar border = kMaxScale * kCellSize; |
| 195 SkRect r = fBounds; | 195 SkRect r = fBounds; |
| 196 r.outset(border, border); | 196 r.outset(border, border); |
| 197 return r; | 197 return r; |
| 198 } | 198 } |
| 199 | 199 |
| 200 private: | 200 private: |
| 201 typedef SkDrawable INHERITED; | 201 typedef SkDrawable INHERITED; |
| 202 }; | 202 }; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 #endif | 245 #endif |
| 246 | 246 |
| 247 private: | 247 private: |
| 248 typedef SampleView INHERITED; | 248 typedef SampleView INHERITED; |
| 249 }; | 249 }; |
| 250 | 250 |
| 251 ////////////////////////////////////////////////////////////////////////////// | 251 ////////////////////////////////////////////////////////////////////////////// |
| 252 | 252 |
| 253 DEF_SAMPLE( return new DrawAtlasView("DrawAtlas", draw_atlas); ) | 253 DEF_SAMPLE( return new DrawAtlasView("DrawAtlas", draw_atlas); ) |
| 254 DEF_SAMPLE( return new DrawAtlasView("DrawAtlasSim", draw_atlas_sim); ) | 254 DEF_SAMPLE( return new DrawAtlasView("DrawAtlasSim", draw_atlas_sim); ) |
| OLD | NEW |