Coverage Report

Created: 2024-05-20 07:14

/src/skia/tools/gpu/ProtectedUtils.cpp
Line
Count
Source (jump to first uncovered line)
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
8
#include "tools/gpu/ProtectedUtils.h"
9
10
#include "include/gpu/ganesh/SkImageGanesh.h"
11
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
12
#include "src/gpu/ganesh/GrDirectContextPriv.h"
13
#include "tools/gpu/BackendSurfaceFactory.h"
14
#include "tools/gpu/BackendTextureImageFactory.h"
15
16
namespace ProtectedUtils {
17
18
sk_sp<SkSurface> CreateProtectedSkSurface(GrDirectContext* dContext,
19
                                          SkISize size,
20
                                          bool textureable,
21
                                          bool isProtected,
22
0
                                          const SkSurfaceProps* surfaceProps) {
23
0
    sk_sp<SkSurface> surface;
24
0
    if (textureable) {
25
0
        surface = sk_gpu_test::MakeBackendTextureSurface(dContext,
26
0
                                                         size,
27
0
                                                         kTopLeft_GrSurfaceOrigin,
28
0
                                                         1,
29
0
                                                         kRGBA_8888_SkColorType,
30
0
                                                         /* colorSpace= */ nullptr,
31
0
                                                         skgpu::Mipmapped::kNo,
32
0
                                                         skgpu::Protected(isProtected),
33
0
                                                         surfaceProps);
34
0
    } else {
35
0
        surface = sk_gpu_test::MakeBackendRenderTargetSurface(dContext,
36
0
                                                              size,
37
0
                                                              kTopLeft_GrSurfaceOrigin,
38
0
                                                              1,
39
0
                                                              kRGBA_8888_SkColorType,
40
0
                                                              /* colorSpace= */ nullptr,
41
0
                                                              skgpu::Protected(isProtected),
42
0
                                                              surfaceProps);
43
0
    }
44
0
    if (!surface) {
45
0
        SK_ABORT("Could not create %s surface.", isProtected ? "protected" : "unprotected");
46
0
        return nullptr;
47
0
    }
48
49
0
    SkCanvas* canvas = surface->getCanvas();
50
51
0
    canvas->clear(SkColors::kBlue);
52
53
0
    if (textureable) {
54
0
        GrBackendTexture backendTex = SkSurfaces::GetBackendTexture(
55
0
                surface.get(), SkSurfaces::BackendHandleAccess::kFlushRead);
56
0
        SkASSERT(backendTex.isValid());
57
0
        SkASSERT(backendTex.isProtected() == isProtected);
58
0
    } else {
59
0
        GrBackendRenderTarget backendRT = SkSurfaces::GetBackendRenderTarget(
60
0
                surface.get(), SkSurfaces::BackendHandleAccess::kFlushRead);
61
0
        SkASSERT(backendRT.isValid());
62
0
        SkASSERT(backendRT.isProtected() == isProtected);
63
0
    }
64
65
0
    return surface;
66
0
}
Unexecuted instantiation: ProtectedUtils::CreateProtectedSkSurface(GrDirectContext*, SkISize, bool, bool, SkSurfaceProps const*)
Unexecuted instantiation: ProtectedUtils::CreateProtectedSkSurface(GrDirectContext*, SkISize, bool, bool, SkSurfaceProps const*)
67
68
0
void CheckImageBEProtection(SkImage* image, bool expectingProtected) {
69
0
    GrBackendTexture beTex;
70
0
    GrSurfaceOrigin origin;
71
0
    bool result = SkImages::GetBackendTextureFromImage(image,
72
0
                                                       &beTex,
73
0
                                                       /* flushPendingGrContextIO= */ true,
74
0
                                                       &origin);
75
0
    if (!result) {
76
0
        SK_ABORT("GetBackendTextureFromImage failed");
77
0
        return;
78
0
    }
79
80
0
    SkASSERT(beTex.isValid());
81
0
    SkASSERT(beTex.isProtected() == expectingProtected);
82
0
}
Unexecuted instantiation: ProtectedUtils::CheckImageBEProtection(SkImage*, bool)
Unexecuted instantiation: ProtectedUtils::CheckImageBEProtection(SkImage*, bool)
83
84
sk_sp<SkImage> CreateProtectedSkImage(GrDirectContext* dContext,
85
                                      SkISize size,
86
                                      SkColor4f color,
87
0
                                      bool isProtected) {
88
0
    SkImageInfo ii = SkImageInfo::Make(size, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
89
90
0
    sk_sp<SkImage> image = sk_gpu_test::MakeBackendTextureImage(dContext,
91
0
                                                                ii,
92
0
                                                                color,
93
0
                                                                skgpu::Mipmapped::kNo,
94
0
                                                                GrRenderable::kNo,
95
0
                                                                kTopLeft_GrSurfaceOrigin,
96
0
                                                                skgpu::Protected(isProtected));
97
0
    if (!image) {
98
0
        SK_ABORT("Could not create %s image.", isProtected ? "protected" : "unprotected");
99
0
        return nullptr;
100
0
    }
101
102
0
    CheckImageBEProtection(image.get(), isProtected);
103
104
0
    return image;
105
0
}
106
107
}  // namespace ProtectedUtils