xref: /aosp_15_r20/external/skia/tools/graphite/ProtectedUtils_Graphite.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker  * Copyright 2023 Google LLC
3*c8dee2aaSAndroid Build Coastguard Worker  *
4*c8dee2aaSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
5*c8dee2aaSAndroid Build Coastguard Worker  * found in the LICENSE file.
6*c8dee2aaSAndroid Build Coastguard Worker  */
7*c8dee2aaSAndroid Build Coastguard Worker 
8*c8dee2aaSAndroid Build Coastguard Worker #include "tools/gpu/ProtectedUtils.h"
9*c8dee2aaSAndroid Build Coastguard Worker 
10*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkCanvas.h"
11*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkSurface.h"
12*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkSurfaceProps.h"
13*c8dee2aaSAndroid Build Coastguard Worker #include "tools/gpu/BackendSurfaceFactory.h"
14*c8dee2aaSAndroid Build Coastguard Worker #include "tools/gpu/BackendTextureImageFactory.h"
15*c8dee2aaSAndroid Build Coastguard Worker 
16*c8dee2aaSAndroid Build Coastguard Worker using namespace skgpu;
17*c8dee2aaSAndroid Build Coastguard Worker using namespace skgpu::graphite;
18*c8dee2aaSAndroid Build Coastguard Worker 
19*c8dee2aaSAndroid Build Coastguard Worker namespace ProtectedUtils {
20*c8dee2aaSAndroid Build Coastguard Worker 
CreateProtectedSkSurface(Recorder * recorder,SkISize size,Protected isProtected)21*c8dee2aaSAndroid Build Coastguard Worker sk_sp<SkSurface> CreateProtectedSkSurface(Recorder* recorder,
22*c8dee2aaSAndroid Build Coastguard Worker                                           SkISize size,
23*c8dee2aaSAndroid Build Coastguard Worker                                           Protected isProtected) {
24*c8dee2aaSAndroid Build Coastguard Worker     SkImageInfo ii = SkImageInfo::Make(size, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
25*c8dee2aaSAndroid Build Coastguard Worker 
26*c8dee2aaSAndroid Build Coastguard Worker     sk_sp<SkSurface> surface = sk_gpu_test::MakeBackendTextureSurface(recorder,
27*c8dee2aaSAndroid Build Coastguard Worker                                                                       ii,
28*c8dee2aaSAndroid Build Coastguard Worker                                                                       Mipmapped::kNo,
29*c8dee2aaSAndroid Build Coastguard Worker                                                                       isProtected,
30*c8dee2aaSAndroid Build Coastguard Worker                                                                       /* surfaceProps= */ nullptr);
31*c8dee2aaSAndroid Build Coastguard Worker     if (!surface) {
32*c8dee2aaSAndroid Build Coastguard Worker         SK_ABORT("Could not create %s surface.",
33*c8dee2aaSAndroid Build Coastguard Worker                  isProtected == Protected::kYes ? "protected" : "unprotected");
34*c8dee2aaSAndroid Build Coastguard Worker         return nullptr;
35*c8dee2aaSAndroid Build Coastguard Worker     }
36*c8dee2aaSAndroid Build Coastguard Worker 
37*c8dee2aaSAndroid Build Coastguard Worker     SkCanvas* canvas = surface->getCanvas();
38*c8dee2aaSAndroid Build Coastguard Worker 
39*c8dee2aaSAndroid Build Coastguard Worker     canvas->clear(SkColors::kBlue);
40*c8dee2aaSAndroid Build Coastguard Worker 
41*c8dee2aaSAndroid Build Coastguard Worker     return surface;
42*c8dee2aaSAndroid Build Coastguard Worker }
43*c8dee2aaSAndroid Build Coastguard Worker 
CreateProtectedSkImage(Recorder * recorder,SkISize size,SkColor4f color,Protected isProtected)44*c8dee2aaSAndroid Build Coastguard Worker sk_sp<SkImage> CreateProtectedSkImage(Recorder* recorder,
45*c8dee2aaSAndroid Build Coastguard Worker                                       SkISize size,
46*c8dee2aaSAndroid Build Coastguard Worker                                       SkColor4f color,
47*c8dee2aaSAndroid Build Coastguard Worker                                       Protected isProtected) {
48*c8dee2aaSAndroid Build Coastguard Worker     SkImageInfo ii = SkImageInfo::Make(size, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
49*c8dee2aaSAndroid Build Coastguard Worker 
50*c8dee2aaSAndroid Build Coastguard Worker     sk_sp<SkImage> image = sk_gpu_test::MakeBackendTextureImage(recorder,
51*c8dee2aaSAndroid Build Coastguard Worker                                                                 ii,
52*c8dee2aaSAndroid Build Coastguard Worker                                                                 color,
53*c8dee2aaSAndroid Build Coastguard Worker                                                                 Mipmapped::kNo,
54*c8dee2aaSAndroid Build Coastguard Worker                                                                 Renderable::kNo,
55*c8dee2aaSAndroid Build Coastguard Worker                                                                 Origin::kTopLeft,
56*c8dee2aaSAndroid Build Coastguard Worker                                                                 isProtected);
57*c8dee2aaSAndroid Build Coastguard Worker     if (!image) {
58*c8dee2aaSAndroid Build Coastguard Worker         SK_ABORT("Could not create %s image.",
59*c8dee2aaSAndroid Build Coastguard Worker                  isProtected == Protected::kYes ? "protected" : "unprotected");
60*c8dee2aaSAndroid Build Coastguard Worker         return nullptr;
61*c8dee2aaSAndroid Build Coastguard Worker     }
62*c8dee2aaSAndroid Build Coastguard Worker 
63*c8dee2aaSAndroid Build Coastguard Worker     return image;
64*c8dee2aaSAndroid Build Coastguard Worker }
65*c8dee2aaSAndroid Build Coastguard Worker 
66*c8dee2aaSAndroid Build Coastguard Worker }  // namespace ProtectedUtils
67