| 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/core/SkCanvas.h" |
| 11 |
#include "include/core/SkSurface.h" |
| 12 |
#include "include/core/SkSurfaceProps.h" |
| 13 |
#include "tools/gpu/BackendSurfaceFactory.h" |
| 14 |
#include "tools/gpu/BackendTextureImageFactory.h" |
| 15 |
|
| 16 |
using namespace skgpu; |
| 17 |
using namespace skgpu::graphite; |
| 18 |
|
| 19 |
namespace ProtectedUtils { |
| 20 |
|
| 21 |
sk_sp<SkSurface> CreateProtectedSkSurface(Recorder* recorder, |
| 22 |
SkISize size, |
| 23 |
Protected isProtected) { |
| 24 |
SkImageInfo ii = SkImageInfo::Make(size, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 25 |
|
| 26 |
sk_sp<SkSurface> surface = sk_gpu_test::MakeBackendTextureSurface(recorder, |
| 27 |
ii, |
| 28 |
Mipmapped::kNo, |
| 29 |
isProtected, |
| 30 |
/* surfaceProps= */ nullptr); |
| 31 |
if (!surface) { |
| 32 |
SK_ABORT("Could not create %s surface.", |
| 33 |
isProtected == Protected::kYes ? "protected" : "unprotected"); |
| 34 |
return nullptr; |
| 35 |
} |
| 36 |
|
| 37 |
SkCanvas* canvas = surface->getCanvas(); |
| 38 |
|
| 39 |
canvas->clear(SkColors::kBlue); |
| 40 |
|
| 41 |
return surface; |
| 42 |
} |
| 43 |
|
| 44 |
sk_sp<SkImage> CreateProtectedSkImage(Recorder* recorder, |
| 45 |
SkISize size, |
| 46 |
SkColor4f color, |
| 47 |
Protected isProtected) { |
| 48 |
SkImageInfo ii = SkImageInfo::Make(size, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 49 |
|
| 50 |
sk_sp<SkImage> image = sk_gpu_test::MakeBackendTextureImage(recorder, |
| 51 |
ii, |
| 52 |
color, |
| 53 |
Mipmapped::kNo, |
| 54 |
Renderable::kNo, |
| 55 |
Origin::kTopLeft, |
| 56 |
isProtected); |
| 57 |
if (!image) { |
| 58 |
SK_ABORT("Could not create %s image.", |
| 59 |
isProtected == Protected::kYes ? "protected" : "unprotected"); |
| 60 |
return nullptr; |
| 61 |
} |
| 62 |
|
| 63 |
return image; |
| 64 |
} |
| 65 |
|
| 66 |
} // namespace ProtectedUtils |