Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: samplecode/SampleShaderText.cpp

Issue 169063002: use SkColorType instead of SkBitmap::Config in samplecode (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samplecode/SampleRotateCircles.cpp ('k') | samplecode/SampleSlides.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
12 #include "SkUnitMappers.h" 12 #include "SkUnitMappers.h"
13 13
14 static void makebm(SkBitmap* bm, SkBitmap::Config config, int w, int h) { 14 static void makebm(SkBitmap* bm, int w, int h) {
15 bm->setConfig(config, w, h); 15 bm->allocN32Pixels(w, h);
16 bm->allocPixels();
17 bm->eraseColor(SK_ColorTRANSPARENT); 16 bm->eraseColor(SK_ColorTRANSPARENT);
18 17
19 SkCanvas canvas(*bm); 18 SkCanvas canvas(*bm);
20 SkScalar s = SkIntToScalar(w < h ? w : h); 19 SkScalar s = SkIntToScalar(w < h ? w : h);
21 SkPoint pts[] = { { 0, 0 }, { s, s } }; 20 SkPoint pts[] = { { 0, 0 }, { s, s } };
22 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; 21 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
23 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; 22 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
24 SkPaint paint; 23 SkPaint paint;
25 24
26 SkUnitMapper* um = NULL; 25 SkUnitMapper* um = NULL;
27 26
28 um = new SkCosineMapper; 27 um = new SkCosineMapper;
29 28
30 SkAutoUnref au(um); 29 SkAutoUnref au(um);
31 30
32 paint.setDither(true); 31 paint.setDither(true);
33 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, 32 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
34 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref() ; 33 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref() ;
35 canvas.drawPaint(paint); 34 canvas.drawPaint(paint);
36 } 35 }
37 36
38 static SkShader* MakeBitmapShader(SkShader::TileMode tx, SkShader::TileMode ty, 37 static SkShader* MakeBitmapShader(SkShader::TileMode tx, SkShader::TileMode ty,
39 int w, int h) { 38 int w, int h) {
40 static SkBitmap bmp; 39 static SkBitmap bmp;
41 if (bmp.isNull()) { 40 if (bmp.isNull()) {
42 makebm(&bmp, SkBitmap::kARGB_8888_Config, w/2, h/4); 41 makebm(&bmp, w/2, h/4);
43 } 42 }
44 return SkShader::CreateBitmapShader(bmp, tx, ty); 43 return SkShader::CreateBitmapShader(bmp, tx, ty);
45 } 44 }
46 45
47 /////////////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////////////
48 47
49 struct GradData { 48 struct GradData {
50 int fCount; 49 int fCount;
51 const SkColor* fColors; 50 const SkColor* fColors;
52 const SkScalar* fPos; 51 const SkScalar* fPos;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 205 }
207 206
208 private: 207 private:
209 typedef SampleView INHERITED; 208 typedef SampleView INHERITED;
210 }; 209 };
211 210
212 /////////////////////////////////////////////////////////////////////////////// 211 ///////////////////////////////////////////////////////////////////////////////
213 212
214 static SkView* MyFactory() { return new ShaderTextView; } 213 static SkView* MyFactory() { return new ShaderTextView; }
215 static SkViewRegister reg(MyFactory); 214 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleRotateCircles.cpp ('k') | samplecode/SampleSlides.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698