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