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
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"
14 #include "include/gpu/GrDirectContext.h"
15
16 #include "tests/Test.h"
17 #include "tools/Resources.h"
18
19 // The gradient shader will use the texture strip atlas if it has too many colors. Make sure
20 // abandoning the context works.
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerGradientTest,reporter,ctxInfo)21 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerGradientTest, reporter, ctxInfo) {
22 auto context = ctxInfo.directContext();
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,
37 SkTileMode::kClamp));
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.
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerColorFilterTest,reporter,ctxInfo)51 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerColorFilterTest, reporter, ctxInfo) {
52 auto context = ctxInfo.directContext();
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
69 canvas->drawImage(std::move(img), 0, 0, SkSamplingOptions(), &p);
70
71 context->abandonContext();
72 }
73