3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #ifndef GrTexture_DEFINED
10 #define GrTexture_DEFINED
12 #include "GrSurface.h"
16 class GrTextureParams;
19 class GrTexture : virtual public GrSurface {
21 GrTexture* asTexture() SK_OVERRIDE { return this; }
22 const GrTexture* asTexture() const SK_OVERRIDE { return this; }
25 * Return the native ID or handle to the texture, depending on the
26 * platform. e.g. on OpenGL, return the texture ID.
28 virtual GrBackendObject getTextureHandle() const = 0;
31 * This function indicates that the texture parameters (wrap mode, filtering, ...) have been
32 * changed externally to Skia.
34 virtual void textureParamsModified() = 0;
37 void validate() const {
38 this->INHERITED::validate();
43 /** Access methods that are only to be used within Skia code. */
44 inline GrTexturePriv texturePriv();
45 inline const GrTexturePriv texturePriv() const;
48 GrTexture(GrGpu*, LifeCycle, const GrSurfaceDesc&);
50 void validateDesc() const;
53 size_t onGpuMemorySize() const SK_OVERRIDE;
54 void dirtyMipMaps(bool mipMapsDirty);
57 kNotAllocated_MipMapsStatus,
58 kAllocated_MipMapsStatus,
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.
68 friend class GrTexturePriv;
70 typedef GrSurface INHERITED;
74 * Represents a texture that is intended to be accessed in device coords with an offset.
76 class GrDeviceCoordTexture {
78 GrDeviceCoordTexture() { fOffset.set(0, 0); }
80 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) {
84 GrDeviceCoordTexture(GrTexture* texture, const SkIPoint& offset)
85 : fTexture(SkSafeRef(texture))
89 GrDeviceCoordTexture& operator=(const GrDeviceCoordTexture& other) {
90 fTexture.reset(SkSafeRef(other.fTexture.get()));
91 fOffset = other.fOffset;
95 const SkIPoint& offset() const { return fOffset; }
97 void setOffset(const SkIPoint& offset) { fOffset = offset; }
98 void setOffset(int ox, int oy) { fOffset.set(ox, oy); }
100 GrTexture* texture() const { return fTexture.get(); }
102 GrTexture* setTexture(GrTexture* texture) {
103 fTexture.reset(SkSafeRef(texture));
108 SkAutoTUnref<GrTexture> fTexture;