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

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

Issue 1249543003: Creating functions for uploading a mipmapped texture. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Storing the max mipmap level in the texture. 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
2 /* 1 /*
3 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
4 * 3 *
5 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 7
9 #include "GrTextureProvider.h" 8 #include "GrTextureProvider.h"
10 #include "GrTexturePriv.h" 9 #include "GrTexturePriv.h"
11 #include "GrResourceCache.h" 10 #include "GrResourceCache.h"
(...skipping 12 matching lines...) Expand all
24 GrTextureProvider::GrTextureProvider(GrGpu* gpu, GrResourceCache* cache, GrSingl eOwner* singleOwner) 23 GrTextureProvider::GrTextureProvider(GrGpu* gpu, GrResourceCache* cache, GrSingl eOwner* singleOwner)
25 : fCache(cache) 24 : fCache(cache)
26 , fGpu(gpu) 25 , fGpu(gpu)
27 #ifdef SK_DEBUG 26 #ifdef SK_DEBUG
28 , fSingleOwner(singleOwner) 27 , fSingleOwner(singleOwner)
29 #endif 28 #endif
30 { 29 {
31 } 30 }
32 31
33 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg eted, 32 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg eted,
34 const void* srcData, size_t rowBytes ) { 33 const SkTArray<SkMipMapLevel>& texel s) {
35 ASSERT_SINGLE_OWNER 34 ASSERT_SINGLE_OWNER
35
36 if (this->isAbandoned()) { 36 if (this->isAbandoned()) {
37 return nullptr; 37 return nullptr;
38 } 38 }
39 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && 39 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
40 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 40 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
41 return nullptr; 41 return nullptr;
42 } 42 }
43 if (!GrPixelConfigIsCompressed(desc.fConfig)) { 43 if (!GrPixelConfigIsCompressed(desc.fConfig)) {
44 static const uint32_t kFlags = kExact_ScratchTextureFlag | 44 // In the case of mipmaps, do not use a scratch texture
45 kNoCreate_ScratchTextureFlag; 45 if (texels.count() < 2) {
46 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { 46 const SkMipMapLevel& baseMipLevel = texels[0];
47 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight , desc.fConfig, 47 static const uint32_t kFlags = kExact_ScratchTextureFlag |
48 srcData, rowBytes)) { 48 kNoCreate_ScratchTextureFlag;
49 if (!budgeted) { 49 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) {
50 texture->resourcePriv().makeUnbudgeted(); 50 if (texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.f Config,
51 baseMipLevel.fTexelsOrOffset, baseMipLe vel.fRowBytes)) {
52 if (!budgeted) {
53 texture->resourcePriv().makeUnbudgeted();
54 }
55 return texture;
51 } 56 }
52 return texture; 57 texture->unref();
53 } 58 }
54 texture->unref();
55 } 59 }
56 } 60 }
57 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); 61 return fGpu->createTexture(desc, budgeted, texels);
62 }
63
64 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg eted,
65 const void* srcData, size_t rowBytes ) {
66 SkMipMapLevel level(srcData, rowBytes, desc.fWidth, desc.fHeight);
67 SkSTArray<1, SkMipMapLevel> texels;
68 texels.push_back(level);
69
70 return this->createTexture(desc, budgeted, texels);
58 } 71 }
59 72
60 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { 73 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) {
61 ASSERT_SINGLE_OWNER 74 ASSERT_SINGLE_OWNER
62 return this->internalCreateApproxTexture(desc, 0); 75 return this->internalCreateApproxTexture(desc, 0);
63 } 76 }
64 77
65 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d esc, 78 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d esc,
66 uint32_t scratchFlags) { 79 uint32_t scratchFlags) {
67 ASSERT_SINGLE_OWNER 80 ASSERT_SINGLE_OWNER
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke y) { 172 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke y) {
160 ASSERT_SINGLE_OWNER 173 ASSERT_SINGLE_OWNER
161 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); 174 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key);
162 if (resource) { 175 if (resource) {
163 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); 176 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture();
164 SkASSERT(texture); 177 SkASSERT(texture);
165 return texture; 178 return texture;
166 } 179 }
167 return NULL; 180 return NULL;
168 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698