1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkMipMap_DEFINED 9 #define SkMipMap_DEFINED 10 11 #include "SkCachedData.h" 12 #include "SkScalar.h" 13 14 class SkBitmap; 15 class SkDiscardableMemory; 16 17 typedef SkDiscardableMemory* (*SkDiscardableFactoryProc)(size_t bytes); 18 19 class SkMipMap : public SkCachedData { 20 public: 21 static SkMipMap* Build(const SkBitmap& src, SkDiscardableFactoryProc); 22 23 struct Level { 24 void* fPixels; 25 uint32_t fRowBytes; 26 uint32_t fWidth, fHeight; 27 float fScale; // < 1.0 28 }; 29 30 bool extractLevel(SkScalar scale, Level*) const; 31 32 protected: onDataChange(void * oldData,void * newData)33 void onDataChange(void* oldData, void* newData) override { 34 fLevels = (Level*)newData; // could be NULL 35 } 36 37 private: 38 Level* fLevels; 39 int fCount; 40 41 // we take ownership of levels, and will free it with sk_free() SkMipMap(void * malloc,size_t size)42 SkMipMap(void* malloc, size_t size) : INHERITED(malloc, size) {} SkMipMap(size_t size,SkDiscardableMemory * dm)43 SkMipMap(size_t size, SkDiscardableMemory* dm) : INHERITED(size, dm) {} 44 45 static size_t AllocLevelsSize(int levelCount, size_t pixelSize); 46 47 typedef SkCachedData INHERITED; 48 }; 49 50 #endif 51