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

Side by Side Diff: samplecode/SampleFilterQuality.cpp

Issue 1422763004: Missing resources crash SampleFilterQuality. (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 | « no previous file | 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"
(...skipping 23 matching lines...) Expand all
34 { bounds.right(), bounds.bottom() }, 34 { bounds.right(), bounds.bottom() },
35 }; 35 };
36 const SkColor colors[] = { 36 const SkColor colors[] = {
37 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK, 37 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK,
38 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, 38 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
39 }; 39 };
40 return SkGradientShader::CreateLinear(pts, 40 return SkGradientShader::CreateLinear(pts,
41 colors, nullptr, SK_ARRAY_COUNT(colors ), 41 colors, nullptr, SK_ARRAY_COUNT(colors ),
42 SkShader::kClamp_TileMode); 42 SkShader::kClamp_TileMode);
43 #else 43 #else
44 SkString resourcePath = GetResourcePath("mandrill_128.png"); 44 SkAutoTUnref<SkImage> image(GetResourceAsImage("mandrill_128.png"));
45 SkAutoTUnref<SkData> data(SkData::NewFromFileName(resourcePath.c_str())); 45 if (nullptr == image) {
46 SkAutoTUnref<SkImage> image(SkImage::NewFromEncoded(data)); 46 return nullptr;
47 }
47 return image->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode ); 48 return image->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode );
48 #endif 49 #endif
49 } 50 }
50 51
51 #define N 128 52 #define N 128
52 #define ANGLE_DELTA 3 53 #define ANGLE_DELTA 3
53 #define SCALE_DELTA (SK_Scalar1 / 32) 54 #define SCALE_DELTA (SK_Scalar1 / 32)
54 55
55 static SkImage* make_image() { 56 static SkImage* make_image() {
56 SkImageInfo info = SkImageInfo::MakeN32(N, N, kOpaque_SkAlphaType); 57 SkImageInfo info = SkImageInfo::MakeN32(N, N, kOpaque_SkAlphaType);
57 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 58 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
58 SkCanvas* canvas = surface->getCanvas(); 59 SkCanvas* canvas = surface->getCanvas();
59 canvas->drawColor(SK_ColorWHITE); 60 canvas->drawColor(SK_ColorWHITE);
60 61
61 SkPath path; 62 SkPath path;
62 path.setFillType(SkPath::kEvenOdd_FillType); 63 path.setFillType(SkPath::kEvenOdd_FillType);
63 64
64 path.addRect(SkRect::MakeWH(N/2, N)); 65 path.addRect(SkRect::MakeWH(N/2, N));
65 path.addRect(SkRect::MakeWH(N, N/2)); 66 path.addRect(SkRect::MakeWH(N, N/2));
66 path.moveTo(0, 0); path.lineTo(N, 0); path.lineTo(0, N); path.close(); 67 path.moveTo(0, 0); path.lineTo(N, 0); path.lineTo(0, N); path.close();
67 68
68 SkPaint paint; 69 SkPaint paint;
69 paint.setShader(make_shader(SkRect::MakeWH(N, N)))->unref(); 70 SkSafeUnref(paint.setShader(make_shader(SkRect::MakeWH(N, N))));
70 71
71 canvas->drawPath(path, paint); 72 canvas->drawPath(path, paint);
72 return surface->newImageSnapshot(); 73 return surface->newImageSnapshot();
73 } 74 }
74 75
75 static SkImage* zoom_up(SkSurface* origSurf, SkImage* orig) { 76 static SkImage* zoom_up(SkSurface* origSurf, SkImage* orig) {
76 const SkScalar S = 16; // amount to scale up 77 const SkScalar S = 16; // amount to scale up
77 const int D = 2; // dimension scaling for the offscreen 78 const int D = 2; // dimension scaling for the offscreen
78 // since we only view the center, don't need to produce the entire thing 79 // since we only view the center, don't need to produce the entire thing
79 80
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 315 }
315 316
316 private: 317 private:
317 typedef SampleView INHERITED; 318 typedef SampleView INHERITED;
318 }; 319 };
319 320
320 ////////////////////////////////////////////////////////////////////////////// 321 //////////////////////////////////////////////////////////////////////////////
321 322
322 static SkView* MyFactory() { return new FilterQualityView; } 323 static SkView* MyFactory() { return new FilterQualityView; }
323 static SkViewRegister reg(MyFactory); 324 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698