skia2/tests/GrOpListFlushTest.cpp

86 lines
3.1 KiB
C++
Raw Normal View History

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "src/gpu/GrDirectContextPriv.h"
#include "src/gpu/GrGpu.h"
#include "tests/Test.h"
static bool check_read(skiatest::Reporter* reporter, const SkBitmap& bitmap) {
bool result = true;
for (int x = 0; x < 1000 && result; ++x) {
const uint32_t srcPixel = *bitmap.getAddr32(x, 0);
if (srcPixel != SK_ColorGREEN) {
ERRORF(reporter, "Expected color of Green, but got 0x%08x, at pixel (%d, 0).",
x, srcPixel);
result = false;
}
}
return result;
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(OpsTaskFlushCount, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
GrGpu* gpu = context->priv().getGpu();
SkImageInfo imageInfo = SkImageInfo::Make(1000, 1, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
sk_sp<SkSurface> surface1 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, imageInfo);
if (!surface1) {
return;
}
sk_sp<SkSurface> surface2 = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, imageInfo);
if (!surface2) {
return;
}
SkCanvas* canvas1 = surface1->getCanvas();
SkCanvas* canvas2 = surface2->getCanvas();
canvas1->clear(SK_ColorRED);
canvas2->clear(SK_ColorRED);
SkRect srcRect = SkRect::MakeWH(1, 1);
SkRect dstRect = SkRect::MakeWH(1, 1);
SkPaint paint;
paint.setColor(SK_ColorGREEN);
canvas1->drawRect(dstRect, paint);
for (int i = 0; i < 1000; ++i) {
srcRect.fLeft = i;
srcRect.fRight = srcRect.fLeft + 1;
sk_sp<SkImage> image = surface1->makeImageSnapshot();
canvas2->drawImageRect(image.get(), srcRect, dstRect, SkSamplingOptions(), nullptr,
SkCanvas::kStrict_SrcRectConstraint);
if (i != 999) {
dstRect.fLeft = i+1;
dstRect.fRight = dstRect.fLeft + 1;
image = surface2->makeImageSnapshot();
canvas1->drawImageRect(image.get(), srcRect, dstRect, SkSamplingOptions(), nullptr,
SkCanvas::kStrict_SrcRectConstraint);
}
}
context->flushAndSubmit();
// In total we make 2000 oplists. Our current limit on max oplists between flushes is 100, so we
// should do 20 flushes while executing oplists. Additionaly we always do 1 flush at the end of
// executing all oplists. So in total we should see 21 flushes here.
Reland "Split apart flushing and submitting in the GrGpu classes and GrDrawingManager." This reverts commit 2faa33772be498c21e014155608036a903647891. Reason for revert: <INSERT REASONING HERE> Original change's description: > Revert "Split apart flushing and submitting in the GrGpu classes and GrDrawingManager." > > This reverts commit 6341d92280f09f8d892b6c51c1eca53dcd1c205f. > > Reason for revert: metal tests failing > > Original change's description: > > Split apart flushing and submitting in the GrGpu classes and GrDrawingManager. > > > > Bug: skia:10118 > > Change-Id: I53e3b9f1bd28a00276a3d35b5160aa0cfec30cfd > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/282417 > > Reviewed-by: Jim Van Verth <jvanverth@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,jvanverth@google.com,bsalomon@google.com,senorblanco@chromium.org > > Change-Id: I2cb98b470e3a066c09012b686e9942edb5a3979b > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10118 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/282852 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> Bug: skia:10118 Change-Id: I9a77abe995a991275a87ee1d38bcab4deb361a9d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/282976 Reviewed-by: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2020-04-10 17:43:51 +00:00
REPORTER_ASSERT(reporter, gpu->stats()->numSubmitToGpus() == 21);
SkBitmap readbackBitmap;
readbackBitmap.allocN32Pixels(1000, 1);
REPORTER_ASSERT(reporter, surface1->readPixels(readbackBitmap, 0, 0));
REPORTER_ASSERT(reporter, check_read(reporter, readbackBitmap));
REPORTER_ASSERT(reporter, surface2->readPixels(readbackBitmap, 0, 0));
REPORTER_ASSERT(reporter, check_read(reporter, readbackBitmap));
}