| OLD | NEW | 
|    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" |   15 #include "SkGradientShader.h" | 
|   16 #include "SkData.h" |   16 #include "SkData.h" | 
|   17 #include "SkPath.h" |   17 #include "SkPath.h" | 
|   18 #include "SkSurface.h" |   18 #include "SkSurface.h" | 
|   19 #include "SkRandom.h" |   19 #include "SkRandom.h" | 
|   20 #include "SkTime.h" |   20 #include "SkTime.h" | 
|   21  |   21  | 
|   22 static SkSurface* make_surface(SkCanvas* canvas, const SkImageInfo& info) { |   22 static SkSurface* make_surface(SkCanvas* canvas, const SkImageInfo& info) { | 
|   23     SkSurface* surface = canvas->newSurface(info); |   23     SkSurface* surface = canvas->newSurface(info); | 
|   24     if (!surface) { |   24     if (!surface) { | 
|   25         surface = SkSurface::NewRaster(info); |   25         surface = SkSurface::NewRaster(info); | 
|   26     } |   26     } | 
|   27     return surface; |   27     return surface; | 
|   28 } |   28 } | 
|   29  |   29  | 
|   30 static SkShader* make_shader(const SkRect& bounds) { |   30 static sk_sp<SkShader> make_shader(const SkRect& bounds) { | 
|   31 #if 0 |   31 #if 0 | 
|   32     const SkPoint pts[] = { |   32     const SkPoint pts[] = { | 
|   33         { bounds.left(), bounds.top() }, |   33         { bounds.left(), bounds.top() }, | 
|   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     SkAutoTUnref<SkImage> image(GetResourceAsImage("mandrill_128.png")); |   44     SkAutoTUnref<SkImage> image(GetResourceAsImage("mandrill_128.png")); | 
|   45     if (nullptr == image) { |   45     if (nullptr == image) { | 
|   46         return nullptr; |   46         return nullptr; | 
|   47     } |   47     } | 
|   48     return image->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode
     ); |   48     return image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMod
     e); | 
|   49 #endif |   49 #endif | 
|   50 } |   50 } | 
|   51  |   51  | 
|   52 #define N   128 |   52 #define N   128 | 
|   53 #define ANGLE_DELTA 3 |   53 #define ANGLE_DELTA 3 | 
|   54 #define SCALE_DELTA (SK_Scalar1 / 32) |   54 #define SCALE_DELTA (SK_Scalar1 / 32) | 
|   55  |   55  | 
|   56 static SkImage* make_image() { |   56 static SkImage* make_image() { | 
|   57     SkImageInfo info = SkImageInfo::MakeN32(N, N, kOpaque_SkAlphaType); |   57     SkImageInfo info = SkImageInfo::MakeN32(N, N, kOpaque_SkAlphaType); | 
|   58     SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |   58     SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 
|   59     SkCanvas* canvas = surface->getCanvas(); |   59     SkCanvas* canvas = surface->getCanvas(); | 
|   60     canvas->drawColor(SK_ColorWHITE); |   60     canvas->drawColor(SK_ColorWHITE); | 
|   61  |   61  | 
|   62     SkPath path; |   62     SkPath path; | 
|   63     path.setFillType(SkPath::kEvenOdd_FillType); |   63     path.setFillType(SkPath::kEvenOdd_FillType); | 
|   64  |   64  | 
|   65     path.addRect(SkRect::MakeWH(N/2, N)); |   65     path.addRect(SkRect::MakeWH(N/2, N)); | 
|   66     path.addRect(SkRect::MakeWH(N, N/2)); |   66     path.addRect(SkRect::MakeWH(N, N/2)); | 
|   67     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(); | 
|   68  |   68  | 
|   69     SkPaint paint; |   69     SkPaint paint; | 
|   70     SkSafeUnref(paint.setShader(make_shader(SkRect::MakeWH(N, N)))); |   70     paint.setShader(make_shader(SkRect::MakeWH(N, N))); | 
|   71      |   71      | 
|   72     canvas->drawPath(path, paint); |   72     canvas->drawPath(path, paint); | 
|   73     return surface->newImageSnapshot(); |   73     return surface->newImageSnapshot(); | 
|   74 } |   74 } | 
|   75  |   75  | 
|   76 static SkImage* zoom_up(SkSurface* origSurf, SkImage* orig) { |   76 static SkImage* zoom_up(SkSurface* origSurf, SkImage* orig) { | 
|   77     const SkScalar S = 16;    // amount to scale up |   77     const SkScalar S = 16;    // amount to scale up | 
|   78     const int D = 2;    // dimension scaling for the offscreen |   78     const int D = 2;    // dimension scaling for the offscreen | 
|   79     // 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 | 
|   80      |   80      | 
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  315     } |  315     } | 
|  316  |  316  | 
|  317 private: |  317 private: | 
|  318     typedef SampleView INHERITED; |  318     typedef SampleView INHERITED; | 
|  319 }; |  319 }; | 
|  320  |  320  | 
|  321 ////////////////////////////////////////////////////////////////////////////// |  321 ////////////////////////////////////////////////////////////////////////////// | 
|  322  |  322  | 
|  323 static SkView* MyFactory() { return new FilterQualityView; } |  323 static SkView* MyFactory() { return new FilterQualityView; } | 
|  324 static SkViewRegister reg(MyFactory); |  324 static SkViewRegister reg(MyFactory); | 
| OLD | NEW |