blob: bfead52bf58b36efb813c7ff22f4f90eb89366b8 [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 Phillips6d344c32020-07-06 10:56:46 -040014#include "include/gpu/GrDirectContext.h"
Robert Phillips96b6d532018-03-19 10:57:42 -040015
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "tests/Test.h"
17#include "tools/Resources.h"
Robert Phillips96b6d532018-03-19 10:57:42 -040018
Robert Phillips96b6d532018-03-19 10:57:42 -040019// The gradient shader will use the texture strip atlas if it has too many colors. Make sure
20// abandoning the context works.
21DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerGradientTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -040022 auto context = ctxInfo.directContext();
Robert Phillips96b6d532018-03-19 10:57:42 -040023
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 Reedfae8fce2019-04-03 10:27:45 -040037 SkTileMode::kClamp));
Robert Phillips96b6d532018-03-19 10:57:42 -040038
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.
51DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerColorFilterTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -040052 auto context = ctxInfo.directContext();
Robert Phillips96b6d532018-03-19 10:57:42 -040053
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, &p);
70
71 context->abandonContext();
72}