xref: /aosp_15_r20/external/skia/src/core/SkMipmapAccessor.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 SkMipmapAccessor_DEFINED
9 #define SkMipmapAccessor_DEFINED
10 
11 #include "include/core/SkBitmap.h"
12 #include "include/core/SkMatrix.h"
13 #include "include/core/SkPixmap.h"
14 #include "include/core/SkRefCnt.h"
15 #include "include/private/base/SkAssert.h"
16 #include "include/private/base/SkNoncopyable.h"
17 #include "src/core/SkMipmap.h"
18 
19 #include <utility>
20 
21 class SkArenaAlloc;
22 class SkImage;
23 class SkImage_Base;
24 enum class SkMipmapMode;
25 
26 class SkMipmapAccessor : ::SkNoncopyable {
27 public:
28     // Returns null on failure
29     static SkMipmapAccessor* Make(SkArenaAlloc*, const SkImage*, const SkMatrix& inv, SkMipmapMode);
30 
level()31     std::pair<SkPixmap, SkMatrix> level() const {
32         SkASSERT(fUpper.addr() != nullptr);
33         return std::make_pair(fUpper, fUpperInv);
34     }
35 
lowerLevel()36     std::pair<SkPixmap, SkMatrix> lowerLevel() const {
37         SkASSERT(fLower.addr() != nullptr);
38         return std::make_pair(fLower, fLowerInv);
39     }
40 
41     // 0....1. Will be 0 if there is no lowerLevel
lowerWeight()42     float lowerWeight() const { return fLowerWeight; }
43 
44 private:
45     SkPixmap     fUpper,
46                  fLower; // only valid for mip_linear
47     float        fLowerWeight;   // lower * weight + upper * (1 - weight)
48     SkMatrix     fUpperInv,
49                  fLowerInv;
50 
51     // these manage lifetime for the buffers
52     SkBitmap              fBaseStorage;
53     sk_sp<const SkMipmap> fCurrMip;
54 
55 public:
56     // Don't call publicly -- this is only public for SkArenaAlloc to access it inside Make()
57     SkMipmapAccessor(const SkImage_Base*, const SkMatrix& inv, SkMipmapMode requestedMode);
58 };
59 
60 #endif
61