blob: 31d8e4c67e88e7e8edba7c7a7ae5539105a71e40 [file] [log] [blame]
Brian Salomon24069eb2020-06-24 10:19:52 -04001/*
2 * Copyright 2020 Google LLC
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#include "include/core/SkCanvas.h"
9#include "include/core/SkImageInfo.h"
10#include "include/core/SkPaint.h"
11#include "include/core/SkRect.h"
12#include "include/core/SkSurface.h"
Robert Phillips6d344c32020-07-06 10:56:46 -040013#include "include/gpu/GrDirectContext.h"
Brian Salomon24069eb2020-06-24 10:19:52 -040014#include "tests/Test.h"
15
16DEF_GPUTEST(GrContext_oomed, reporter, originalOptions) {
17 GrContextOptions options = originalOptions;
18 options.fRandomGLOOM = true;
19 options.fSkipGLErrorChecks = GrContextOptions::Enable::kNo;
20 sk_gpu_test::GrContextFactory factory(options);
21 for (int ct = 0; ct < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++ct) {
22 auto contextType = static_cast<sk_gpu_test::GrContextFactory::ContextType>(ct);
Robert Phillips6d344c32020-07-06 10:56:46 -040023 auto context = factory.get(contextType);
Brian Salomon24069eb2020-06-24 10:19:52 -040024 if (!context) {
25 continue;
26 }
27 if (context->backend() != GrBackendApi::kOpenGL) {
28 continue;
29 }
30 auto info = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
31 for (int run = 0; run < 20; ++run) {
32 bool oomed = false;
33 for (int i = 0; i < 500; ++i) {
34 // Make sure we're actually making a significant number of GL calls and not just
35 // issuing a small number calls by reusing scratch resources created in a previous
36 // iteration.
37 context->freeGpuResources();
38 auto surf =
39 SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 1, nullptr);
40 SkPaint paint;
41 surf->getCanvas()->drawRect(SkRect::MakeLTRB(100, 100, 2000, 2000), paint);
42 surf->flushAndSubmit();
43 if ((oomed = context->oomed())) {
44 REPORTER_ASSERT(reporter, !context->oomed(), "oomed() wasn't cleared");
45 break;
46 }
47 }
48 if (!oomed) {
49 ERRORF(reporter, "Did not OOM on %dth run.", run);
50 }
51 }
52 }
53}