1 /* 2 * Copyright 2016 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 GrTextureContext_DEFINED 9 #define GrTextureContext_DEFINED 10 11 #include "GrSurfaceContext.h" 12 #include "../private/GrTextureProxy.h" 13 14 class GrContext; 15 class GrDrawingManager; 16 class GrSurface; 17 class GrTextureOpList; 18 class GrTextureProxy; 19 struct SkIPoint; 20 struct SkIRect; 21 22 /** 23 * A helper object to orchestrate commands (currently just copies) for GrSurfaces that are 24 * GrTextures and not GrRenderTargets. 25 */ 26 class SK_API GrTextureContext : public GrSurfaceContext { 27 public: 28 ~GrTextureContext() override; 29 asSurfaceProxy()30 GrSurfaceProxy* asSurfaceProxy() override { return fTextureProxy.get(); } asSurfaceProxy()31 const GrSurfaceProxy* asSurfaceProxy() const override { return fTextureProxy.get(); } asSurfaceProxyRef()32 sk_sp<GrSurfaceProxy> asSurfaceProxyRef() override { return fTextureProxy; } 33 asTextureProxy()34 GrTextureProxy* asTextureProxy() override { return fTextureProxy.get(); } asTextureProxyRef()35 sk_sp<GrTextureProxy> asTextureProxyRef() override { return fTextureProxy; } 36 37 GrRenderTargetProxy* asRenderTargetProxy() override; 38 sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() override; 39 40 protected: 41 GrTextureContext(GrContext*, GrDrawingManager*, sk_sp<GrTextureProxy>, 42 sk_sp<SkColorSpace>, GrAuditTrail*, GrSingleOwner*); 43 44 SkDEBUGCODE(void validate() const;) 45 46 private: 47 friend class GrDrawingManager; // for ctor 48 49 bool onCopy(GrSurfaceProxy* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override; 50 bool onReadPixels(const SkImageInfo& dstInfo, void* dstBuffer, 51 size_t dstRowBytes, int x, int y, uint32_t flags) override; 52 bool onWritePixels(const SkImageInfo& srcInfo, const void* srcBuffer, 53 size_t srcRowBytes, int x, int y, uint32_t flags) override; 54 55 GrTextureOpList* getOpList(); 56 57 sk_sp<GrTextureProxy> fTextureProxy; 58 59 // In MDB-mode the GrOpList can be closed by some other renderTargetContext that has picked 60 // it up. For this reason, the GrOpList should only ever be accessed via 'getOpList'. 61 GrTextureOpList* fOpList; 62 63 typedef GrSurfaceContext INHERITED; 64 }; 65 66 #endif 67