TextureStripAtlasManagerTest.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include "include/core/SkCanvas.h"
  8. #include "include/core/SkPaint.h"
  9. #include "include/core/SkSurface.h"
  10. #include "include/effects/SkGradientShader.h"
  11. #include "include/effects/SkTableColorFilter.h"
  12. #include "tests/Test.h"
  13. #include "tools/Resources.h"
  14. // The gradient shader will use the texture strip atlas if it has too many colors. Make sure
  15. // abandoning the context works.
  16. DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerGradientTest, reporter, ctxInfo) {
  17. GrContext* context = ctxInfo.grContext();
  18. static const SkColor gColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
  19. SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
  20. SK_ColorBLACK };
  21. static const SkScalar gPos[] = { 0, 0.17f, 0.32f, 0.49f, 0.66f, 0.83f, 1.0f };
  22. SkPaint p;
  23. p.setShader(SkGradientShader::MakeTwoPointConical(SkPoint::Make(0, 0),
  24. 1.0f,
  25. SkPoint::Make(10.0f, 20.0f),
  26. 2.0f,
  27. gColors,
  28. gPos,
  29. 7,
  30. SkTileMode::kClamp));
  31. SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
  32. auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
  33. SkCanvas* canvas = surface->getCanvas();
  34. SkRect r = SkRect::MakeXYWH(10, 10, 100, 100);
  35. canvas->drawRect(r, p);
  36. context->abandonContext();
  37. }
  38. // The table color filter uses the texture strip atlas. Make sure abandoning the context works.
  39. DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureStripAtlasManagerColorFilterTest, reporter, ctxInfo) {
  40. GrContext* context = ctxInfo.grContext();
  41. sk_sp<SkImage> img = GetResourceAsImage("images/mandrill_128.png");
  42. uint8_t identity[256];
  43. for (int i = 0; i < 256; i++) {
  44. identity[i] = i;
  45. }
  46. SkPaint p;
  47. p.setColorFilter(SkTableColorFilter::Make(identity));
  48. SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
  49. auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
  50. SkCanvas* canvas = surface->getCanvas();
  51. canvas->drawImage(std::move(img), 0, 0, &p);
  52. context->abandonContext();
  53. }