| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
| 10 #include "SkSurface.h" | 10 #include "SkSurface.h" |
| 11 #include "SkSurfaceProps.h" | 11 #include "SkSurfaceProps.h" |
| 12 | 12 |
| 13 #define W 200 | 13 #define W 200 |
| 14 #define H 100 | 14 #define H 100 |
| 15 | 15 |
| 16 static sk_sp<SkShader> make_shader() { | 16 static sk_sp<SkShader> make_shader() { |
| 17 int a = 0x99; | 17 int a = 0x99; |
| 18 int b = 0xBB; | 18 int b = 0xBB; |
| 19 SkPoint pts[] = { { 0, 0 }, { W, H } }; | 19 SkPoint pts[] = { { 0, 0 }, { W, H } }; |
| 20 SkColor colors[] = { SkColorSetRGB(a, a, a), SkColorSetRGB(b, b, b) }; | 20 SkColor colors[] = { SkColorSetRGB(a, a, a), SkColorSetRGB(b, b, b) }; |
| 21 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam
p_TileMode); | 21 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam
p_TileMode); |
| 22 } | 22 } |
| 23 | 23 |
| 24 static SkSurface* make_surface(GrContext* ctx, const SkImageInfo& info, SkPixelG
eometry geo, | 24 static sk_sp<SkSurface> make_surface(GrContext* ctx, const SkImageInfo& info, Sk
PixelGeometry geo, |
| 25 int disallowAA, int disallowDither) { | 25 int disallowAA, int disallowDither) { |
| 26 uint32_t flags = 0; | 26 uint32_t flags = 0; |
| 27 if (disallowAA) { | 27 if (disallowAA) { |
| 28 flags |= SkSurfaceProps::kDisallowAntiAlias_Flag; | 28 flags |= SkSurfaceProps::kDisallowAntiAlias_Flag; |
| 29 } | 29 } |
| 30 if (disallowDither) { | 30 if (disallowDither) { |
| 31 flags |= SkSurfaceProps::kDisallowDither_Flag; | 31 flags |= SkSurfaceProps::kDisallowDither_Flag; |
| 32 } | 32 } |
| 33 | 33 |
| 34 SkSurfaceProps props(flags, geo); | 34 SkSurfaceProps props(flags, geo); |
| 35 if (ctx) { | 35 if (ctx) { |
| 36 return SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props)
; | 36 return SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props
); |
| 37 } else { | 37 } else { |
| 38 return SkSurface::NewRaster(info, &props); | 38 return SkSurface::MakeRaster(info, &props); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 static void test_draw(SkCanvas* canvas, const char label[]) { | 42 static void test_draw(SkCanvas* canvas, const char label[]) { |
| 43 SkPaint paint; | 43 SkPaint paint; |
| 44 | 44 |
| 45 paint.setAntiAlias(true); | 45 paint.setAntiAlias(true); |
| 46 paint.setLCDRenderText(true); | 46 paint.setLCDRenderText(true); |
| 47 paint.setDither(true); | 47 paint.setDither(true); |
| 48 | 48 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 { kBGR_H_SkPixelGeometry, "BGR_H" }, | 85 { kBGR_H_SkPixelGeometry, "BGR_H" }, |
| 86 { kRGB_V_SkPixelGeometry, "RGB_V" }, | 86 { kRGB_V_SkPixelGeometry, "RGB_V" }, |
| 87 { kBGR_V_SkPixelGeometry, "BGR_V" }, | 87 { kBGR_V_SkPixelGeometry, "BGR_V" }, |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 SkScalar x = 0; | 90 SkScalar x = 0; |
| 91 for (int disallowAA = 0; disallowAA <= 1; ++disallowAA) { | 91 for (int disallowAA = 0; disallowAA <= 1; ++disallowAA) { |
| 92 for (int disallowDither = 0; disallowDither <= 1; ++disallowDither)
{ | 92 for (int disallowDither = 0; disallowDither <= 1; ++disallowDither)
{ |
| 93 SkScalar y = 0; | 93 SkScalar y = 0; |
| 94 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { | 94 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { |
| 95 SkAutoTUnref<SkSurface> surface(make_surface(ctx, info, rec[
i].fGeo, | 95 auto surface(make_surface(ctx, info, rec[i].fGeo, disallowAA
, disallowDither)); |
| 96 disallowAA, dis
allowDither)); | |
| 97 test_draw(surface->getCanvas(), rec[i].fLabel); | 96 test_draw(surface->getCanvas(), rec[i].fLabel); |
| 98 surface->draw(canvas, x, y, nullptr); | 97 surface->draw(canvas, x, y, nullptr); |
| 99 y += H; | 98 y += H; |
| 100 } | 99 } |
| 101 x += W; | 100 x += W; |
| 102 } | 101 } |
| 103 } | 102 } |
| 104 } | 103 } |
| 105 | 104 |
| 106 private: | 105 private: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 127 return SkISize::Make(300, 140); | 126 return SkISize::Make(300, 140); |
| 128 } | 127 } |
| 129 | 128 |
| 130 static void drawInto(SkCanvas* canvas) { | 129 static void drawInto(SkCanvas* canvas) { |
| 131 canvas->drawColor(SK_ColorRED); | 130 canvas->drawColor(SK_ColorRED); |
| 132 } | 131 } |
| 133 | 132 |
| 134 void onDraw(SkCanvas* canvas) override { | 133 void onDraw(SkCanvas* canvas) override { |
| 135 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); | 134 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); |
| 136 | 135 |
| 137 SkAutoTUnref<SkSurface> surf(canvas->newSurface(info, nullptr)); | 136 auto surf(canvas->makeSurface(info, nullptr)); |
| 138 if (!surf.get()) { | 137 if (!surf) { |
| 139 surf.reset(SkSurface::NewRaster(info)); | 138 surf = SkSurface::MakeRaster(info); |
| 140 } | 139 } |
| 141 drawInto(surf->getCanvas()); | 140 drawInto(surf->getCanvas()); |
| 142 | 141 |
| 143 sk_sp<SkImage> image(surf->makeImageSnapshot()); | 142 sk_sp<SkImage> image(surf->makeImageSnapshot()); |
| 144 canvas->drawImage(image, 10, 10, nullptr); | 143 canvas->drawImage(image, 10, 10, nullptr); |
| 145 | 144 |
| 146 SkAutoTUnref<SkSurface> surf2(surf->newSurface(info)); | 145 auto surf2(surf->makeSurface(info)); |
| 147 drawInto(surf2->getCanvas()); | 146 drawInto(surf2->getCanvas()); |
| 148 | 147 |
| 149 // Assert that the props were communicated transitively through the firs
t image | 148 // Assert that the props were communicated transitively through the firs
t image |
| 150 SkASSERT(equal(surf->props(), surf2->props())); | 149 SkASSERT(equal(surf->props(), surf2->props())); |
| 151 | 150 |
| 152 sk_sp<SkImage> image2(surf2->makeImageSnapshot()); | 151 sk_sp<SkImage> image2(surf2->makeImageSnapshot()); |
| 153 canvas->drawImage(image2.get(), 10 + SkIntToScalar(image->width()) + 10,
10, nullptr); | 152 canvas->drawImage(image2.get(), 10 + SkIntToScalar(image->width()) + 10,
10, nullptr); |
| 154 } | 153 } |
| 155 | 154 |
| 156 private: | 155 private: |
| 157 typedef GM INHERITED; | 156 typedef GM INHERITED; |
| 158 }; | 157 }; |
| 159 DEF_GM( return new NewSurfaceGM ) | 158 DEF_GM( return new NewSurfaceGM ) |
| 160 | 159 |
| OLD | NEW |