| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #ifndef SkMipMap_DEFINED | 8 #ifndef SkMipMap_DEFINED |
| 9 #define SkMipMap_DEFINED | 9 #define SkMipMap_DEFINED |
| 10 | 10 |
| 11 #include "SkCachedData.h" | 11 #include "SkCachedData.h" |
| 12 #include "SkPixmap.h" | 12 #include "SkPixmap.h" |
| 13 #include "SkScalar.h" | 13 #include "SkScalar.h" |
| 14 #include "SkSize.h" | 14 #include "SkSize.h" |
| 15 #include "SkShader.h" |
| 15 | 16 |
| 16 class SkBitmap; | 17 class SkBitmap; |
| 17 class SkDiscardableMemory; | 18 class SkDiscardableMemory; |
| 18 | 19 |
| 19 typedef SkDiscardableMemory* (*SkDiscardableFactoryProc)(size_t bytes); | 20 typedef SkDiscardableMemory* (*SkDiscardableFactoryProc)(size_t bytes); |
| 20 | 21 |
| 21 class SkMipMap : public SkCachedData { | 22 class SkMipMap : public SkCachedData { |
| 22 public: | 23 public: |
| 23 static SkMipMap* Build(const SkPixmap& src, SkDiscardableFactoryProc); | 24 static SkMipMap* Build(const SkPixmap& src, SkSourceGammaTreatment, SkDiscar
dableFactoryProc); |
| 24 static SkMipMap* Build(const SkBitmap& src, SkDiscardableFactoryProc); | 25 static SkMipMap* Build(const SkBitmap& src, SkSourceGammaTreatment, SkDiscar
dableFactoryProc); |
| 26 |
| 27 static SkSourceGammaTreatment DeduceTreatment(const SkShader::ContextRec& re
c) { |
| 28 return (SkShader::ContextRec::kPMColor_DstType == rec.fPreferredDstType)
? |
| 29 SkSourceGammaTreatment::kIgnore : SkSourceGammaTreatment::kRespe
ct; |
| 30 } |
| 25 | 31 |
| 26 // Determines how many levels a SkMipMap will have without creating that mip
map. | 32 // Determines how many levels a SkMipMap will have without creating that mip
map. |
| 27 static int ComputeLevelCount(int baseWidth, int baseHeight); | 33 static int ComputeLevelCount(int baseWidth, int baseHeight); |
| 28 | 34 |
| 29 // Determines the size of a given mipmap level. | 35 // Determines the size of a given mipmap level. |
| 30 static SkISize ComputeLevelSize(int baseWidth, int baseHeight, int level); | 36 static SkISize ComputeLevelSize(int baseWidth, int baseHeight, int level); |
| 31 | 37 |
| 32 struct Level { | 38 struct Level { |
| 33 SkPixmap fPixmap; | 39 SkPixmap fPixmap; |
| 34 SkSize fScale; // < 1.0 | 40 SkSize fScale; // < 1.0 |
| 35 }; | 41 }; |
| 36 | 42 |
| 37 bool extractLevel(const SkSize& scale, Level*) const; | 43 bool extractLevel(const SkSize& scale, Level*) const; |
| 38 int countLevels() const; | 44 int countLevels() const; |
| 39 bool getLevel(int index, Level*) const; | 45 bool getLevel(int index, Level*) const; |
| 40 | 46 |
| 41 protected: | 47 protected: |
| 42 void onDataChange(void* oldData, void* newData) override { | 48 void onDataChange(void* oldData, void* newData) override { |
| 43 fLevels = (Level*)newData; // could be nullptr | 49 fLevels = (Level*)newData; // could be nullptr |
| 44 } | 50 } |
| 45 | 51 |
| 46 private: | 52 private: |
| 47 Level* fLevels; | 53 sk_sp<SkColorSpace> fCS; |
| 48 int fCount; | 54 Level* fLevels; // managed by the baseclass, may be null due
to onDataChanged. |
| 55 int fCount; |
| 49 | 56 |
| 50 // we take ownership of levels, and will free it with sk_free() | |
| 51 SkMipMap(void* malloc, size_t size) : INHERITED(malloc, size) {} | 57 SkMipMap(void* malloc, size_t size) : INHERITED(malloc, size) {} |
| 52 SkMipMap(size_t size, SkDiscardableMemory* dm) : INHERITED(size, dm) {} | 58 SkMipMap(size_t size, SkDiscardableMemory* dm) : INHERITED(size, dm) {} |
| 53 | 59 |
| 54 static size_t AllocLevelsSize(int levelCount, size_t pixelSize); | 60 static size_t AllocLevelsSize(int levelCount, size_t pixelSize); |
| 55 | 61 |
| 56 typedef SkCachedData INHERITED; | 62 typedef SkCachedData INHERITED; |
| 57 }; | 63 }; |
| 58 | 64 |
| 59 #endif | 65 #endif |
| OLD | NEW |