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

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: Removing the concept of a dirty mipmap. It is expected that the texture upload provides the mipmaps. Created 5 years, 3 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 17 #include <cmath>
18 void GrTexture::dirtyMipMaps(bool mipMapsDirty) {
19 if (mipMapsDirty) {
20 if (kValid_MipMapsStatus == fMipMapsStatus) {
21 fMipMapsStatus = kAllocated_MipMapsStatus;
22 }
23 } else {
24 const bool sizeChanged = kNotAllocated_MipMapsStatus == fMipMapsStatus;
25 fMipMapsStatus = kValid_MipMapsStatus;
26 if (sizeChanged) {
27 // This must not be called until after changing fMipMapsStatus.
28 this->didChangeGpuMemorySize();
29 }
30 }
31 }
32 18
33 size_t GrTexture::onGpuMemorySize() const { 19 size_t GrTexture::onGpuMemorySize() const {
34 size_t textureSize; 20 size_t textureSize;
35 21
36 if (GrPixelConfigIsCompressed(fDesc.fConfig)) { 22 if (GrPixelConfigIsCompressed(fDesc.fConfig)) {
37 textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fD esc.fHeight); 23 textureSize = GrCompressedFormatDataSize(fDesc.fConfig, fDesc.fWidth, fD esc.fHeight);
38 } else { 24 } else {
39 textureSize = (size_t) fDesc.fWidth * fDesc.fHeight * GrBytesPerPixel(fD esc.fConfig); 25 textureSize = (size_t) fDesc.fWidth * fDesc.fHeight * GrBytesPerPixel(fD esc.fConfig);
40 } 26 }
41 27
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 , fMipMapsStatus(kNotAllocated_MipMapsStatus) { 72 , fMipMapsStatus(kNotAllocated_MipMapsStatus) {
87 73
88 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) { 74 if (!this->isExternal() && !GrPixelConfigIsCompressed(desc.fConfig)) {
89 GrScratchKey key; 75 GrScratchKey key;
90 GrTexturePriv::ComputeScratchKey(desc, &key); 76 GrTexturePriv::ComputeScratchKey(desc, &key);
91 this->setScratchKey(key); 77 this->setScratchKey(key);
92 } 78 }
93 // only make sense if alloc size is pow2 79 // only make sense if alloc size is pow2
94 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); 80 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
95 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); 81 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight);
82 if (desc.fIsMipMapped) {
83 fMipMapsStatus = kAllocated_MipMapsStatus;
84 } else {
85 fMipMapsStatus = kNotAllocated_MipMapsStatus;
86 }
96 } 87 }
97 88
98 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k ey) { 89 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k ey) {
99 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour ceType(); 90 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour ceType();
100 91
101 GrScratchKey::Builder builder(key, kType, 2); 92 GrScratchKey::Builder builder(key, kType, 2);
102 93
103 GrSurfaceOrigin origin = resolve_origin(desc); 94 GrSurfaceOrigin origin = resolve_origin(desc);
104 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; 95 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag;
105 96
106 SkASSERT(desc.fWidth <= SK_MaxU16); 97 SkASSERT(desc.fWidth <= SK_MaxU16);
107 SkASSERT(desc.fHeight <= SK_MaxU16); 98 SkASSERT(desc.fHeight <= SK_MaxU16);
108 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 6)); 99 // make sure desc.fConfig fits in 5 bits
100 SkASSERT(log2(kLast_GrPixelConfig) <= 5);
bsalomon 2015/09/15 13:14:11 Can you use sk_float_log2? It looks like it works
cblume 2015/09/16 18:40:46 Good catch.
101 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 5));
109 SkASSERT(desc.fSampleCnt < (1 << 8)); 102 SkASSERT(desc.fSampleCnt < (1 << 8));
110 SkASSERT(flags < (1 << 10)); 103 SkASSERT(flags < (1 << 10));
111 SkASSERT(static_cast<int>(origin) < (1 << 8)); 104 SkASSERT(static_cast<int>(origin) < (1 << 8));
112 105
113 builder[0] = desc.fWidth | (desc.fHeight << 16); 106 builder[0] = desc.fWidth | (desc.fHeight << 16);
114 builder[1] = desc.fConfig | (desc.fSampleCnt << 6) | (flags << 14) | (origin << 24); 107 builder[1] = desc.fConfig | desc.fIsMipMapped << 5 | (desc.fSampleCnt << 6) | (flags << 14) | (origin << 24);
bsalomon 2015/09/15 13:14:11 100 col wrap
cblume 2015/09/16 18:40:46 Done.
115 } 108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698