Robert Phillips | 96b6d53 | 2018-03-19 10:57:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkPaint.h" |
| 11 | #include "include/core/SkSurface.h" |
| 12 | #include "include/effects/SkGradientShader.h" |
| 13 | #include "include/effects/SkTableColorFilter.h" |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 14 | #include "include/gpu/GrDirectContext.h" |
Robert Phillips | 96b6d53 | 2018-03-19 10:57:42 -0400 | [diff] [blame] | 15 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "tests/Test.h" |
| 17 | #include "tools/Resources.h" |
Robert Phillips | 96b6d53 | 2018-03-19 10:57:42 -0400 | [diff] [blame] | 18 | |
Robert Phillips | 96b6d53 | 2018-03-19 10:57:42 -0400 | [diff] [blame] | 19 | // The gradient shader will use the texture strip atlas if it has too many colors. Make sure |
| 20 | // abandoning the context works. |
| 21 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerGradientTest, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 22 | auto context = ctxInfo.directContext(); |
Robert Phillips | 96b6d53 | 2018-03-19 10:57:42 -0400 | [diff] [blame] | 23 | |
| 24 | static const SkColor gColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, |
| 25 | SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, |
| 26 | SK_ColorBLACK }; |
| 27 | static const SkScalar gPos[] = { 0, 0.17f, 0.32f, 0.49f, 0.66f, 0.83f, 1.0f }; |
| 28 | |
| 29 | SkPaint p; |
| 30 | p.setShader(SkGradientShader::MakeTwoPointConical(SkPoint::Make(0, 0), |
| 31 | 1.0f, |
| 32 | SkPoint::Make(10.0f, 20.0f), |
| 33 | 2.0f, |
| 34 | gColors, |
| 35 | gPos, |
| 36 | 7, |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 37 | SkTileMode::kClamp)); |
Robert Phillips | 96b6d53 | 2018-03-19 10:57:42 -0400 | [diff] [blame] | 38 | |
| 39 | SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); |
| 40 | auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); |
| 41 | SkCanvas* canvas = surface->getCanvas(); |
| 42 | |
| 43 | SkRect r = SkRect::MakeXYWH(10, 10, 100, 100); |
| 44 | |
| 45 | canvas->drawRect(r, p); |
| 46 | |
| 47 | context->abandonContext(); |
| 48 | } |
| 49 | |
| 50 | // The table color filter uses the texture strip atlas. Make sure abandoning the context works. |
| 51 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerColorFilterTest, reporter, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 52 | auto context = ctxInfo.directContext(); |
Robert Phillips | 96b6d53 | 2018-03-19 10:57:42 -0400 | [diff] [blame] | 53 | |
| 54 | sk_sp<SkImage> img = GetResourceAsImage("images/mandrill_128.png"); |
| 55 | |
| 56 | |
| 57 | uint8_t identity[256]; |
| 58 | for (int i = 0; i < 256; i++) { |
| 59 | identity[i] = i; |
| 60 | } |
| 61 | |
| 62 | SkPaint p; |
| 63 | p.setColorFilter(SkTableColorFilter::Make(identity)); |
| 64 | |
| 65 | SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); |
| 66 | auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); |
| 67 | SkCanvas* canvas = surface->getCanvas(); |
| 68 | |
Mike Reed | 039f136 | 2021-01-27 21:21:08 -0500 | [diff] [blame] | 69 | canvas->drawImage(std::move(img), 0, 0, SkSamplingOptions(), &p); |
Robert Phillips | 96b6d53 | 2018-03-19 10:57:42 -0400 | [diff] [blame] | 70 | |
| 71 | context->abandonContext(); |
| 72 | } |