2018-12-07 16:20:33 +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.
|
|
|
|
*/
|
|
|
|
|
2020-12-23 15:11:33 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrGpu.h"
|
|
|
|
#include "tests/Test.h"
|
2018-12-07 16:20:33 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-22 20:19:24 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrOpsTaskFlushCount, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto context = ctxInfo.directContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2018-12-07 16:20:33 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
SkIRect srcRect = SkIRect::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, nullptr);
|
|
|
|
if (i != 999) {
|
|
|
|
dstRect.fLeft = i+1;
|
|
|
|
dstRect.fRight = dstRect.fLeft + 1;
|
|
|
|
image = surface2->makeImageSnapshot();
|
|
|
|
canvas1->drawImageRect(image.get(), srcRect, dstRect, nullptr);
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 19:45:44 +00:00
|
|
|
context->flushAndSubmit();
|
2018-12-07 16:20:33 +00:00
|
|
|
|
|
|
|
// 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.
|
2020-04-10 17:43:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, gpu->stats()->numSubmitToGpus() == 21);
|
2018-12-07 16:20:33 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|