Flutter Engine
The Flutter Engine
Functions
GrDDLImageTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrTypes.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/private/chromium/GrSurfaceCharacterization.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/gpu/ContextType.h"

Go to the source code of this file.

Functions

 DEF_GANESH_TEST (GrDDLImage_MakeSubset, reporter, options, CtsEnforcement::kApiLevel_T)
 

Function Documentation

◆ DEF_GANESH_TEST()

DEF_GANESH_TEST ( GrDDLImage_MakeSubset  ,
reporter  ,
options  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 33 of file GrDDLImageTest.cpp.

33 {
34 using namespace skgpu;
35
37 for (int ct = 0; ct < skgpu::kContextTypeCount; ++ct) {
38 auto contextType = static_cast<skgpu::ContextType>(ct);
39 auto dContext = factory.get(contextType);
40 if (!dContext) {
41 continue;
42 }
43
44 Protected isProtected = Protected(dContext->priv().caps()->supportsProtectedContent());
45
46 SkIRect subsetBounds = SkIRect::MakeLTRB(4,4,8,8);
48
49 // Raster image:
50 SkBitmap bm;
51 bm.setInfo(ii);
52 bm.allocPixels();
54 bm.setImmutable();
55 auto rasterImg = bm.asImage();
56 REPORTER_ASSERT(reporter, rasterImg->isValid(static_cast<GrRecordingContext*>(nullptr)));
57
58 // raster + context:
59 auto subImg1 = rasterImg->makeSubset(dContext, subsetBounds);
60 REPORTER_ASSERT(reporter, subImg1->isValid(dContext));
61
62 // raster + no context:
63 auto subImg2 = rasterImg->makeSubset(nullptr, subsetBounds);
64 REPORTER_ASSERT(reporter, subImg2->isValid(static_cast<GrRecordingContext*>(nullptr)));
65
66 // Texture image:
67 auto surf = SkSurfaces::RenderTarget(dContext, skgpu::Budgeted::kNo, ii);
69 REPORTER_ASSERT(reporter, surf->characterize(&sc));
70 GrBackendTexture tex = dContext->createBackendTexture(ii.width(),
71 ii.height(),
72 ii.colorType(),
75 isProtected);
76 auto gpuImage = SkImages::BorrowTextureFrom(dContext,
77 tex,
79 ii.colorType(),
80 ii.alphaType(),
81 ii.refColorSpace());
82 REPORTER_ASSERT(reporter, gpuImage->isValid(dContext));
83
84 // gpu image + context:
85 auto subImg5 = gpuImage->makeSubset(dContext, subsetBounds);
86 REPORTER_ASSERT(reporter, subImg5->isValid(dContext));
87
88 // gpu image + nullptr:
89 REPORTER_ASSERT(reporter, !gpuImage->makeSubset(nullptr, subsetBounds));
90
91 dContext->flush();
92 dContext->submit(GrSyncCpu::kYes);
93 dContext->deleteBackendTexture(tex);
94 }
95}
const char * options
reporter
Definition: FontMgrTest.cpp:39
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
skgpu::Protected Protected
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void setImmutable()
Definition: SkBitmap.cpp:400
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Definition: SkBitmap.cpp:114
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
SK_API sk_sp< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
Definition: GpuTools.h:21
static const int kContextTypeCount
Definition: ContextType.h:42
ContextType
Definition: ContextType.h:19
Mipmapped
Definition: GpuTypes.h:53
Protected
Definition: GpuTypes.h:61
Definition: SkRect.h:32
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition: SkRect.h:91
sk_sp< SkColorSpace > refColorSpace() const
int width() const
Definition: SkImageInfo.h:365
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkAlphaType alphaType() const
Definition: SkImageInfo.h:375
SkColorType colorType() const
Definition: SkImageInfo.h:373
int height() const
Definition: SkImageInfo.h:371