blob: d03529f1201f31473e0e15973a064b2ae2ac03b0 [file] [log] [blame]
Robert Phillips96b6d532018-03-19 10:57:42 -04001/*
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 "SkCanvas.h"
10#include "SkGradientShader.h"
11#include "SkPaint.h"
12#include "SkSurface.h"
13#include "SkTableColorFilter.h"
14
15#include "Resources.h"
16#include "Test.h"
17
18#if SK_SUPPORT_GPU // These are all GPU-backend specific tests
19
20
21// The gradient shader will use the texture strip atlas if it has too many colors. Make sure
22// abandoning the context works.
23DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerGradientTest, reporter, ctxInfo) {
24 GrContext* context = ctxInfo.grContext();
25
26 static const SkColor gColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
27 SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
28 SK_ColorBLACK };
29 static const SkScalar gPos[] = { 0, 0.17f, 0.32f, 0.49f, 0.66f, 0.83f, 1.0f };
30
31 SkPaint p;
32 p.setShader(SkGradientShader::MakeTwoPointConical(SkPoint::Make(0, 0),
33 1.0f,
34 SkPoint::Make(10.0f, 20.0f),
35 2.0f,
36 gColors,
37 gPos,
38 7,
39 SkShader::kClamp_TileMode));
40
41 SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
42 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
43 SkCanvas* canvas = surface->getCanvas();
44
45 SkRect r = SkRect::MakeXYWH(10, 10, 100, 100);
46
47 canvas->drawRect(r, p);
48
49 context->abandonContext();
50}
51
52// The table color filter uses the texture strip atlas. Make sure abandoning the context works.
53DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerColorFilterTest, reporter, ctxInfo) {
54 GrContext* context = ctxInfo.grContext();
55
56 sk_sp<SkImage> img = GetResourceAsImage("images/mandrill_128.png");
57
58
59 uint8_t identity[256];
60 for (int i = 0; i < 256; i++) {
61 identity[i] = i;
62 }
63
64 SkPaint p;
65 p.setColorFilter(SkTableColorFilter::Make(identity));
66
67 SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
68 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
69 SkCanvas* canvas = surface->getCanvas();
70
71 canvas->drawImage(std::move(img), 0, 0, &p);
72
73 context->abandonContext();
74}
75
76#endif