reed@google.com | dc6c8ba | 2013-07-18 21:14:04 +0000 | [diff] [blame] | 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 | |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 8 | #ifndef SkMipMap_DEFINED |
| 9 | #define SkMipMap_DEFINED |
| 10 | |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 11 | #include "SkCachedData.h" |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 12 | #include "SkScalar.h" |
| 13 | |
| 14 | class SkBitmap; |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 15 | class SkDiscardableMemory; |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 16 | |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 17 | typedef SkDiscardableMemory* (*SkDiscardableFactoryProc)(size_t bytes); |
| 18 | |
| 19 | class SkMipMap : public SkCachedData { |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 20 | public: |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 21 | static SkMipMap* Build(const SkBitmap& src, SkDiscardableFactoryProc); |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 22 | |
| 23 | struct Level { |
| 24 | void* fPixels; |
| 25 | uint32_t fRowBytes; |
| 26 | uint32_t fWidth, fHeight; |
reed@google.com | d94697c | 2013-07-24 14:31:33 +0000 | [diff] [blame] | 27 | float fScale; // < 1.0 |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 28 | }; |
skia.committer@gmail.com | a799198 | 2013-07-19 07:00:57 +0000 | [diff] [blame] | 29 | |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 30 | bool extractLevel(SkScalar scale, Level*) const; |
| 31 | |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 32 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 33 | void onDataChange(void* oldData, void* newData) override { |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 34 | fLevels = (Level*)newData; // could be NULL |
| 35 | } |
reed@google.com | d94697c | 2013-07-24 14:31:33 +0000 | [diff] [blame] | 36 | |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 37 | private: |
| 38 | Level* fLevels; |
| 39 | int fCount; |
| 40 | |
| 41 | // we take ownership of levels, and will free it with sk_free() |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 42 | SkMipMap(void* malloc, size_t size) : INHERITED(malloc, size) {} |
| 43 | SkMipMap(size_t size, SkDiscardableMemory* dm) : INHERITED(size, dm) {} |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 44 | |
reed | 9d93c2e | 2014-10-08 05:17:12 -0700 | [diff] [blame] | 45 | static size_t AllocLevelsSize(int levelCount, size_t pixelSize); |
| 46 | |
| 47 | typedef SkCachedData INHERITED; |
reed@google.com | eed6f1b | 2013-07-18 19:53:31 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | #endif |