| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "ktx.h" | 9 #include "ktx.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 11 #include "SkStream.h" | 11 #include "SkStream.h" |
| 12 #include "SkEndian.h" | 12 #include "SkEndian.h" |
| 13 | 13 |
| 14 #include "gl/GrGLDefines.h" | 14 #include "gl/GrGLDefines.h" |
| 15 #include "GrConfig.h" |
| 15 | 16 |
| 16 #include "etc1.h" | 17 #include "etc1.h" |
| 17 | 18 |
| 19 static inline uint32_t compressed_fmt_to_gl_define(SkTextureCompressor::Format f
mt) { |
| 20 static const uint32_t kGLDefineMap[SkTextureCompressor::kFormatCnt] = { |
| 21 GR_GL_COMPRESSED_LUMINANCE_LATC1, // kLATC_Format |
| 22 GR_GL_COMPRESSED_R11, // kR11_EAC_Format |
| 23 GR_GL_COMPRESSED_RGB8_ETC1, // kETC1_Format |
| 24 GR_GL_COMPRESSED_RGBA_ASTC_12x12, // kASTC_12x12_Format |
| 25 }; |
| 26 |
| 27 GR_STATIC_ASSERT(0 == SkTextureCompressor::kLATC_Format); |
| 28 GR_STATIC_ASSERT(1 == SkTextureCompressor::kR11_EAC_Format); |
| 29 GR_STATIC_ASSERT(2 == SkTextureCompressor::kETC1_Format); |
| 30 GR_STATIC_ASSERT(3 == SkTextureCompressor::kASTC_12x12_Format); |
| 31 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kGLDefineMap) == SkTextureCompressor::kForma
tCnt); |
| 32 |
| 33 return kGLDefineMap[fmt]; |
| 34 } |
| 35 |
| 18 #define KTX_FILE_IDENTIFIER_SIZE 12 | 36 #define KTX_FILE_IDENTIFIER_SIZE 12 |
| 19 static const uint8_t KTX_FILE_IDENTIFIER[KTX_FILE_IDENTIFIER_SIZE] = { | 37 static const uint8_t KTX_FILE_IDENTIFIER[KTX_FILE_IDENTIFIER_SIZE] = { |
| 20 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A | 38 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A |
| 21 }; | 39 }; |
| 22 | 40 |
| 23 static const uint32_t kKTX_ENDIANNESS_CODE = 0x04030201; | 41 static const uint32_t kKTX_ENDIANNESS_CODE = 0x04030201; |
| 24 | 42 |
| 25 bool SkKTXFile::KeyValue::readKeyAndValue(const uint8_t* data) { | 43 bool SkKTXFile::KeyValue::readKeyAndValue(const uint8_t* data) { |
| 26 const char *key = reinterpret_cast<const char *>(data); | 44 const char *key = reinterpret_cast<const char *>(data); |
| 27 const char *value = key; | 45 const char *value = key; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 const KeyValue *begin = this->fKeyValuePairs.begin(); | 134 const KeyValue *begin = this->fKeyValuePairs.begin(); |
| 117 const KeyValue *end = this->fKeyValuePairs.end(); | 135 const KeyValue *end = this->fKeyValuePairs.end(); |
| 118 for (const KeyValue *kv = begin; kv != end; ++kv) { | 136 for (const KeyValue *kv = begin; kv != end; ++kv) { |
| 119 if (kv->key() == key) { | 137 if (kv->key() == key) { |
| 120 return kv->value(); | 138 return kv->value(); |
| 121 } | 139 } |
| 122 } | 140 } |
| 123 return SkString(); | 141 return SkString(); |
| 124 } | 142 } |
| 125 | 143 |
| 126 bool SkKTXFile::isETC1() const { | 144 bool SkKTXFile::isCompressedFormat(SkTextureCompressor::Format fmt) const { |
| 127 return this->valid() && GR_GL_COMPRESSED_RGB8_ETC1 == fHeader.fGLInternalFor
mat; | 145 if (!this->valid()) { |
| 146 return false; |
| 147 } |
| 148 |
| 149 // This has many aliases |
| 150 bool isFmt = false; |
| 151 if (fmt == SkTextureCompressor::kLATC_Format) { |
| 152 isFmt = GR_GL_COMPRESSED_RED_RGTC1 == fHeader.fGLInternalFormat || |
| 153 GR_GL_COMPRESSED_3DC_X == fHeader.fGLInternalFormat; |
| 154 } |
| 155 |
| 156 return isFmt || compressed_fmt_to_gl_define(fmt) == fHeader.fGLInternalForma
t; |
| 128 } | 157 } |
| 129 | 158 |
| 130 bool SkKTXFile::isRGBA8() const { | 159 bool SkKTXFile::isRGBA8() const { |
| 131 return this->valid() && GR_GL_RGBA8 == fHeader.fGLInternalFormat; | 160 return this->valid() && GR_GL_RGBA8 == fHeader.fGLInternalFormat; |
| 132 } | 161 } |
| 133 | 162 |
| 134 bool SkKTXFile::isRGB8() const { | 163 bool SkKTXFile::isRGB8() const { |
| 135 return this->valid() && GR_GL_RGB8 == fHeader.fGLInternalFormat; | 164 return this->valid() && GR_GL_RGB8 == fHeader.fGLInternalFormat; |
| 136 } | 165 } |
| 137 | 166 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 for (int i = 0; i < height; ++i) { | 519 for (int i = 0; i < height; ++i) { |
| 491 if (!stream->write(rowPtr, bpp*width)) { | 520 if (!stream->write(rowPtr, bpp*width)) { |
| 492 return false; | 521 return false; |
| 493 } | 522 } |
| 494 rowPtr += bitmap.rowBytes(); | 523 rowPtr += bitmap.rowBytes(); |
| 495 } | 524 } |
| 496 } | 525 } |
| 497 | 526 |
| 498 return true; | 527 return true; |
| 499 } | 528 } |
| OLD | NEW |