| 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 "SkScalar.h" | 12 #include "SkScalar.h" |
| 13 #include "SkMipMapLevel.h" |
| 13 | 14 |
| 14 class SkBitmap; | 15 class SkBitmap; |
| 15 class SkDiscardableMemory; | |
| 16 | |
| 17 typedef SkDiscardableMemory* (*SkDiscardableFactoryProc)(size_t bytes); | |
| 18 | 16 |
| 19 class SkMipMap : public SkCachedData { | 17 class SkMipMap : public SkCachedData { |
| 20 public: | 18 public: |
| 21 static SkMipMap* Build(const SkBitmap& src, SkDiscardableFactoryProc); | 19 static SkMipMap* Build(const SkBitmap& src, SkDiscardableFactoryProc); |
| 22 | 20 |
| 23 struct Level { | 21 struct Level { |
| 24 void* fPixels; | 22 void* fPixels; |
| 25 uint32_t fRowBytes; | 23 uint32_t fRowBytes; |
| 26 uint32_t fWidth, fHeight; | 24 uint32_t fWidth, fHeight; |
| 27 float fScale; // < 1.0 | 25 float fScale; // < 1.0 |
| 28 }; | 26 }; |
| 29 | 27 |
| 30 bool extractLevel(SkScalar scale, Level*) const; | 28 bool extractLevel(SkScalar scale, Level*) const; |
| 29 int getLevelsCount() const; |
| 30 // getLevel() is 1-indexed because the SkMipMap contains the generated |
| 31 // mipmaps, which does not include the base level (which is normally |
| 32 // mipmap level 0). SkMipMap contains mipmap levels 1-x, not 0-x. |
| 33 bool getLevel(int levelIndex, Level* levelPtr) const; |
| 31 | 34 |
| 32 protected: | 35 protected: |
| 33 void onDataChange(void* oldData, void* newData) override { | 36 void onDataChange(void* oldData, void* newData) override { |
| 34 fLevels = (Level*)newData; // could be nullptr | 37 fLevels = (Level*)newData; // could be nullptr |
| 35 } | 38 } |
| 36 | 39 |
| 37 private: | 40 private: |
| 38 Level* fLevels; | 41 Level* fLevels; |
| 39 int fCount; | 42 int fCount; |
| 40 | 43 |
| 41 // we take ownership of levels, and will free it with sk_free() | 44 // we take ownership of levels, and will free it with sk_free() |
| 42 SkMipMap(void* malloc, size_t size) : INHERITED(malloc, size) {} | 45 SkMipMap(void* malloc, size_t size) : INHERITED(malloc, size) {} |
| 43 SkMipMap(size_t size, SkDiscardableMemory* dm) : INHERITED(size, dm) {} | 46 SkMipMap(size_t size, SkDiscardableMemory* dm) : INHERITED(size, dm) {} |
| 44 | 47 |
| 45 static size_t AllocLevelsSize(int levelCount, size_t pixelSize); | 48 static size_t AllocLevelsSize(int levelCount, size_t pixelSize); |
| 46 | 49 |
| 47 typedef SkCachedData INHERITED; | 50 typedef SkCachedData INHERITED; |
| 48 }; | 51 }; |
| 49 | 52 |
| 50 #endif | 53 #endif |
| OLD | NEW |