| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkColorCubeFilter.h" | 8 #include "SkColorCubeFilter.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkOnce.h" | 10 #include "SkOnce.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 static const int MIN_CUBE_SIZE = 4; | 42 static const int MIN_CUBE_SIZE = 4; |
| 43 static const int MAX_CUBE_SIZE = 64; | 43 static const int MAX_CUBE_SIZE = 64; |
| 44 | 44 |
| 45 static bool is_valid_3D_lut(SkData* cubeData, int cubeDimension) { | 45 static bool is_valid_3D_lut(SkData* cubeData, int cubeDimension) { |
| 46 size_t minMemorySize = sizeof(uint8_t) * 4 * cubeDimension * cubeDimension *
cubeDimension; | 46 size_t minMemorySize = sizeof(uint8_t) * 4 * cubeDimension * cubeDimension *
cubeDimension; |
| 47 return (cubeDimension >= MIN_CUBE_SIZE) && (cubeDimension <= MAX_CUBE_SIZE)
&& | 47 return (cubeDimension >= MIN_CUBE_SIZE) && (cubeDimension <= MAX_CUBE_SIZE)
&& |
| 48 (nullptr != cubeData) && (cubeData->size() >= minMemorySize); | 48 (nullptr != cubeData) && (cubeData->size() >= minMemorySize); |
| 49 } | 49 } |
| 50 | 50 |
| 51 SkColorFilter* SkColorCubeFilter::Create(SkData* cubeData, int cubeDimension) { | 51 sk_sp<SkColorFilter> SkColorCubeFilter::Make(sk_sp<SkData> cubeData, int cubeDim
ension) { |
| 52 if (!is_valid_3D_lut(cubeData, cubeDimension)) { | 52 if (!is_valid_3D_lut(cubeData.get(), cubeDimension)) { |
| 53 return nullptr; | 53 return nullptr; |
| 54 } | 54 } |
| 55 | 55 |
| 56 return new SkColorCubeFilter(cubeData, cubeDimension); | 56 return sk_sp<SkColorFilter>(new SkColorCubeFilter(std::move(cubeData), cubeD
imension)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 SkColorCubeFilter::SkColorCubeFilter(SkData* cubeData, int cubeDimension) | 59 SkColorCubeFilter::SkColorCubeFilter(sk_sp<SkData> cubeData, int cubeDimension) |
| 60 : fCubeData(SkRef(cubeData)) | 60 : fCubeData(std::move(cubeData)) |
| 61 , fUniqueID(SkNextColorCubeUniqueID()) | 61 , fUniqueID(SkNextColorCubeUniqueID()) |
| 62 , fCache(cubeDimension) { | 62 , fCache(cubeDimension) |
| 63 } | 63 {} |
| 64 | 64 |
| 65 uint32_t SkColorCubeFilter::getFlags() const { | 65 uint32_t SkColorCubeFilter::getFlags() const { |
| 66 return this->INHERITED::getFlags() | kAlphaUnchanged_Flag; | 66 return this->INHERITED::getFlags() | kAlphaUnchanged_Flag; |
| 67 } | 67 } |
| 68 | 68 |
| 69 SkColorCubeFilter::ColorCubeProcesingCache::ColorCubeProcesingCache(int cubeDime
nsion) | 69 SkColorCubeFilter::ColorCubeProcesingCache::ColorCubeProcesingCache(int cubeDime
nsion) |
| 70 : fCubeDimension(cubeDimension) | 70 : fCubeDimension(cubeDimension) |
| 71 , fLutsInited(false) { | 71 , fLutsInited(false) { |
| 72 fColorToIndex[0] = fColorToIndex[1] = nullptr; | 72 fColorToIndex[0] = fColorToIndex[1] = nullptr; |
| 73 fColorToFactors[0] = fColorToFactors[1] = nullptr; | 73 fColorToFactors[0] = fColorToFactors[1] = nullptr; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 colorToFactors, fCache.cubeDimension(), | 135 colorToFactors, fCache.cubeDimension(), |
| 136 (const SkColor*)fCubeData->data()); | 136 (const SkColor*)fCubeData->data()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 SkFlattenable* SkColorCubeFilter::CreateProc(SkReadBuffer& buffer) { | 139 SkFlattenable* SkColorCubeFilter::CreateProc(SkReadBuffer& buffer) { |
| 140 int cubeDimension = buffer.readInt(); | 140 int cubeDimension = buffer.readInt(); |
| 141 auto cubeData(buffer.readByteArrayAsData()); | 141 auto cubeData(buffer.readByteArrayAsData()); |
| 142 if (!buffer.validate(is_valid_3D_lut(cubeData.get(), cubeDimension))) { | 142 if (!buffer.validate(is_valid_3D_lut(cubeData.get(), cubeDimension))) { |
| 143 return nullptr; | 143 return nullptr; |
| 144 } | 144 } |
| 145 return Create(cubeData.get(), cubeDimension); | 145 return Make(std::move(cubeData), cubeDimension).release(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void SkColorCubeFilter::flatten(SkWriteBuffer& buffer) const { | 148 void SkColorCubeFilter::flatten(SkWriteBuffer& buffer) const { |
| 149 this->INHERITED::flatten(buffer); | 149 this->INHERITED::flatten(buffer); |
| 150 buffer.writeInt(fCache.cubeDimension()); | 150 buffer.writeInt(fCache.cubeDimension()); |
| 151 buffer.writeDataAsByteArray(fCubeData.get()); | 151 buffer.writeDataAsByteArray(fCubeData.get()); |
| 152 } | 152 } |
| 153 | 153 |
| 154 #ifndef SK_IGNORE_TO_STRING | 154 #ifndef SK_IGNORE_TO_STRING |
| 155 void SkColorCubeFilter::toString(SkString* str) const { | 155 void SkColorCubeFilter::toString(SkString* str) const { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 if (textureCube) { | 320 if (textureCube) { |
| 321 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); | 321 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); |
| 322 } else { | 322 } else { |
| 323 return nullptr; | 323 return nullptr; |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 return GrColorCubeEffect::Create(textureCube); | 327 return GrColorCubeEffect::Create(textureCube); |
| 328 } | 328 } |
| 329 #endif | 329 #endif |
| OLD | NEW |