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