1 | /* |
2 | * Copyright 2015 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 SkBitmapController_DEFINED |
9 | #define SkBitmapController_DEFINED |
10 | |
11 | #include "include/core/SkBitmap.h" |
12 | #include "include/core/SkFilterQuality.h" |
13 | #include "include/core/SkImage.h" |
14 | #include "include/core/SkMatrix.h" |
15 | #include "src/core/SkBitmapCache.h" |
16 | #include "src/core/SkMipmap.h" |
17 | |
18 | class SkImage_Base; |
19 | |
20 | /** |
21 | * Handles request to scale, filter, and lock a bitmap to be rasterized. |
22 | */ |
23 | class SkBitmapController : ::SkNoncopyable { |
24 | public: |
25 | class State : ::SkNoncopyable { |
26 | public: |
27 | State(const SkImage_Base*, const SkMatrix& inv, SkFilterQuality); |
28 | |
29 | const SkPixmap& pixmap() const { return fPixmap; } |
30 | const SkMatrix& invMatrix() const { return fInvMatrix; } |
31 | SkFilterQuality quality() const { return fQuality; } |
32 | |
33 | private: |
34 | bool processHighRequest(const SkImage_Base*); |
35 | bool processMediumRequest(const SkImage_Base*); |
36 | |
37 | SkPixmap fPixmap; |
38 | SkMatrix fInvMatrix; |
39 | SkFilterQuality fQuality; |
40 | |
41 | // Pixmap storage. |
42 | SkBitmap fResultBitmap; |
43 | sk_sp<const SkMipmap> fCurrMip; |
44 | |
45 | }; |
46 | |
47 | static State* RequestBitmap(const SkImage_Base*, const SkMatrix& inverse, SkFilterQuality, |
48 | SkArenaAlloc*); |
49 | |
50 | private: |
51 | SkBitmapController() = delete; |
52 | }; |
53 | |
54 | class SkMipmapAccessor : ::SkNoncopyable { |
55 | public: |
56 | SkMipmapAccessor(const SkImage_Base*, const SkMatrix& inv, SkMipmapMode requestedMode); |
57 | |
58 | const SkPixmap& level() const { return fUpper; } |
59 | // only valid if mode() == kLinear |
60 | const SkPixmap& lowerLevel() const { return fLower; } |
61 | // 0....1. Will be 1.0 if there is no lowerLevel |
62 | float lowerWeight() const { return fLowerWeight; } |
63 | SkMipmapMode mode() const { return fResolvedMode; } |
64 | |
65 | private: |
66 | SkPixmap fUpper, |
67 | fLower; // only valid for mip_linear |
68 | float fLowerWeight; // lower * weight + upper * (1 - weight) |
69 | SkMipmapMode fResolvedMode; |
70 | |
71 | // these manage lifetime for the buffers |
72 | SkBitmap fBaseStorage; |
73 | sk_sp<const SkMipmap> fCurrMip; |
74 | }; |
75 | |
76 | #endif |
77 | |