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

Side by Side Diff: samplecode/SampleFilterQuality.cpp

Issue 1410243009: tweaks for nov demo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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 | « resources/nov-talk-sequence.txt ('k') | no next file » | 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 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 "gm.h" 8 #include "gm.h"
9 9
10 #include "Resources.h" 10 #include "Resources.h"
11 #include "SampleCode.h" 11 #include "SampleCode.h"
12 #include "SkAnimTimer.h" 12 #include "SkAnimTimer.h"
13 #include "SkCanvas.h" 13 #include "SkCanvas.h"
14 #include "SkInterpolator.h" 14 #include "SkInterpolator.h"
15 #include "SkGradientShader.h"
16 #include "SkData.h"
15 #include "SkPath.h" 17 #include "SkPath.h"
16 #include "SkSurface.h" 18 #include "SkSurface.h"
17 #include "SkRandom.h" 19 #include "SkRandom.h"
18 #include "SkTime.h" 20 #include "SkTime.h"
19 21
20 static SkSurface* make_surface(SkCanvas* canvas, const SkImageInfo& info) { 22 static SkSurface* make_surface(SkCanvas* canvas, const SkImageInfo& info) {
21 SkSurface* surface = canvas->newSurface(info); 23 SkSurface* surface = canvas->newSurface(info);
22 if (!surface) { 24 if (!surface) {
23 surface = SkSurface::NewRaster(info); 25 surface = SkSurface::NewRaster(info);
24 } 26 }
25 return surface; 27 return surface;
26 } 28 }
27 29
30 static SkShader* make_shader(const SkRect& bounds) {
31 #if 0
32 const SkPoint pts[] = {
33 { bounds.left(), bounds.top() },
34 { bounds.right(), bounds.bottom() },
35 };
36 const SkColor colors[] = {
37 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK,
38 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
39 };
40 return SkGradientShader::CreateLinear(pts,
41 colors, nullptr, SK_ARRAY_COUNT(colors ),
42 SkShader::kClamp_TileMode);
43 #else
44 SkString resourcePath = GetResourcePath("mandrill_128.png");
45 SkAutoTUnref<SkData> data(SkData::NewFromFileName(resourcePath.c_str()));
46 SkAutoTUnref<SkImage> image(SkImage::NewFromEncoded(data));
47 return image->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode );
48 #endif
49 }
50
28 #define N 128 51 #define N 128
29 #define ANGLE_DELTA 3 52 #define ANGLE_DELTA 3
30 #define SCALE_DELTA (SK_Scalar1 / 32) 53 #define SCALE_DELTA (SK_Scalar1 / 32)
31 54
32 static SkImage* make_image() { 55 static SkImage* make_image() {
33 SkImageInfo info = SkImageInfo::MakeN32(N, N, kOpaque_SkAlphaType); 56 SkImageInfo info = SkImageInfo::MakeN32(N, N, kOpaque_SkAlphaType);
34 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 57 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
35 SkCanvas* canvas = surface->getCanvas(); 58 SkCanvas* canvas = surface->getCanvas();
36 canvas->drawColor(SK_ColorWHITE); 59 canvas->drawColor(SK_ColorWHITE);
37 60
38 SkPath path; 61 SkPath path;
39 path.setFillType(SkPath::kEvenOdd_FillType); 62 path.setFillType(SkPath::kEvenOdd_FillType);
40 63
41 path.addRect(SkRect::MakeWH(N/2, N)); 64 path.addRect(SkRect::MakeWH(N/2, N));
42 path.addRect(SkRect::MakeWH(N, N/2)); 65 path.addRect(SkRect::MakeWH(N, N/2));
43 path.moveTo(0, 0); path.lineTo(N, 0); path.lineTo(0, N); path.close(); 66 path.moveTo(0, 0); path.lineTo(N, 0); path.lineTo(0, N); path.close();
44 67
45 canvas->drawPath(path, SkPaint()); 68 SkPaint paint;
69 paint.setShader(make_shader(SkRect::MakeWH(N, N)))->unref();
70
71 canvas->drawPath(path, paint);
46 return surface->newImageSnapshot(); 72 return surface->newImageSnapshot();
47 } 73 }
48 74
49 static SkImage* zoom_up(SkSurface* origSurf, SkImage* orig) { 75 static SkImage* zoom_up(SkSurface* origSurf, SkImage* orig) {
50 const SkScalar S = 8; // amount to scale up 76 const SkScalar S = 16; // amount to scale up
51 const int D = 2; // dimension scaling for the offscreen 77 const int D = 2; // dimension scaling for the offscreen
52 // since we only view the center, don't need to produce the entire thing 78 // since we only view the center, don't need to produce the entire thing
53 79
54 SkImageInfo info = SkImageInfo::MakeN32(orig->width() * D, orig->height() * D, 80 SkImageInfo info = SkImageInfo::MakeN32(orig->width() * D, orig->height() * D,
55 kOpaque_SkAlphaType); 81 kOpaque_SkAlphaType);
56 SkAutoTUnref<SkSurface> surface(origSurf->newSurface(info)); 82 SkAutoTUnref<SkSurface> surface(origSurf->newSurface(info));
57 SkCanvas* canvas = surface->getCanvas(); 83 SkCanvas* canvas = surface->getCanvas();
58 canvas->drawColor(SK_ColorWHITE); 84 canvas->drawColor(SK_ColorWHITE);
59 canvas->scale(S, S); 85 canvas->scale(S, S);
60 canvas->translate(-SkScalarHalf(orig->width()) * (S - D) / S, 86 canvas->translate(-SkScalarHalf(orig->width()) * (S - D) / S,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 314 }
289 315
290 private: 316 private:
291 typedef SampleView INHERITED; 317 typedef SampleView INHERITED;
292 }; 318 };
293 319
294 ////////////////////////////////////////////////////////////////////////////// 320 //////////////////////////////////////////////////////////////////////////////
295 321
296 static SkView* MyFactory() { return new FilterQualityView; } 322 static SkView* MyFactory() { return new FilterQualityView; }
297 static SkViewRegister reg(MyFactory); 323 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « resources/nov-talk-sequence.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698