| 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 sk_sp<SkSurface> make_surface(GrContext* ctx, const SkImageInfo& info, Sk
PixelGeometry geo, | 24 static sk_sp<SkSurface> make_surface(GrContext* ctx, const SkImageInfo& info, Sk
PixelGeometry geo) { |
| 25 int disallowAA, int disallowDither) { | 25 SkSurfaceProps props(0, geo); |
| 26 uint32_t flags = 0; | |
| 27 if (disallowAA) { | |
| 28 flags |= SkSurfaceProps::kDisallowAntiAlias_Flag; | |
| 29 } | |
| 30 if (disallowDither) { | |
| 31 flags |= SkSurfaceProps::kDisallowDither_Flag; | |
| 32 } | |
| 33 | |
| 34 SkSurfaceProps props(flags, geo); | |
| 35 if (ctx) { | 26 if (ctx) { |
| 36 return SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props
); | 27 return SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props
); |
| 37 } else { | 28 } else { |
| 38 return SkSurface::MakeRaster(info, &props); | 29 return SkSurface::MakeRaster(info, &props); |
| 39 } | 30 } |
| 40 } | 31 } |
| 41 | 32 |
| 42 static void test_draw(SkCanvas* canvas, const char label[]) { | 33 static void test_draw(SkCanvas* canvas, const char label[]) { |
| 43 SkPaint paint; | 34 SkPaint paint; |
| 44 | 35 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 60 class SurfacePropsGM : public skiagm::GM { | 51 class SurfacePropsGM : public skiagm::GM { |
| 61 public: | 52 public: |
| 62 SurfacePropsGM() {} | 53 SurfacePropsGM() {} |
| 63 | 54 |
| 64 protected: | 55 protected: |
| 65 SkString onShortName() override { | 56 SkString onShortName() override { |
| 66 return SkString("surfaceprops"); | 57 return SkString("surfaceprops"); |
| 67 } | 58 } |
| 68 | 59 |
| 69 SkISize onISize() override { | 60 SkISize onISize() override { |
| 70 return SkISize::Make(W * 4, H * 5); | 61 return SkISize::Make(W, H * 5); |
| 71 } | 62 } |
| 72 | 63 |
| 73 void onDraw(SkCanvas* canvas) override { | 64 void onDraw(SkCanvas* canvas) override { |
| 74 GrContext* ctx = canvas->getGrContext(); | 65 GrContext* ctx = canvas->getGrContext(); |
| 75 | 66 |
| 76 // must be opaque to have a hope of testing LCD text | 67 // must be opaque to have a hope of testing LCD text |
| 77 const SkImageInfo info = SkImageInfo::MakeN32(W, H, kOpaque_SkAlphaType, | 68 const SkImageInfo info = SkImageInfo::MakeN32(W, H, kOpaque_SkAlphaType, |
| 78 sk_ref_sp(canvas->imageInf
o().colorSpace())); | 69 sk_ref_sp(canvas->imageInf
o().colorSpace())); |
| 79 | 70 |
| 80 const struct { | 71 const struct { |
| 81 SkPixelGeometry fGeo; | 72 SkPixelGeometry fGeo; |
| 82 const char* fLabel; | 73 const char* fLabel; |
| 83 } recs[] = { | 74 } recs[] = { |
| 84 { kUnknown_SkPixelGeometry, "Unknown" }, | 75 { kUnknown_SkPixelGeometry, "Unknown" }, |
| 85 { kRGB_H_SkPixelGeometry, "RGB_H" }, | 76 { kRGB_H_SkPixelGeometry, "RGB_H" }, |
| 86 { kBGR_H_SkPixelGeometry, "BGR_H" }, | 77 { kBGR_H_SkPixelGeometry, "BGR_H" }, |
| 87 { kRGB_V_SkPixelGeometry, "RGB_V" }, | 78 { kRGB_V_SkPixelGeometry, "RGB_V" }, |
| 88 { kBGR_V_SkPixelGeometry, "BGR_V" }, | 79 { kBGR_V_SkPixelGeometry, "BGR_V" }, |
| 89 }; | 80 }; |
| 90 | 81 |
| 91 SkScalar x = 0; | 82 SkScalar x = 0; |
| 92 for (int disallowAA = 0; disallowAA <= 1; ++disallowAA) { | 83 SkScalar y = 0; |
| 93 for (int disallowDither = 0; disallowDither <= 1; ++disallowDither)
{ | 84 for (const auto& rec : recs) { |
| 94 SkScalar y = 0; | 85 auto surface(make_surface(ctx, info, rec.fGeo)); |
| 95 for (const auto& rec : recs) { | 86 if (!surface) { |
| 96 auto surface(make_surface(ctx, info, rec.fGeo, disallowAA, d
isallowDither)); | 87 SkDebugf("failed to create surface! label: %s", rec.fLabel); |
| 97 if (!surface) { | 88 continue; |
| 98 SkDebugf("failed to create surface! label: %s AA: %s dit
her: %s\n", | |
| 99 rec.fLabel, (disallowAA == 1 ? "disallowed" : "
allowed"), | |
| 100 (disallowDither == 1 ? "disallowed" : "allowed"
)); | |
| 101 continue; | |
| 102 } | |
| 103 test_draw(surface->getCanvas(), rec.fLabel); | |
| 104 surface->draw(canvas, x, y, nullptr); | |
| 105 y += H; | |
| 106 } | |
| 107 x += W; | |
| 108 } | 89 } |
| 90 test_draw(surface->getCanvas(), rec.fLabel); |
| 91 surface->draw(canvas, x, y, nullptr); |
| 92 y += H; |
| 109 } | 93 } |
| 110 } | 94 } |
| 111 | 95 |
| 112 private: | 96 private: |
| 113 typedef GM INHERITED; | 97 typedef GM INHERITED; |
| 114 }; | 98 }; |
| 115 DEF_GM( return new SurfacePropsGM ) | 99 DEF_GM( return new SurfacePropsGM ) |
| 116 | 100 |
| 117 #ifdef SK_DEBUG | 101 #ifdef SK_DEBUG |
| 118 static bool equal(const SkSurfaceProps& a, const SkSurfaceProps& b) { | 102 static bool equal(const SkSurfaceProps& a, const SkSurfaceProps& b) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 SkASSERT(equal(surf->props(), surf2->props())); | 140 SkASSERT(equal(surf->props(), surf2->props())); |
| 157 | 141 |
| 158 sk_sp<SkImage> image2(surf2->makeImageSnapshot()); | 142 sk_sp<SkImage> image2(surf2->makeImageSnapshot()); |
| 159 canvas->drawImage(image2.get(), 10 + SkIntToScalar(image->width()) + 10,
10, nullptr); | 143 canvas->drawImage(image2.get(), 10 + SkIntToScalar(image->width()) + 10,
10, nullptr); |
| 160 } | 144 } |
| 161 | 145 |
| 162 private: | 146 private: |
| 163 typedef GM INHERITED; | 147 typedef GM INHERITED; |
| 164 }; | 148 }; |
| 165 DEF_GM( return new NewSurfaceGM ) | 149 DEF_GM( return new NewSurfaceGM ) |
| OLD | NEW |