blob: 87f0d5ab0a893826a7500f2b3777d49c57c14114 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
reed@google.comac10a2d2010-12-22 21:39:39 +00009#ifndef GrTexture_DEFINED
10#define GrTexture_DEFINED
11
robertphillips@google.com7d501ab2012-06-21 21:09:06 +000012#include "GrSurface.h"
bsalomonc44be0e2014-07-25 07:32:33 -070013#include "SkPoint.h"
14#include "SkRefCnt.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000015
robertphillips@google.coma1e57952012-06-04 20:05:28 +000016class GrResourceKey;
bsalomon@google.comb8670992012-07-25 21:27:09 +000017class GrTextureParams;
bsalomonafbf2d62014-09-30 12:18:44 -070018class GrTexturePriv;
reed@google.comac10a2d2010-12-22 21:39:39 +000019
bsalomon37dd3312014-11-03 08:47:23 -080020class GrTexture : virtual public GrSurface {
reed@google.comac10a2d2010-12-22 21:39:39 +000021public:
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000022 /**
23 * Approximate number of bytes used by the texture
24 */
25 virtual size_t gpuMemorySize() const SK_OVERRIDE;
26
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000027 virtual GrTexture* asTexture() SK_OVERRIDE { return this; }
28 virtual const GrTexture* asTexture() const SK_OVERRIDE { return this; }
29
30 /**
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000031 * Return the native ID or handle to the texture, depending on the
32 * platform. e.g. on OpenGL, return the texture ID.
33 */
34 virtual GrBackendObject getTextureHandle() const = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +000035
junov@chromium.org957ebdd2012-06-12 13:58:36 +000036 /**
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000037 * This function indicates that the texture parameters (wrap mode, filtering, ...) have been
38 * changed externally to Skia.
junov@chromium.org957ebdd2012-06-12 13:58:36 +000039 */
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000040 virtual void textureParamsModified() = 0;
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000041
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000042#ifdef SK_DEBUG
43 void validate() const {
44 this->INHERITED::validate();
commit-bot@chromium.org59e7d232014-05-09 18:02:51 +000045 this->validateDesc();
46 }
47#endif
48
bsalomonafbf2d62014-09-30 12:18:44 -070049 /** Access methods that are only to be used within Skia code. */
50 inline GrTexturePriv texturePriv();
51 inline const GrTexturePriv texturePriv() const;
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000052
53protected:
bsalomonf2703d82014-10-28 14:33:06 -070054 GrTexture(GrGpu* gpu, bool isWrapped, const GrSurfaceDesc& desc);
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000055
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000056 void validateDesc() const;
57
58private:
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +000059 void dirtyMipMaps(bool mipMapsDirty);
60
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000061 enum MipMapsStatus {
62 kNotAllocated_MipMapsStatus,
63 kAllocated_MipMapsStatus,
64 kValid_MipMapsStatus
65 };
66
bsalomonafbf2d62014-09-30 12:18:44 -070067 MipMapsStatus fMipMapsStatus;
68 // These two shift a fixed-point value into normalized coordinates
69 // for this texture if the texture is power of two sized.
70 int fShiftFixedX;
71 int fShiftFixedY;
reed@google.comac10a2d2010-12-22 21:39:39 +000072
bsalomonafbf2d62014-09-30 12:18:44 -070073 friend class GrTexturePriv;
74
75 typedef GrSurface INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +000076};
77
bsalomon@google.com26e18b52013-03-29 19:22:36 +000078/**
79 * Represents a texture that is intended to be accessed in device coords with an offset.
80 */
81class GrDeviceCoordTexture {
82public:
83 GrDeviceCoordTexture() { fOffset.set(0, 0); }
84
85 GrDeviceCoordTexture(const GrDeviceCoordTexture& other) {
86 *this = other;
87 }
88
89 GrDeviceCoordTexture(GrTexture* texture, const SkIPoint& offset)
90 : fTexture(SkSafeRef(texture))
91 , fOffset(offset) {
92 }
93
94 GrDeviceCoordTexture& operator=(const GrDeviceCoordTexture& other) {
95 fTexture.reset(SkSafeRef(other.fTexture.get()));
96 fOffset = other.fOffset;
97 return *this;
98 }
99
100 const SkIPoint& offset() const { return fOffset; }
101
102 void setOffset(const SkIPoint& offset) { fOffset = offset; }
103 void setOffset(int ox, int oy) { fOffset.set(ox, oy); }
104
105 GrTexture* texture() const { return fTexture.get(); }
106
107 GrTexture* setTexture(GrTexture* texture) {
108 fTexture.reset(SkSafeRef(texture));
109 return texture;
110 }
commit-bot@chromium.orge49157f2014-05-09 20:46:48 +0000111
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000112private:
113 SkAutoTUnref<GrTexture> fTexture;
114 SkIPoint fOffset;
115};
116
reed@google.comac10a2d2010-12-22 21:39:39 +0000117#endif