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

Side by Side Diff: samplecode/SampleFatBits.cpp

Issue 834303005: Factor out checkerboard function in gm and sampleapp into tools. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rename to sk_tools::DrawCheckerboard Created 5 years, 11 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
« no previous file with comments | « samplecode/SampleColorFilter.cpp ('k') | samplecode/SampleUnpremul.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 "Checkerboard.h"
8 #include "SampleCode.h" 9 #include "SampleCode.h"
9 #include "SkView.h" 10 #include "SkView.h"
10 #include "SkCanvas.h" 11 #include "SkCanvas.h"
11 #include "SkPath.h" 12 #include "SkPath.h"
12 #include "SkRegion.h" 13 #include "SkRegion.h"
13 #include "SkShader.h" 14 #include "SkShader.h"
14 #include "SkUtils.h" 15 #include "SkUtils.h"
15 #include "SkImage.h" 16 #include "SkImage.h"
16 #include "SkSurface.h" 17 #include "SkSurface.h"
17 18
(...skipping 10 matching lines...) Expand all
28 static void apply_grid(SkPoint pts[], int count) { 29 static void apply_grid(SkPoint pts[], int count) {
29 for (int i = 0; i < count; ++i) { 30 for (int i = 0; i < count; ++i) {
30 pts[i].set(apply_grid(pts[i].fX), apply_grid(pts[i].fY)); 31 pts[i].set(apply_grid(pts[i].fX), apply_grid(pts[i].fY));
31 } 32 }
32 } 33 }
33 34
34 static void erase(SkSurface* surface) { 35 static void erase(SkSurface* surface) {
35 surface->getCanvas()->clear(SK_ColorTRANSPARENT); 36 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
36 } 37 }
37 38
38 static SkShader* createChecker(const SkMatrix& localMatrix) {
39 // SkColor colors[] = { 0xFFFDFDFD, 0xFFF4F4F4 };
40 SkColor colors[] = { 0xFFFFFFFF, 0xFFFFFFFF };
41 SkBitmap bm;
42 bm.allocN32Pixels(2, 2);
43 bm.lockPixels();
44 *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = SkPreMultiplyColor(colors[0]);
45 *bm.getAddr32(0, 1) = *bm.getAddr32(1, 0) = SkPreMultiplyColor(colors[1]);
46 return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
47 SkShader::kRepeat_TileMode, &localMatrix );
48 }
49
50 class FatBits { 39 class FatBits {
51 public: 40 public:
52 FatBits() { 41 FatBits() {
53 fAA = false; 42 fAA = false;
54 fStyle = kHair_Style; 43 fStyle = kHair_Style;
55 fGrid = true; 44 fGrid = true;
56 fShowSkeleton = true; 45 fShowSkeleton = true;
57 fUseGPU = false; 46 fUseGPU = false;
58 fUseClip = false; 47 fUseClip = false;
59 fRectAsOval = false; 48 fRectAsOval = false;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 Style getStyle() const { return fStyle; } 80 Style getStyle() const { return fStyle; }
92 void setStyle(Style s) { fStyle = s; } 81 void setStyle(Style s) { fStyle = s; }
93 82
94 void setWHZ(int width, int height, int zoom) { 83 void setWHZ(int width, int height, int zoom) {
95 fW = width; 84 fW = width;
96 fH = height; 85 fH = height;
97 fZoom = zoom; 86 fZoom = zoom;
98 fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zo om)); 87 fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zo om));
99 fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom)); 88 fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom));
100 fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom); 89 fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom);
101 fShader.reset(createChecker(fMatrix)); 90 fShader.reset(sk_tools::CreateCheckerboardShader(
91 0xFFCCCCCC, 0xFFFFFFFF, zoom));
102 92
103 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); 93 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
104 fMinSurface.reset(SkSurface::NewRaster(info)); 94 fMinSurface.reset(SkSurface::NewRaster(info));
105 info = info.makeWH(width * zoom, height * zoom); 95 info = info.makeWH(width * zoom, height * zoom);
106 fMaxSurface.reset(SkSurface::NewRaster(info)); 96 fMaxSurface.reset(SkSurface::NewRaster(info));
107 } 97 }
108 98
109 void drawBG(SkCanvas*); 99 void drawBG(SkCanvas*);
110 void drawFG(SkCanvas*); 100 void drawFG(SkCanvas*);
111 void drawLine(SkCanvas*, SkPoint pts[2]); 101 void drawLine(SkCanvas*, SkPoint pts[2]);
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 506
517 private: 507 private:
518 508
519 typedef SampleView INHERITED; 509 typedef SampleView INHERITED;
520 }; 510 };
521 511
522 ////////////////////////////////////////////////////////////////////////////// 512 //////////////////////////////////////////////////////////////////////////////
523 513
524 static SkView* MyFactory() { return new DrawLineView; } 514 static SkView* MyFactory() { return new DrawLineView; }
525 static SkViewRegister reg(MyFactory); 515 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleColorFilter.cpp ('k') | samplecode/SampleUnpremul.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698