2018-03-19 14:57:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "include/effects/SkTableColorFilter.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2018-03-19 14:57:42 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/Resources.h"
|
2018-03-19 14:57:42 +00:00
|
|
|
|
|
|
|
// The gradient shader will use the texture strip atlas if it has too many colors. Make sure
|
|
|
|
// abandoning the context works.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerGradientTest, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2018-03-19 14:57:42 +00:00
|
|
|
|
|
|
|
static const SkColor gColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
|
|
|
|
SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
|
|
|
|
SK_ColorBLACK };
|
|
|
|
static const SkScalar gPos[] = { 0, 0.17f, 0.32f, 0.49f, 0.66f, 0.83f, 1.0f };
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setShader(SkGradientShader::MakeTwoPointConical(SkPoint::Make(0, 0),
|
|
|
|
1.0f,
|
|
|
|
SkPoint::Make(10.0f, 20.0f),
|
|
|
|
2.0f,
|
|
|
|
gColors,
|
|
|
|
gPos,
|
|
|
|
7,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode::kClamp));
|
2018-03-19 14:57:42 +00:00
|
|
|
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
|
|
|
|
auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
|
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
|
|
|
|
SkRect r = SkRect::MakeXYWH(10, 10, 100, 100);
|
|
|
|
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
|
|
|
|
context->abandonContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The table color filter uses the texture strip atlas. Make sure abandoning the context works.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerColorFilterTest, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2018-03-19 14:57:42 +00:00
|
|
|
|
|
|
|
sk_sp<SkImage> img = GetResourceAsImage("images/mandrill_128.png");
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t identity[256];
|
|
|
|
for (int i = 0; i < 256; i++) {
|
|
|
|
identity[i] = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColorFilter(SkTableColorFilter::Make(identity));
|
|
|
|
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
|
|
|
|
auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
|
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
|
2021-01-28 02:21:08 +00:00
|
|
|
canvas->drawImage(std::move(img), 0, 0, SkSamplingOptions(), &p);
|
2018-03-19 14:57:42 +00:00
|
|
|
|
|
|
|
context->abandonContext();
|
|
|
|
}
|