blob: d6c2dc2bf8f6d626e717edfdbb426f72bdb15452 [file] [log] [blame]
bsalomonafbf2d62014-09-30 12:18:44 -07001/*
2 * Copyright 2014 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 GrTexturePriv_DEFINED
9#define GrTexturePriv_DEFINED
10
11#include "GrTexture.h"
12
13/** Class that adds methods to GrTexture that are only intended for use internal to Skia.
14 This class is purely a privileged window into GrTexture. It should never have additional data
15 members or virtual methods.
16 Non-static methods that are not trivial inlines should be spring-boarded (e.g. declared and
17 implemented privately in GrTexture with a inline public method here). */
18class GrTexturePriv {
19public:
bsalomonf2703d82014-10-28 14:33:06 -070020 void setFlag(GrSurfaceFlags flags) {
bsalomonafbf2d62014-09-30 12:18:44 -070021 fTexture->fDesc.fFlags = fTexture->fDesc.fFlags | flags;
22 }
23
bsalomonf2703d82014-10-28 14:33:06 -070024 void resetFlag(GrSurfaceFlags flags) {
bsalomonafbf2d62014-09-30 12:18:44 -070025 fTexture->fDesc.fFlags = fTexture->fDesc.fFlags & ~flags;
26 }
27
bsalomonf2703d82014-10-28 14:33:06 -070028 bool isSetFlag(GrSurfaceFlags flags) const {
bsalomonafbf2d62014-09-30 12:18:44 -070029 return 0 != (fTexture->fDesc.fFlags & flags);
30 }
31
32 void dirtyMipMaps(bool mipMapsDirty) { fTexture->dirtyMipMaps(mipMapsDirty); }
33
34 bool mipMapsAreDirty() const {
35 return GrTexture::kValid_MipMapsStatus != fTexture->fMipMapsStatus;
36 }
37
38 bool hasMipMaps() const {
39 return GrTexture::kNotAllocated_MipMapsStatus != fTexture->fMipMapsStatus;
40 }
41
bsalomonbcf0a522014-10-08 08:40:09 -070042 static GrResourceKey::ResourceType ResourceType() {
43 static const GrResourceKey::ResourceType gType = GrResourceKey::GenerateResourceType();
44 return gType;
45 }
46
bsalomonafbf2d62014-09-30 12:18:44 -070047 static GrResourceKey ComputeKey(const GrGpu* gpu,
48 const GrTextureParams* params,
bsalomonf2703d82014-10-28 14:33:06 -070049 const GrSurfaceDesc& desc,
bsalomonafbf2d62014-09-30 12:18:44 -070050 const GrCacheID& cacheID);
bsalomonf2703d82014-10-28 14:33:06 -070051 static GrResourceKey ComputeScratchKey(const GrSurfaceDesc& desc);
bsalomonafbf2d62014-09-30 12:18:44 -070052 static bool NeedsResizing(const GrResourceKey& key);
53 static bool NeedsBilerp(const GrResourceKey& key);
54
55
56 // TODO: Move this logic and the shift values out of here and to the callers.
57 SkFixed normalizeFixedX(SkFixed x) const {
58 SkASSERT(SkIsPow2(fTexture->fDesc.fWidth));
59 return x >> fTexture->fShiftFixedX;
60 }
61
62 SkFixed normalizeFixedY(SkFixed y) const {
63 SkASSERT(SkIsPow2(fTexture->fDesc.fHeight));
64 return y >> fTexture->fShiftFixedY;
65 }
66
67private:
68 GrTexturePriv(GrTexture* texture) : fTexture(texture) { }
69 GrTexturePriv(const GrTexturePriv& that) : fTexture(that.fTexture) { }
70 GrTexturePriv& operator=(const GrTexturePriv&); // unimpl
71
72 // No taking addresses of this type.
73 const GrTexturePriv* operator&() const;
74 GrTexturePriv* operator&();
75
76 GrTexture* fTexture;
77
78 friend class GrTexture; // to construct/copy this type.
79};
80
81inline GrTexturePriv GrTexture::texturePriv() { return GrTexturePriv(this); }
82
83inline const GrTexturePriv GrTexture::texturePriv () const {
84 return GrTexturePriv(const_cast<GrTexture*>(this));
85}
86
87#endif