Flutter Engine
The Flutter Engine
Classes | Namespaces | Typedefs | Functions | Variables
exoticformats.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkImage.h"
#include "include/core/SkStream.h"
#include "include/core/SkTextureCompressionType.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "src/core/SkCompressedDataUtils.h"
#include "src/core/SkMipmap.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrImageContextPriv.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/gl/GrGLDefines.h"
#include "src/gpu/ganesh/image/SkImage_GaneshBase.h"
#include "src/image/SkImage_Base.h"
#include "tools/Resources.h"
#include "tools/gpu/ProxyUtils.h"

Go to the source code of this file.

Classes

struct  ImageInfo
 
struct  DDS_PIXELFORMAT
 
struct  DDS_HEADER
 
class  skiagm::ExoticFormatsGM
 

Namespaces

namespace  skiagm
 

Typedefs

typedef uint32_t DWORD
 

Functions

static uint32_t get_uint (uint8_t *buffer, uint32_t i)
 
static sk_sp< SkDataload_ktx (const char *filename, ImageInfo *imageInfo)
 
static sk_sp< SkDataload_dds (const char *filename, ImageInfo *imageInfo)
 
static sk_sp< SkImagedata_to_img (GrDirectContext *direct, sk_sp< SkData > data, const ImageInfo &info)
 

Variables

constexpr unsigned int kDDPF_FOURCC = 0x4
 
constexpr unsigned int kDDSD_CAPS = 0x1
 
constexpr unsigned int kDDSD_HEIGHT = 0x2
 
constexpr unsigned int kDDSD_WIDTH = 0x4
 
constexpr unsigned int kDDSD_PITCH = 0x8
 
constexpr unsigned int kDDSD_PIXELFORMAT = 0x001000
 
constexpr unsigned int kDDSD_MIPMAPCOUNT = 0x020000
 
constexpr unsigned int kDDSD_LINEARSIZE = 0x080000
 
constexpr unsigned int kDDSD_DEPTH = 0x800000
 
constexpr unsigned int kDDSD_REQUIRED = kDDSD_CAPS | kDDSD_HEIGHT | kDDSD_WIDTH | kDDSD_PIXELFORMAT
 

Typedef Documentation

◆ DWORD

typedef uint32_t DWORD

Definition at line 170 of file exoticformats.cpp.

Function Documentation

◆ data_to_img()

static sk_sp< SkImage > data_to_img ( GrDirectContext direct,
sk_sp< SkData data,
const ImageInfo info 
)
static

Definition at line 311 of file exoticformats.cpp.

312 {
313 if (direct) {
315 std::move(data),
316 info.fDim.fWidth,
317 info.fDim.fHeight,
318 info.fCompressionType,
319 info.fMipmapped);
320 } else {
322 std::move(data), info.fDim.fWidth, info.fDim.fHeight, info.fCompressionType);
323 }
324}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SK_API sk_sp< SkImage > TextureFromCompressedTextureData(GrDirectContext *direct, sk_sp< SkData > data, int width, int height, SkTextureCompressionType type, skgpu::Mipmapped mipmapped=skgpu::Mipmapped::kNo, GrProtected isProtected=GrProtected::kNo)
SK_API sk_sp< SkImage > RasterFromCompressedTextureData(sk_sp< SkData > data, int width, int height, SkTextureCompressionType type)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ get_uint()

static uint32_t get_uint ( uint8_t *  buffer,
uint32_t  i 
)
inlinestatic

Definition at line 40 of file exoticformats.cpp.

40 {
41 uint32_t result;
42 memcpy(&result, &(buffer[i]), 4);
43 return result;
44}
GAsyncResult * result
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ load_dds()

static sk_sp< SkData > load_dds ( const char *  filename,
ImageInfo imageInfo 
)
static

Definition at line 217 of file exoticformats.cpp.

217 {
218 SkFILEStream input(filename);
219 if (!input.isValid()) {
220 return nullptr;
221 }
222
223 constexpr uint32_t kMagic = 0x20534444;
224 uint32_t magic;
225
226 if (input.read(&magic, 4) != 4) {
227 return nullptr;
228 }
229
230 if (magic != kMagic) {
231 return nullptr;
232 }
233
234 constexpr size_t kDDSHeaderSize = sizeof(DDS_HEADER);
235 static_assert(kDDSHeaderSize == 124);
236 constexpr size_t kDDSPixelFormatSize = sizeof(DDS_PIXELFORMAT);
237 static_assert(kDDSPixelFormatSize == 32);
238
240
241 if (input.read(&header, kDDSHeaderSize) != kDDSHeaderSize) {
242 return nullptr;
243 }
244
245 if (header.dwSize != kDDSHeaderSize ||
246 header.ddspf.dwSize != kDDSPixelFormatSize) {
247 return nullptr;
248 }
249
250 if ((header.dwFlags & kDDSD_REQUIRED) != kDDSD_REQUIRED) {
251 return nullptr;
252 }
253
254 if (header.dwFlags & (kDDSD_PITCH | kDDSD_LINEARSIZE | kDDSD_DEPTH)) {
255 // TODO: support these features
256 }
257
258 imageInfo->fDim.fWidth = header.dwWidth;
259 imageInfo->fDim.fHeight = header.dwHeight;
260
261 int numberOfMipmapLevels = 1;
262 if (header.dwFlags & kDDSD_MIPMAPCOUNT) {
263 if (header.dwMipMapCount == 1) {
265 } else {
266 int numRequiredLevels = SkMipmap::ComputeLevelCount(header.dwWidth, header.dwHeight)+1;
267 if (header.dwMipMapCount != (unsigned) numRequiredLevels) {
268 return nullptr;
269 }
271 numberOfMipmapLevels = numRequiredLevels;
272 }
273 } else {
275 }
276
277 if (!(header.ddspf.dwFlags & kDDPF_FOURCC)) {
278 return nullptr;
279 }
280
281 // We only handle these one format right now
282 switch (header.ddspf.dwFourCC) {
283 case 0x31545844: // DXT1
285 break;
286 default:
287 return nullptr;
288 }
289
290 TArray<size_t> individualMipOffsets(numberOfMipmapLevels);
291
292 size_t dataSize = SkCompressedDataSize(imageInfo->fCompressionType,
293 {(int)header.dwWidth, (int)header.dwHeight},
294 &individualMipOffsets,
295 imageInfo->fMipmapped == skgpu::Mipmapped::kYes);
296 SkASSERT(individualMipOffsets.size() == numberOfMipmapLevels);
297
299
300 uint8_t* dest = (uint8_t*) data->writable_data();
301
302 size_t amountRead = input.read(dest, dataSize);
303 if (amountRead != dataSize) {
304 return nullptr;
305 }
306
307 return data;
308}
#define SkASSERT(cond)
Definition: SkAssert.h:116
size_t SkCompressedDataSize(SkTextureCompressionType type, SkISize dimensions, TArray< size_t > *individualMipOffsets, bool mipmapped)
static const char kMagic[]
Definition: SkPicture.cpp:58
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition: SkMipmap.cpp:134
constexpr unsigned int kDDSD_REQUIRED
constexpr unsigned int kDDSD_MIPMAPCOUNT
constexpr unsigned int kDDSD_PITCH
constexpr unsigned int kDDSD_DEPTH
constexpr unsigned int kDDSD_LINEARSIZE
constexpr unsigned int kDDPF_FOURCC
dest
Definition: zip.py:79
static const char header[]
Definition: skpbench.cpp:88
SkTextureCompressionType fCompressionType
SkISize fDim
skgpu::Mipmapped fMipmapped
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17

◆ load_ktx()

static sk_sp< SkData > load_ktx ( const char *  filename,
ImageInfo imageInfo 
)
static

Definition at line 48 of file exoticformats.cpp.

48 {
49 SkFILEStream input(filename);
50 if (!input.isValid()) {
51 return nullptr;
52 }
53
54 constexpr int kKTXIdentifierSize = 12;
55 constexpr int kKTXHeaderSize = kKTXIdentifierSize + 13 * sizeof(uint32_t);
56 uint8_t header[kKTXHeaderSize];
57
58 if (input.read(header, kKTXHeaderSize) != kKTXHeaderSize) {
59 return nullptr;
60 }
61
62 static const uint8_t kExpectedIdentifier[kKTXIdentifierSize] = {
63 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
64 };
65
66 if (0 != memcmp(header, kExpectedIdentifier, kKTXIdentifierSize)) {
67 return nullptr;
68 }
69
70 uint32_t endianness = get_uint(header, 12);
71 if (endianness != 0x04030201) {
72 // TODO: need to swap rest of header and, if glTypeSize is > 1, all
73 // the texture data.
74 return nullptr;
75 }
76
77 uint32_t glType = get_uint(header, 16);
78 SkDEBUGCODE(uint32_t glTypeSize = get_uint(header, 20);)
79 uint32_t glFormat = get_uint(header, 24);
80 uint32_t glInternalFormat = get_uint(header, 28);
81 //uint32_t glBaseInternalFormat = get_uint(header, 32);
82 uint32_t pixelWidth = get_uint(header, 36);
83 uint32_t pixelHeight = get_uint(header, 40);
84 uint32_t pixelDepth = get_uint(header, 44);
85 //uint32_t numberOfArrayElements = get_uint(header, 48);
86 uint32_t numberOfFaces = get_uint(header, 52);
87 int numberOfMipmapLevels = get_uint(header, 56);
88 uint32_t bytesOfKeyValueData = get_uint(header, 60);
89
90 if (glType != 0 || glFormat != 0) { // only care about compressed data for now
91 return nullptr;
92 }
93 SkASSERT(glTypeSize == 1); // required for compressed data
94
95 // We only handle these four formats right now
96 switch (glInternalFormat) {
100 break;
103 break;
106 break;
107 default:
108 return nullptr;
109 }
110
111 imageInfo->fDim.fWidth = pixelWidth;
112 imageInfo->fDim.fHeight = pixelHeight;
113
114 if (pixelDepth != 0) {
115 return nullptr; // pixel depth is always zero for 2D textures
116 }
117
118 if (numberOfFaces != 1) {
119 return nullptr; // we don't support cube maps right now
120 }
121
122 if (numberOfMipmapLevels == 1) {
124 } else {
125 int numRequiredMipLevels = SkMipmap::ComputeLevelCount(pixelWidth, pixelHeight)+1;
126 if (numberOfMipmapLevels != numRequiredMipLevels) {
127 return nullptr;
128 }
130 }
131
132 if (bytesOfKeyValueData != 0) {
133 return nullptr;
134 }
135
136 TArray<size_t> individualMipOffsets(numberOfMipmapLevels);
137
138 size_t dataSize = SkCompressedDataSize(imageInfo->fCompressionType,
139 {(int)pixelWidth, (int)pixelHeight},
140 &individualMipOffsets,
141 imageInfo->fMipmapped == skgpu::Mipmapped::kYes);
142 SkASSERT(individualMipOffsets.size() == numberOfMipmapLevels);
143
145
146 uint8_t* dest = (uint8_t*) data->writable_data();
147
148 size_t offset = 0;
149 for (int i = 0; i < numberOfMipmapLevels; ++i) {
150 uint32_t imageSize;
151
152 if (input.read(&imageSize, 4) != 4) {
153 return nullptr;
154 }
155
156 SkASSERT(offset + imageSize <= dataSize);
157 SkASSERT(offset == individualMipOffsets[i]);
158
159 if (input.read(&dest[offset], imageSize) != imageSize) {
160 return nullptr;
161 }
162
163 offset += imageSize;
164 }
165
166 return data;
167}
#define GR_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
Definition: GrGLDefines.h:261
#define GR_GL_COMPRESSED_ETC1_RGB8
Definition: GrGLDefines.h:278
#define GR_GL_COMPRESSED_RGB8_ETC2
Definition: GrGLDefines.h:285
#define GR_GL_COMPRESSED_RGB_S3TC_DXT1_EXT
Definition: GrGLDefines.h:260
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static uint32_t get_uint(uint8_t *buffer, uint32_t i)
SeparatedVector2 offset

Variable Documentation

◆ kDDPF_FOURCC

constexpr unsigned int kDDPF_FOURCC = 0x4
constexpr

Definition at line 173 of file exoticformats.cpp.

◆ kDDSD_CAPS

constexpr unsigned int kDDSD_CAPS = 0x1
constexpr

Definition at line 187 of file exoticformats.cpp.

◆ kDDSD_DEPTH

constexpr unsigned int kDDSD_DEPTH = 0x800000
constexpr

Definition at line 194 of file exoticformats.cpp.

◆ kDDSD_HEIGHT

constexpr unsigned int kDDSD_HEIGHT = 0x2
constexpr

Definition at line 188 of file exoticformats.cpp.

◆ kDDSD_LINEARSIZE

constexpr unsigned int kDDSD_LINEARSIZE = 0x080000
constexpr

Definition at line 193 of file exoticformats.cpp.

◆ kDDSD_MIPMAPCOUNT

constexpr unsigned int kDDSD_MIPMAPCOUNT = 0x020000
constexpr

Definition at line 192 of file exoticformats.cpp.

◆ kDDSD_PITCH

constexpr unsigned int kDDSD_PITCH = 0x8
constexpr

Definition at line 190 of file exoticformats.cpp.

◆ kDDSD_PIXELFORMAT

constexpr unsigned int kDDSD_PIXELFORMAT = 0x001000
constexpr

Definition at line 191 of file exoticformats.cpp.

◆ kDDSD_REQUIRED

constexpr unsigned int kDDSD_REQUIRED = kDDSD_CAPS | kDDSD_HEIGHT | kDDSD_WIDTH | kDDSD_PIXELFORMAT
constexpr

Definition at line 196 of file exoticformats.cpp.

◆ kDDSD_WIDTH

constexpr unsigned int kDDSD_WIDTH = 0x4
constexpr

Definition at line 189 of file exoticformats.cpp.