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 | 15 |
16 class SkBitmap; | 16 class SkBitmap; |
17 class SkDiscardableMemory; | 17 class SkDiscardableMemory; |
18 | 18 |
19 typedef SkDiscardableMemory* (*SkDiscardableFactoryProc)(size_t bytes); | 19 typedef SkDiscardableMemory* (*SkDiscardableFactoryProc)(size_t bytes); |
20 | 20 |
21 class SkMipMap : public SkCachedData { | 21 class SkMipMap : public SkCachedData { |
22 public: | 22 public: |
23 static SkMipMap* Build(const SkPixmap& src, SkDiscardableFactoryProc); | 23 static SkMipMap* Build(const SkPixmap& src, SkDiscardableFactoryProc); |
24 static SkMipMap* Build(const SkBitmap& src, SkDiscardableFactoryProc); | 24 static SkMipMap* Build(const SkBitmap& src, SkDiscardableFactoryProc); |
25 | 25 |
26 // This function lets you determine how many levels a SkMipMap will have wit
hout | 26 // Determines how many levels a SkMipMap will have without creating that mip
map. |
27 // creating that mipmap. | |
28 static int ComputeLevelCount(int baseWidth, int baseHeight); | 27 static int ComputeLevelCount(int baseWidth, int baseHeight); |
29 | 28 |
| 29 // Determines the size of a given mipmap level. |
| 30 static SkSize ComputeLevelSize(int baseWidth, int baseHeight, int level); |
| 31 |
30 struct Level { | 32 struct Level { |
31 SkPixmap fPixmap; | 33 SkPixmap fPixmap; |
32 SkSize fScale; // < 1.0 | 34 SkSize fScale; // < 1.0 |
33 }; | 35 }; |
34 | 36 |
35 bool extractLevel(const SkSize& scale, Level*) const; | 37 bool extractLevel(const SkSize& scale, Level*) const; |
36 int countLevels() const; | 38 int countLevels() const; |
37 bool getLevel(int index, Level*) const; | 39 bool getLevel(int index, Level*) const; |
38 | 40 |
39 protected: | 41 protected: |
40 void onDataChange(void* oldData, void* newData) override { | 42 void onDataChange(void* oldData, void* newData) override { |
41 fLevels = (Level*)newData; // could be nullptr | 43 fLevels = (Level*)newData; // could be nullptr |
42 } | 44 } |
43 | 45 |
44 private: | 46 private: |
45 Level* fLevels; | 47 Level* fLevels; |
46 int fCount; | 48 int fCount; |
47 | 49 |
48 // we take ownership of levels, and will free it with sk_free() | 50 // we take ownership of levels, and will free it with sk_free() |
49 SkMipMap(void* malloc, size_t size) : INHERITED(malloc, size) {} | 51 SkMipMap(void* malloc, size_t size) : INHERITED(malloc, size) {} |
50 SkMipMap(size_t size, SkDiscardableMemory* dm) : INHERITED(size, dm) {} | 52 SkMipMap(size_t size, SkDiscardableMemory* dm) : INHERITED(size, dm) {} |
51 | 53 |
52 static size_t AllocLevelsSize(int levelCount, size_t pixelSize); | 54 static size_t AllocLevelsSize(int levelCount, size_t pixelSize); |
53 | 55 |
54 typedef SkCachedData INHERITED; | 56 typedef SkCachedData INHERITED; |
55 }; | 57 }; |
56 | 58 |
57 #endif | 59 #endif |
OLD | NEW |