Home | History | Annotate | Download | only in image
      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 SkImage_Gpu_DEFINED
      9 #define SkImage_Gpu_DEFINED
     10 
     11 #include "GrClip.h"
     12 #include "GrContext.h"
     13 #include "GrGpuResourcePriv.h"
     14 #include "GrSurfaceProxyPriv.h"
     15 #include "SkAtomics.h"
     16 #include "SkBitmap.h"
     17 #include "SkGr.h"
     18 #include "SkImagePriv.h"
     19 #include "SkImage_Base.h"
     20 #include "SkSurface.h"
     21 
     22 class GrTexture;
     23 
     24 class SkImage_Gpu : public SkImage_Base {
     25 public:
     26     SkImage_Gpu(GrContext*, uint32_t uniqueID, SkAlphaType, sk_sp<GrTextureProxy>,
     27                 sk_sp<SkColorSpace>, SkBudgeted);
     28     ~SkImage_Gpu() override;
     29 
     30     SkImageInfo onImageInfo() const override;
     31     SkAlphaType onAlphaType() const override { return fAlphaType; }
     32 
     33     bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
     34     sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
     35 
     36     GrContext* context() const override { return fContext; }
     37     GrTextureProxy* peekProxy() const override {
     38         return fProxy.get();
     39     }
     40     sk_sp<GrTextureProxy> asTextureProxyRef() const override {
     41         return fProxy;
     42     }
     43     sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*, const GrSamplerState&, SkColorSpace*,
     44                                             sk_sp<SkColorSpace>*,
     45                                             SkScalar scaleAdjust[2]) const override;
     46 
     47     sk_sp<GrTextureProxy> refPinnedTextureProxy(uint32_t* uniqueID) const override {
     48         *uniqueID = this->uniqueID();
     49         return fProxy;
     50     }
     51     GrBackendObject onGetTextureHandle(bool flushPendingGrContextIO,
     52                                        GrSurfaceOrigin* origin) const override;
     53     GrTexture* onGetTexture() const override;
     54 
     55     bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
     56                       int srcX, int srcY, CachingHint) const override;
     57 
     58     sk_sp<SkColorSpace> refColorSpace() { return fColorSpace; }
     59 
     60     sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>, SkColorType,
     61                                     SkTransferFunctionBehavior) const override;
     62 
     63     bool onIsValid(GrContext*) const override;
     64 
     65 private:
     66     GrContext*             fContext;
     67     sk_sp<GrTextureProxy>  fProxy;
     68     const SkAlphaType      fAlphaType;
     69     const SkBudgeted       fBudgeted;
     70     sk_sp<SkColorSpace>    fColorSpace;
     71     mutable SkAtomic<bool> fAddedRasterVersionToCache;
     72 
     73 
     74     typedef SkImage_Base INHERITED;
     75 };
     76 
     77 #endif
     78