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