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 "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 // The gradient shader will use the texture strip atlas if it has too many colors. Make sure 19 // abandoning the context works. 20 DEF_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, 36 SkShader::kClamp_TileMode)); 37 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. 50 DEF_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 } 72