1 2 /* 3 * Copyright 2011 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 #ifndef GrTexture_DEFINED 10 #define GrTexture_DEFINED 11 12 #include "GrSurface.h" 13 #include "SkPoint.h" 14 #include "SkRefCnt.h" 15 16 class GrTextureParams; 17 class GrTexturePriv; 18 19 class GrTexture : virtual public GrSurface { 20 public: asTexture()21 GrTexture* asTexture() override { return this; } asTexture()22 const GrTexture* asTexture() const override { return this; } 23 24 /** 25 * Return the native ID or handle to the texture, depending on the 26 * platform. e.g. on OpenGL, return the texture ID. 27 */ 28 virtual GrBackendObject getTextureHandle() const = 0; 29 30 /** 31 * This function indicates that the texture parameters (wrap mode, filtering, ...) have been 32 * changed externally to Skia. 33 */ 34 virtual void textureParamsModified() = 0; 35 36 #ifdef SK_DEBUG validate()37 void validate() const { 38 this->INHERITED::validate(); 39 this->validateDesc(); 40 } 41 #endif 42 43 /** Access methods that are only to be used within Skia code. */ 44 inline GrTexturePriv texturePriv(); 45 inline const GrTexturePriv texturePriv() const; 46 47 protected: 48 GrTexture(GrGpu*, LifeCycle, const GrSurfaceDesc&); 49 50 void validateDesc() const; 51 52 private: 53 size_t onGpuMemorySize() const override; 54 void dirtyMipMaps(bool mipMapsDirty); 55 56 enum MipMapsStatus { 57 kNotAllocated_MipMapsStatus, 58 kAllocated_MipMapsStatus, 59 kValid_MipMapsStatus 60 }; 61 62 MipMapsStatus fMipMapsStatus; 63 // These two shift a fixed-point value into normalized coordinates 64 // for this texture if the texture is power of two sized. 65 int fShiftFixedX; 66 int fShiftFixedY; 67 68 friend class GrTexturePriv; 69 70 typedef GrSurface INHERITED; 71 }; 72 73 /** 74 * Represents a texture that is intended to be accessed in device coords with an offset. 75 */ 76 class GrDeviceCoordTexture { 77 public: GrDeviceCoordTexture()78 GrDeviceCoordTexture() { fOffset.set(0, 0); } 79 GrDeviceCoordTexture(const GrDeviceCoordTexture & other)80 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) { 81 *this = other; 82 } 83 GrDeviceCoordTexture(GrTexture * texture,const SkIPoint & offset)84 GrDeviceCoordTexture(GrTexture* texture, const SkIPoint& offset) 85 : fTexture(SkSafeRef(texture)) 86 , fOffset(offset) { 87 } 88 89 GrDeviceCoordTexture& operator=(const GrDeviceCoordTexture& other) { 90 fTexture.reset(SkSafeRef(other.fTexture.get())); 91 fOffset = other.fOffset; 92 return *this; 93 } 94 offset()95 const SkIPoint& offset() const { return fOffset; } 96 setOffset(const SkIPoint & offset)97 void setOffset(const SkIPoint& offset) { fOffset = offset; } setOffset(int ox,int oy)98 void setOffset(int ox, int oy) { fOffset.set(ox, oy); } 99 texture()100 GrTexture* texture() const { return fTexture.get(); } 101 setTexture(GrTexture * texture)102 GrTexture* setTexture(GrTexture* texture) { 103 fTexture.reset(SkSafeRef(texture)); 104 return texture; 105 } 106 107 private: 108 SkAutoTUnref<GrTexture> fTexture; 109 SkIPoint fOffset; 110 }; 111 112 #endif 113