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: Moving glTexStorage over to a separate CL. 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 "SkFloatingPoint.h"
17 18
18 void GrTexture::dirtyMipMaps(bool mipMapsDirty) { 19 void GrTexture::dirtyMipMaps(bool mipMapsDirty) {
19 if (mipMapsDirty) { 20 if (mipMapsDirty) {
20 if (kValid_MipMapsStatus == fMipMapsStatus) { 21 if (kValid_MipMapsStatus == fMipMapsStatus) {
21 fMipMapsStatus = kAllocated_MipMapsStatus; 22 fMipMapsStatus = kAllocated_MipMapsStatus;
22 } 23 }
23 } else { 24 } else {
24 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus; 25 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus;
25 fMipMapsStatus = kValid_MipMapsStatus; 26 fMipMapsStatus = kValid_MipMapsStatus;
26 if (sizeChanged) { 27 if (sizeChanged) {
27 // This must not be called until after changing fMipMapsStatus. 28 // This must not be called until after changing fMipMapsStatus.
28 this->didChangeGpuMemorySize(); 29 this->didChangeGpuMemorySize();
30 // TODO(http://skbug.com/4548) - The desc and scratch key should be
31 // updated to reflect the newly-allocated mipmaps.
29 } 32 }
30 } 33 }
31 } 34 }
32 35
33 size_t GrTexture::onGpuMemorySize() const { 36 size_t GrTexture::onGpuMemorySize() const {
34 size_t textureSize; 37 size_t textureSize;
35 38
36 if (GrPixelConfigIsCompressed(fDesc.fConfig)) { 39 if (GrPixelConfigIsCompressed(fDesc.fConfig)) {
37 textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fD esc.fHeight); 40 textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fD esc.fHeight);
38 } else { 41 } else {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } else { 80 } else {
78 return desc.fOrigin; 81 return desc.fOrigin;
79 } 82 }
80 } 83 }
81 } 84 }
82 85
83 ////////////////////////////////////////////////////////////////////////////// 86 //////////////////////////////////////////////////////////////////////////////
84 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc) 87 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc)
85 : INHERITED(gpu, lifeCycle, desc) 88 : INHERITED(gpu, lifeCycle, desc)
86 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { 89 , fMipMapsStatus(kNotAllocated_MipMapsStatus) {
87
88 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) { 90 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) {
89 GrScratchKey key; 91 GrScratchKey key;
90 GrTexturePriv::ComputeScratchKey(desc, &key); 92 GrTexturePriv::ComputeScratchKey(desc, &key);
93 this->setScratchKey(key);
94 }
95 // only make sense if alloc size is pow2
96 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
97 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight);
98 }
99
100 GrTexture::GrTexture(GrGpu* gpu, LifeCycle lifeCycle, const GrSurfaceDesc& desc,
101 bool wasMipMapDataProvided)
102 : INHERITED(gpu, lifeCycle, desc) {
103 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) {
104 GrScratchKey key;
105 GrTexturePriv::ComputeScratchKey(desc, &key);
91 this->setScratchKey(key); 106 this->setScratchKey(key);
92 } 107 }
93 // only make sense if alloc size is pow2 108 // only make sense if alloc size is pow2
94 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); 109 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
95 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); 110 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight);
111
112 if (wasMipMapDataProvided) {
113 fMipMapsStatus = kValid_MipMapsStatus;
114 } else {
115 fMipMapsStatus = kNotAllocated_MipMapsStatus;
116 }
96 } 117 }
97 118
98 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k ey) { 119 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k ey) {
99 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour ceType(); 120 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour ceType();
100 121
101 GrSurfaceOrigin origin = resolve_origin(desc); 122 GrSurfaceOrigin origin = resolve_origin(desc);
102 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; 123 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag;
103 124
104 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 6)); 125 // make sure desc.fConfig fits in 5 bits
126 SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5);
127 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5));
105 SkASSERT(desc.fSampleCnt < (1 << 8)); 128 SkASSERT(desc.fSampleCnt < (1 << 8));
106 SkASSERT(flags < (1 << 10)); 129 SkASSERT(flags < (1 << 10));
107 SkASSERT(static_cast<int>(origin) < (1 << 8)); 130 SkASSERT(static_cast<int>(origin) < (1 << 8));
108 131
109 GrScratchKey::Builder builder(key, kType, 3); 132 GrScratchKey::Builder builder(key, kType, 3);
110 builder[0] = desc.fWidth; 133 builder[0] = desc.fWidth;
111 builder[1] = desc.fHeight; 134 builder[1] = desc.fHeight;
112 builder[2] = desc.fConfig | (desc.fSampleCnt << 6) | (flags << 14) | (origin << 24); 135 builder[2] = desc.fConfig | (desc.fIsMipMapped << 5) | (desc.fSampleCnt << 6 ) | (flags << 14)
136 | (origin << 24);
113 } 137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698