Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/gpu/GrTexture.cpp

Issue 1249543003: Creating functions for uploading a mipmapped texture. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Cleaning up the allocated SkMipMap object. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "GrCaps.h" 10 #include "GrCaps.h"
11 #include "GrGpu.h" 11 #include "GrGpu.h"
12 #include "GrResourceKey.h" 12 #include "GrResourceKey.h"
13 #include "GrRenderTarget.h" 13 #include "GrRenderTarget.h"
14 #include "GrRenderTargetPriv.h" 14 #include "GrRenderTargetPriv.h"
15 #include "GrTexture.h" 15 #include "GrTexture.h"
16 #include "GrTexturePriv.h" 16 #include "GrTexturePriv.h"
17 #include "SkMath.h"
18 #include "SkMipMapLevel.h"
19 #include "SkTypes.h"
17 20
18 void GrTexture::dirtyMipMaps(bool mipMapsDirty) { 21 void GrTexture::dirtyMipMaps(bool mipMapsDirty) {
19 if (mipMapsDirty) { 22 if (mipMapsDirty) {
20 if (kValid_MipMapsStatus == fMipMapsStatus) { 23 if (kValid_MipMapsStatus == fMipMapsStatus) {
21 fMipMapsStatus = kAllocated_MipMapsStatus; 24 fMipMapsStatus = kAllocated_MipMapsStatus;
22 } 25 }
23 } else { 26 } else {
24 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; 27 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus;
25 fMipMapsStatus = kValid_MipMapsStatus; 28 fMipMapsStatus = kValid_MipMapsStatus;
26 if (sizeChanged) { 29 if (sizeChanged) {
27 // This must not be called until after changing fMipMapsStatus. 30 // This must not be called until after changing fMipMapsStatus.
28 this->didChangeGpuMemorySize(); 31 this->didChangeGpuMemorySize();
32 // TODO(http://skbug.com/4548) - The desc and scratch key should be
33 // updated to reflect the newly-allocated mipmaps.
29 } 34 }
30 } 35 }
31 } 36 }
32 37
33 size_t GrTexture::onGpuMemorySize() const { 38 size_t GrTexture::onGpuMemorySize() const {
34 size_t textureSize; 39 size_t textureSize;
35 40
36 if (GrPixelConfigIsCompressed(fDesc.fConfig)) { 41 if (GrPixelConfigIsCompressed(fDesc.fConfig)) {
37 textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fD esc.fHeight); 42 textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fD esc.fHeight);
38 } else { 43 } else {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin; 81 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin;
77 } else { 82 } else {
78 return desc.fOrigin; 83 return desc.fOrigin;
79 } 84 }
80 } 85 }
81 } 86 }
82 87
83 ////////////////////////////////////////////////////////////////////////////// 88 //////////////////////////////////////////////////////////////////////////////
84 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc) 89 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc)
85 : INHERITED(gpu, lifeCycle, desc) 90 : INHERITED(gpu, lifeCycle, desc)
86 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { 91 , fMipMapsStatus(kNotAllocated_MipMapsStatus)
87 92 , fMaxMipMapLevel(0) {
88 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) { 93 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) {
89 GrScratchKey key; 94 GrScratchKey key;
90 GrTexturePriv::ComputeScratchKey(desc, &key); 95 GrTexturePriv::ComputeScratchKey(desc, &key);
96 this->setScratchKey(key);
97 }
98 // only make sense if alloc size is pow2
99 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
100 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight);
101 }
102
103 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc,
104 bool wasMipMapDataProvided)
105 : INHERITED(gpu, lifeCycle, desc) {
106 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) {
107 GrScratchKey key;
108 GrTexturePriv::ComputeScratchKey(desc, &key);
91 this->setScratchKey(key); 109 this->setScratchKey(key);
92 } 110 }
93 // only make sense if alloc size is pow2 111 // only make sense if alloc size is pow2
94 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); 112 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
95 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); 113 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight);
114
115 if (wasMipMapDataProvided) {
116 fMipMapsStatus = kValid_MipMapsStatus;
117 fMaxMipMapLevel = SkMipMapLevelCount(fDesc.fWidth, fDesc.fHeight);
118 } else {
119 fMipMapsStatus = kNotAllocated_MipMapsStatus;
120 fMaxMipMapLevel = 0;
121 }
96 } 122 }
97 123
98 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k ey) { 124 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k ey) {
99 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour ceType(); 125 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour ceType();
100 126
101 GrSurfaceOrigin origin = resolve_origin(desc); 127 GrSurfaceOrigin origin = resolve_origin(desc);
102 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; 128 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag;
103 129
104 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 6)); 130 // make sure desc.fConfig fits in 5 bits
131 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5);
132 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5));
105 SkASSERT(desc.fSampleCnt < (1 << 8)); 133 SkASSERT(desc.fSampleCnt < (1 << 8));
106 SkASSERT(flags < (1 << 10)); 134 SkASSERT(flags < (1 << 10));
107 SkASSERT(static_cast<int>(origin) < (1 << 8)); 135 SkASSERT(static_cast<int>(origin) < (1 << 8));
108 136
109 GrScratchKey::Builder builder(key, kType, 3); 137 GrScratchKey::Builder builder(key, kType, 3);
110 builder[0] = desc.fWidth; 138 builder[0] = desc.fWidth;
111 builder[1] = desc.fHeight; 139 builder[1] = desc.fHeight;
112 builder[2] = desc.fConfig | (desc.fSampleCnt << 6) | (flags << 14) | (origin << 24); 140 builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6 ) | (flags << 14)
141 | (origin << 24);
113 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698