Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / tests / GrDDLImageTest.cpp
1 /*
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/SkBitmap.h"
9 #include "include/core/SkImage.h"
10 #include "include/core/SkSurface.h"
11 #include "include/core/SkSurfaceCharacterization.h"
12 #include "tests/Test.h"
13
14 DEF_GPUTEST(GrDDLImage_MakeSubset, reporter, options) {
15     sk_gpu_test::GrContextFactory factory(options);
16     for (int ct = 0; ct < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++ct) {
17         auto contextType = static_cast<sk_gpu_test::GrContextFactory::ContextType>(ct);
18         auto dContext = factory.get(contextType);
19         if (!dContext) {
20             continue;
21         }
22         SkIRect subsetBounds = SkIRect::MakeLTRB(4,4,8,8);
23         SkImageInfo ii = SkImageInfo::Make(16, 16, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
24
25         // Raster image:
26         SkBitmap bm;
27         bm.setInfo(ii);
28         bm.allocPixels();
29         bm.eraseColor(SK_ColorBLACK);
30         bm.setImmutable();
31         auto rasterImg = bm.asImage();
32         REPORTER_ASSERT(reporter, rasterImg->isValid(static_cast<GrRecordingContext*>(nullptr)));
33
34         // raster + context:
35         auto subImg1 = rasterImg->makeSubset(subsetBounds, dContext);
36         REPORTER_ASSERT(reporter, subImg1->isValid(dContext));
37
38         // raster + no context:
39         auto subImg2 = rasterImg->makeSubset(subsetBounds, nullptr);
40         REPORTER_ASSERT(reporter, subImg2->isValid(static_cast<GrRecordingContext*>(nullptr)));
41
42         // Texture image:
43         auto surf = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, ii);
44         SkSurfaceCharacterization sc;
45         REPORTER_ASSERT(reporter, surf->characterize(&sc));
46         GrBackendTexture tex =
47                 dContext->createBackendTexture(ii.width(), ii.height(), ii.colorType(),
48                                                GrMipmapped(sc.isMipMapped()), GrRenderable::kYes);
49         auto gpuImage = SkImage::MakeFromTexture(dContext, tex, kTopLeft_GrSurfaceOrigin,
50                                                  ii.colorType(), ii.alphaType(),
51                                                  ii.refColorSpace());
52         REPORTER_ASSERT(reporter, gpuImage->isValid(dContext));
53
54         // gpu image + context:
55         auto subImg5 = gpuImage->makeSubset(subsetBounds, dContext);
56         REPORTER_ASSERT(reporter, subImg5->isValid(dContext));
57
58         // gpu image + nullptr:
59         REPORTER_ASSERT(reporter, !gpuImage->makeSubset(subsetBounds, nullptr));
60
61         dContext->flush();
62         dContext->submit(true);
63         dContext->deleteBackendTexture(tex);
64     }
65 }