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

Side by Side Diff: samplecode/SampleFatBits.cpp

Issue 279563002: hide get/setLocalMatrix (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 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 | « include/core/SkShader.h ('k') | src/core/SkPictureShader.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 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 17 matching lines...) Expand all
28 static void apply_grid(SkPoint pts[], int count) { 28 static void apply_grid(SkPoint pts[], int count) {
29 for (int i = 0; i < count; ++i) { 29 for (int i = 0; i < count; ++i) {
30 pts[i].set(apply_grid(pts[i].fX), apply_grid(pts[i].fY)); 30 pts[i].set(apply_grid(pts[i].fX), apply_grid(pts[i].fY));
31 } 31 }
32 } 32 }
33 33
34 static void erase(SkSurface* surface) { 34 static void erase(SkSurface* surface) {
35 surface->getCanvas()->clear(SK_ColorTRANSPARENT); 35 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
36 } 36 }
37 37
38 static SkShader* createChecker() { 38 static SkShader* createChecker(const SkMatrix& localMatrix) {
39 // SkColor colors[] = { 0xFFFDFDFD, 0xFFF4F4F4 }; 39 // SkColor colors[] = { 0xFFFDFDFD, 0xFFF4F4F4 };
40 SkColor colors[] = { 0xFFFFFFFF, 0xFFFFFFFF }; 40 SkColor colors[] = { 0xFFFFFFFF, 0xFFFFFFFF };
41 SkBitmap bm; 41 SkBitmap bm;
42 bm.allocN32Pixels(2, 2); 42 bm.allocN32Pixels(2, 2);
43 bm.lockPixels(); 43 bm.lockPixels();
44 *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = SkPreMultiplyColor(colors[0]); 44 *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = SkPreMultiplyColor(colors[0]);
45 *bm.getAddr32(0, 1) = *bm.getAddr32(1, 0) = SkPreMultiplyColor(colors[1]); 45 *bm.getAddr32(0, 1) = *bm.getAddr32(1, 0) = SkPreMultiplyColor(colors[1]);
46 SkMatrix m;
47 m.setScale(12, 12);
48 return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, 46 return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
49 SkShader::kRepeat_TileMode, &m); 47 SkShader::kRepeat_TileMode, &localMatrix );
50 } 48 }
51 49
52 class FatBits { 50 class FatBits {
53 public: 51 public:
54 FatBits() : fShader(createChecker()) { 52 FatBits() {
55 fAA = false; 53 fAA = false;
56 fStyle = kHair_Style; 54 fStyle = kHair_Style;
57 fGrid = true; 55 fGrid = true;
58 fShowSkeleton = true; 56 fShowSkeleton = true;
59 fUseGPU = false; 57 fUseGPU = false;
60 fUseClip = false; 58 fUseClip = false;
61 fRectAsOval = false; 59 fRectAsOval = false;
62 fUseTriangle = false; 60 fUseTriangle = false;
63 61
64 fClipRect.set(2, 2, 11, 8 ); 62 fClipRect.set(2, 2, 11, 8 );
(...skipping 28 matching lines...) Expand all
93 Style getStyle() const { return fStyle; } 91 Style getStyle() const { return fStyle; }
94 void setStyle(Style s) { fStyle = s; } 92 void setStyle(Style s) { fStyle = s; }
95 93
96 void setWHZ(int width, int height, int zoom) { 94 void setWHZ(int width, int height, int zoom) {
97 fW = width; 95 fW = width;
98 fH = height; 96 fH = height;
99 fZoom = zoom; 97 fZoom = zoom;
100 fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zo om)); 98 fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zo om));
101 fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom)); 99 fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom));
102 fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom); 100 fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom);
103 fShader->setLocalMatrix(fMatrix); 101 fShader.reset(createChecker(fMatrix));
104 102
105 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); 103 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
106 fMinSurface.reset(SkSurface::NewRaster(info)); 104 fMinSurface.reset(SkSurface::NewRaster(info));
107 info.fWidth *= zoom; 105 info.fWidth *= zoom;
108 info.fHeight *= zoom; 106 info.fHeight *= zoom;
109 fMaxSurface.reset(SkSurface::NewRaster(info)); 107 fMaxSurface.reset(SkSurface::NewRaster(info));
110 } 108 }
111 109
112 void drawBG(SkCanvas*); 110 void drawBG(SkCanvas*);
113 void drawFG(SkCanvas*); 111 void drawFG(SkCanvas*);
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 517
520 private: 518 private:
521 519
522 typedef SampleView INHERITED; 520 typedef SampleView INHERITED;
523 }; 521 };
524 522
525 ////////////////////////////////////////////////////////////////////////////// 523 //////////////////////////////////////////////////////////////////////////////
526 524
527 static SkView* MyFactory() { return new DrawLineView; } 525 static SkView* MyFactory() { return new DrawLineView; }
528 static SkViewRegister reg(MyFactory); 526 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « include/core/SkShader.h ('k') | src/core/SkPictureShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698