Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ProtectedUtils.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 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
9
15
16namespace ProtectedUtils {
17
19 SkISize size,
20 bool textureable,
21 bool isProtected,
22 const SkSurfaceProps* surfaceProps) {
24 if (textureable) {
26 size,
28 1,
30 /* colorSpace= */ nullptr,
31 skgpu::Mipmapped::kNo,
32 skgpu::Protected(isProtected),
33 surfaceProps);
34 } else {
36 size,
38 1,
40 /* colorSpace= */ nullptr,
41 skgpu::Protected(isProtected),
42 surfaceProps);
43 }
44 if (!surface) {
45 SK_ABORT("Could not create %s surface.", isProtected ? "protected" : "unprotected");
46 return nullptr;
47 }
48
49 SkCanvas* canvas = surface->getCanvas();
50
51 canvas->clear(SkColors::kBlue);
52
53 if (textureable) {
55 surface.get(), SkSurfaces::BackendHandleAccess::kFlushRead);
56 SkASSERT(backendTex.isValid());
57 SkASSERT(backendTex.isProtected() == isProtected);
58 } else {
60 surface.get(), SkSurfaces::BackendHandleAccess::kFlushRead);
61 SkASSERT(backendRT.isValid());
62 SkASSERT(backendRT.isProtected() == isProtected);
63 }
64
65 return surface;
66}
67
68void CheckImageBEProtection(SkImage* image, bool expectingProtected) {
69 GrBackendTexture beTex;
70 GrSurfaceOrigin origin;
72 &beTex,
73 /* flushPendingGrContextIO= */ true,
74 &origin);
75 if (!result) {
76 SK_ABORT("GetBackendTextureFromImage failed");
77 return;
78 }
79
80 SkASSERT(beTex.isValid());
81 SkASSERT(beTex.isProtected() == expectingProtected);
82}
83
85 SkISize size,
87 bool isProtected) {
89
90 sk_sp<SkImage> image = sk_gpu_test::MakeBackendTextureImage(dContext,
91 ii,
92 color,
93 skgpu::Mipmapped::kNo,
94 GrRenderable::kNo,
96 skgpu::Protected(isProtected));
97 if (!image) {
98 SK_ABORT("Could not create %s image.", isProtected ? "protected" : "unprotected");
99 return nullptr;
100 }
101
102 CheckImageBEProtection(image.get(), isProtected);
103
104 return image;
105}
106
107} // namespace ProtectedUtils
GrSurfaceOrigin
Definition GrTypes.h:147
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
SkColor4f color
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SK_ABORT(message,...)
Definition SkAssert.h:70
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
void clear(SkColor color)
Definition SkCanvas.h:1199
T * get() const
Definition SkRefCnt.h:303
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkImage > image
Definition examples.cpp:29
GAsyncResult * result
sk_sp< SkSurface > CreateProtectedSkSurface(GrDirectContext *dContext, SkISize size, bool textureable, bool isProtected, const SkSurfaceProps *surfaceProps)
sk_sp< SkImage > CreateProtectedSkImage(GrDirectContext *dContext, SkISize size, SkColor4f color, bool isProtected)
void CheckImageBEProtection(SkImage *image, bool expectingProtected)
constexpr SkColor4f kBlue
Definition SkColor.h:442
SK_API bool GetBackendTextureFromImage(const SkImage *img, GrBackendTexture *outTexture, bool flushPendingGrContextIO, GrSurfaceOrigin *origin=nullptr)
SK_API GrBackendTexture GetBackendTexture(SkSurface *, BackendHandleAccess)
SK_API GrBackendRenderTarget GetBackendRenderTarget(SkSurface *, BackendHandleAccess)
sk_sp< SkSurface > MakeBackendRenderTargetSurface(GrDirectContext *dContext, const SkImageInfo &ii, GrSurfaceOrigin origin, int sampleCnt, GrProtected isProtected, const SkSurfaceProps *props)
sk_sp< SkSurface > MakeBackendTextureSurface(GrDirectContext *dContext, const SkImageInfo &ii, GrSurfaceOrigin origin, int sampleCnt, skgpu::Mipmapped mipmapped, GrProtected isProtected, const SkSurfaceProps *props)
Protected
Definition GpuTypes.h:61
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)