1 | /* |
---|---|
2 | * Copyright 2020 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 | #ifndef GrBackendUtils_DEFINED |
9 | #define GrBackendUtils_DEFINED |
10 | |
11 | #include "include/core/SkImage.h" |
12 | |
13 | #include "include/gpu/GrBackendSurface.h" |
14 | |
15 | #ifdef SK_METAL |
16 | #include "src/gpu/mtl/GrMtlCppUtil.h" |
17 | #endif |
18 | |
19 | static SkImage::CompressionType GrBackendFormatToCompressionType(const GrBackendFormat& format) { |
20 | switch (format.backend()) { |
21 | case GrBackendApi::kOpenGL: { |
22 | #ifdef SK_GL |
23 | GrGLFormat glFormat = format.asGLFormat(); |
24 | switch (glFormat) { |
25 | case GrGLFormat::kCOMPRESSED_ETC1_RGB8: |
26 | case GrGLFormat::kCOMPRESSED_RGB8_ETC2: |
27 | return SkImage::CompressionType::kETC2_RGB8_UNORM; |
28 | case GrGLFormat::kCOMPRESSED_RGB8_BC1: |
29 | return SkImage::CompressionType::kBC1_RGB8_UNORM; |
30 | case GrGLFormat::kCOMPRESSED_RGBA8_BC1: |
31 | return SkImage::CompressionType::kBC1_RGBA8_UNORM; |
32 | default: |
33 | return SkImage::CompressionType::kNone; |
34 | } |
35 | #endif |
36 | break; |
37 | } |
38 | case GrBackendApi::kVulkan: { |
39 | #ifdef SK_VULKAN |
40 | VkFormat vkFormat; |
41 | SkAssertResult(format.asVkFormat(&vkFormat)); |
42 | switch (vkFormat) { |
43 | case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: |
44 | return SkImage::CompressionType::kETC2_RGB8_UNORM; |
45 | case VK_FORMAT_BC1_RGB_UNORM_BLOCK: |
46 | return SkImage::CompressionType::kBC1_RGB8_UNORM; |
47 | case VK_FORMAT_BC1_RGBA_UNORM_BLOCK: |
48 | return SkImage::CompressionType::kBC1_RGBA8_UNORM; |
49 | default: |
50 | return SkImage::CompressionType::kNone; |
51 | } |
52 | #endif |
53 | break; |
54 | } |
55 | case GrBackendApi::kMetal: { |
56 | #ifdef SK_METAL |
57 | return GrMtlBackendFormatToCompressionType(format); |
58 | #endif |
59 | break; |
60 | } |
61 | case GrBackendApi::kDirect3D: { |
62 | #ifdef SK_DIRECT3D |
63 | DXGI_FORMAT dxgiFormat; |
64 | SkAssertResult(format.asDxgiFormat(&dxgiFormat)); |
65 | switch (dxgiFormat) { |
66 | case DXGI_FORMAT_BC1_UNORM: |
67 | return SkImage::CompressionType::kBC1_RGBA8_UNORM; |
68 | default: |
69 | return SkImage::CompressionType::kNone; |
70 | } |
71 | #endif |
72 | break; |
73 | } |
74 | case GrBackendApi::kDawn: { |
75 | return SkImage::CompressionType::kNone; |
76 | } |
77 | case GrBackendApi::kMock: { |
78 | return format.asMockCompressionType(); |
79 | } |
80 | } |
81 | return SkImage::CompressionType::kNone; |
82 | } |
83 | |
84 | #endif |
85 | |
86 |