• 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 SkBitmapController_DEFINED
9 #define SkBitmapController_DEFINED
10 
11 #include "SkBitmap.h"
12 #include "SkBitmapCache.h"
13 #include "SkFilterQuality.h"
14 #include "SkMatrix.h"
15 
16 class SkBitmapProvider;
17 
18 /**
19  *  Handles request to scale, filter, and lock a bitmap to be rasterized.
20  */
21 class SkBitmapController : ::SkNoncopyable {
22 public:
23     class State : ::SkNoncopyable {
24     public:
~State()25         virtual ~State() {}
26 
pixmap()27         const SkPixmap& pixmap() const { return fPixmap; }
invMatrix()28         const SkMatrix& invMatrix() const { return fInvMatrix; }
quality()29         SkFilterQuality quality() const { return fQuality; }
30 
31     protected:
32         SkPixmap        fPixmap;
33         SkMatrix        fInvMatrix;
34         SkFilterQuality fQuality;
35 
36     private:
37         friend class SkBitmapController;
38     };
39 
~SkBitmapController()40     virtual ~SkBitmapController() {}
41 
42     State* requestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality,
43                          void* storage, size_t storageSize);
44 
requestBitmap(const SkBitmapProvider & bp,const SkMatrix & inv,SkFilterQuality quality)45     State* requestBitmap(const SkBitmapProvider& bp, const SkMatrix& inv, SkFilterQuality quality) {
46         return this->requestBitmap(bp, inv, quality, nullptr, 0);
47     }
48 
49 protected:
50     virtual State* onRequestBitmap(const SkBitmapProvider&, const SkMatrix& inv, SkFilterQuality,
51                                    void* storage, size_t storageSize) = 0;
52 };
53 
54 ///////////////////////////////////////////////////////////////////////////////////////////////////
55 
56 #include "SkMipMap.h"
57 
58 class SkDefaultBitmapController : public SkBitmapController {
59 public:
60     enum class CanShadeHQ { kNo, kYes };
SkDefaultBitmapController(CanShadeHQ canShadeHQ)61     SkDefaultBitmapController(CanShadeHQ canShadeHQ)
62         : fCanShadeHQ(canShadeHQ == CanShadeHQ::kYes) {}
63 
64 protected:
65     State* onRequestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality,
66                            void* storage, size_t storageSize) override;
67     bool fCanShadeHQ;
68 };
69 
70 #endif
71