Home | History | Annotate | Download | only in core
      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:
     25         virtual ~State() {}
     26 
     27         const SkPixmap& pixmap() const { return fPixmap; }
     28         const SkMatrix& invMatrix() const { return fInvMatrix; }
     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 
     40     virtual ~SkBitmapController() {}
     41 
     42     State* requestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality,
     43                          void* storage, size_t storageSize);
     44 
     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 class SkDefaultBitmapController : public SkBitmapController {
     57 public:
     58     SkDefaultBitmapController() {}
     59 
     60 protected:
     61     State* onRequestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality,
     62                            void* storage, size_t storageSize) override;
     63 };
     64 
     65 #endif
     66