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 #include "include/core/SkCanvas.h"
9 #include "include/core/SkColor.h"
10 #include "include/core/SkColorFilter.h"
11 #include "include/core/SkImageInfo.h"
12 #include "include/core/SkPaint.h"
13 #include "include/core/SkPoint.h"
14 #include "include/core/SkRect.h"
15 #include "include/core/SkRefCnt.h"
16 #include "include/core/SkSamplingOptions.h"
17 #include "include/core/SkScalar.h"
18 #include "include/core/SkSurface.h"
19 #include "include/core/SkTileMode.h"
20 #include "include/core/SkTypes.h"
21 #include "include/effects/SkGradientShader.h"
22 #include "include/gpu/GpuTypes.h"
23 #include "include/gpu/GrDirectContext.h"
24 #include "tests/CtsEnforcement.h"
25 #include "tests/Test.h"
26 #include "tools/Resources.h"
27
28 #include <cstdint>
29 #include <utility>
30
31 class SkImage;
32 struct GrContextOptions;
33
34 // The gradient shader will use the texture strip atlas if it has too many colors. Make sure
35 // abandoning the context works.
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerGradientTest,reporter,ctxInfo,CtsEnforcement::kApiLevel_T)36 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerGradientTest,
37 reporter,
38 ctxInfo,
39 CtsEnforcement::kApiLevel_T) {
40 auto context = ctxInfo.directContext();
41
42 static const SkColor gColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
43 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
44 SK_ColorBLACK };
45 static const SkScalar gPos[] = { 0, 0.17f, 0.32f, 0.49f, 0.66f, 0.83f, 1.0f };
46
47 SkPaint p;
48 p.setShader(SkGradientShader::MakeTwoPointConical(SkPoint::Make(0, 0),
49 1.0f,
50 SkPoint::Make(10.0f, 20.0f),
51 2.0f,
52 gColors,
53 gPos,
54 7,
55 SkTileMode::kClamp));
56
57 SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
58 auto surface(SkSurface::MakeRenderTarget(context, skgpu::Budgeted::kNo, info));
59 SkCanvas* canvas = surface->getCanvas();
60
61 SkRect r = SkRect::MakeXYWH(10, 10, 100, 100);
62
63 canvas->drawRect(r, p);
64
65 context->abandonContext();
66 }
67
68 // The table color filter uses the texture strip atlas. Make sure abandoning the context works.
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerColorFilterTest,reporter,ctxInfo,CtsEnforcement::kApiLevel_T)69 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerColorFilterTest,
70 reporter,
71 ctxInfo,
72 CtsEnforcement::kApiLevel_T) {
73 auto context = ctxInfo.directContext();
74
75 sk_sp<SkImage> img = GetResourceAsImage("images/mandrill_128.png");
76
77
78 uint8_t identity[256];
79 for (int i = 0; i < 256; i++) {
80 identity[i] = i;
81 }
82
83 SkPaint p;
84 p.setColorFilter(SkColorFilters::Table(identity));
85
86 SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
87 auto surface(SkSurface::MakeRenderTarget(context, skgpu::Budgeted::kNo, info));
88 SkCanvas* canvas = surface->getCanvas();
89
90 canvas->drawImage(std::move(img), 0, 0, SkSamplingOptions(), &p);
91
92 context->abandonContext();
93 }
94