GrOpListFlushTest.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/SkSurface.h"
  9. #include "include/gpu/GrContext.h"
  10. #include "src/gpu/GrContextPriv.h"
  11. #include "src/gpu/GrGpu.h"
  12. #include "tests/Test.h"
  13. static bool check_read(skiatest::Reporter* reporter, const SkBitmap& bitmap) {
  14. bool result = true;
  15. for (int x = 0; x < 1000 && result; ++x) {
  16. const uint32_t srcPixel = *bitmap.getAddr32(x, 0);
  17. if (srcPixel != SK_ColorGREEN) {
  18. ERRORF(reporter, "Expected color of Green, but got 0x%08x, at pixel (%d, 0).",
  19. x, srcPixel);
  20. result = false;
  21. }
  22. }
  23. return result;
  24. }
  25. DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrOpListFlushCount, reporter, ctxInfo) {
  26. GrContext* context = ctxInfo.grContext();
  27. GrGpu* gpu = context->priv().getGpu();
  28. SkImageInfo imageInfo = SkImageInfo::Make(1000, 1, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
  29. sk_sp<SkSurface> surface1 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, imageInfo);
  30. if (!surface1) {
  31. return;
  32. }
  33. sk_sp<SkSurface> surface2 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, imageInfo);
  34. if (!surface2) {
  35. return;
  36. }
  37. SkCanvas* canvas1 = surface1->getCanvas();
  38. SkCanvas* canvas2 = surface2->getCanvas();
  39. canvas1->clear(SK_ColorRED);
  40. canvas2->clear(SK_ColorRED);
  41. SkIRect srcRect = SkIRect::MakeWH(1, 1);
  42. SkRect dstRect = SkRect::MakeWH(1, 1);
  43. SkPaint paint;
  44. paint.setColor(SK_ColorGREEN);
  45. canvas1->drawRect(dstRect, paint);
  46. for (int i = 0; i < 1000; ++i) {
  47. srcRect.fLeft = i;
  48. srcRect.fRight = srcRect.fLeft + 1;
  49. sk_sp<SkImage> image = surface1->makeImageSnapshot();
  50. canvas2->drawImageRect(image.get(), srcRect, dstRect, nullptr);
  51. if (i != 999) {
  52. dstRect.fLeft = i+1;
  53. dstRect.fRight = dstRect.fLeft + 1;
  54. image = surface2->makeImageSnapshot();
  55. canvas1->drawImageRect(image.get(), srcRect, dstRect, nullptr);
  56. }
  57. }
  58. context->flush();
  59. // In total we make 2000 oplists. Our current limit on max oplists between flushes is 100, so we
  60. // should do 20 flushes while executing oplists. Additionaly we always do 1 flush at the end of
  61. // executing all oplists. So in total we should see 21 flushes here.
  62. REPORTER_ASSERT(reporter, gpu->stats()->numFinishFlushes() == 21);
  63. SkBitmap readbackBitmap;
  64. readbackBitmap.allocN32Pixels(1000, 1);
  65. REPORTER_ASSERT(reporter, surface1->readPixels(readbackBitmap, 0, 0));
  66. REPORTER_ASSERT(reporter, check_read(reporter, readbackBitmap));
  67. REPORTER_ASSERT(reporter, surface2->readPixels(readbackBitmap, 0, 0));
  68. REPORTER_ASSERT(reporter, check_read(reporter, readbackBitmap));
  69. }