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

Unified Diff: src/gpu/GrGpu.cpp

Issue 1249543003: Creating functions for uploading a mipmapped texture. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: No longer exposing SkMipMap and SkCachedData. Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrGpu.cpp
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 728fb880622010fa9495932d467b7f6df7d3ff04..a595eaebfb241dd440d89be1403c9311c827b98a 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2010 Google Inc.
*
@@ -64,73 +63,110 @@ static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget)
}
}
-GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted,
- const void* srcData, size_t rowBytes) {
- GrSurfaceDesc desc = origDesc;
-
- if (!this->caps()->isConfigTexturable(desc.fConfig)) {
- return NULL;
+/**
+ * Prior to creating a texture, make sure the type of texture being created is
+ * supported by calling check_texture_creation_params.
+ *
+ * @param caps The capabilities of the GL device.
+ * @param desc The descriptor of the texture to create.
+ * @param isRT Indicates if the texture be a render target.
+ */
+static bool check_texture_creation_params(const GrCaps& caps, const GrSurfaceDesc& desc,
+ bool* isRT) {
+ if (!caps.isConfigTexturable(desc.fConfig)) {
+ return false;
}
- bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
- if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
- return NULL;
+ *isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
+ if (*isRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+ return false;
}
- // We currently not support multisampled textures
- if (!isRT && desc.fSampleCnt > 0) {
- return NULL;
+ // We currently do not support multisampled textures
+ if (!*isRT && desc.fSampleCnt > 0) {
+ return false;
}
- GrTexture *tex = NULL;
-
- if (isRT) {
- int maxRTSize = this->caps()->maxRenderTargetSize();
+ if (*isRT) {
+ int maxRTSize = caps.maxRenderTargetSize();
if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
- return NULL;
+ return false;
}
} else {
- int maxSize = this->caps()->maxTextureSize();
+ int maxSize = caps.maxTextureSize();
if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
- return NULL;
+ return false;
}
}
+ return true;
+}
+
+GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted,
+ SkTArray<SkMipMapLevel>& texels) {
+ GrSurfaceDesc desc = origDesc;
+
+ const GrCaps* caps = this->caps();
+ if (!caps) {
+ return NULL;
+ } else {
+ bool isRT = false;
+ bool textureCreationParamsValid = check_texture_creation_params(*caps, desc, &isRT);
+ if (!textureCreationParamsValid) {
+ return NULL;
+ }
- GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
- GrGpuResource::kUncached_LifeCycle;
+ desc.fSampleCnt = SkTMin(desc.fSampleCnt, caps->maxSampleCount());
+ // Attempt to catch un- or wrongly initialized sample counts;
+ SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
- desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
- // Attempt to catch un- or wrongly initialized sample counts;
- SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
+ desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
- desc.fOrigin = resolve_origin(desc.fOrigin, isRT);
+ GrTexture *tex = NULL;
+ GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
+ GrGpuResource::kUncached_LifeCycle;
- if (GrPixelConfigIsCompressed(desc.fConfig)) {
- // We shouldn't be rendering into this
- SkASSERT(!isRT);
- SkASSERT(0 == desc.fSampleCnt);
+ if (GrPixelConfigIsCompressed(desc.fConfig)) {
+ // We shouldn't be rendering into this
+ SkASSERT(!isRT);
+ SkASSERT(0 == desc.fSampleCnt);
- if (!this->caps()->npotTextureTileSupport() &&
- (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
- return NULL;
- }
+ if (!caps->npotTextureTileSupport() &&
+ (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
+ return NULL;
+ }
- this->handleDirtyContext();
- tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData);
- } else {
- this->handleDirtyContext();
- tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes);
- }
- if (!this->caps()->reuseScratchTextures() && !isRT) {
- tex->resourcePriv().removeScratchKey();
- }
- if (tex) {
- fStats.incTextureCreates();
- if (srcData) {
- fStats.incTextureUploads();
+ this->handleDirtyContext();
+ tex = this->onCreateCompressedTexture(desc, lifeCycle, texels);
+ } else {
+ this->handleDirtyContext();
+ tex = this->onCreateTexture(desc, lifeCycle, texels);
+ }
+ if (tex) {
+ /* TODO: I am unsure how to use a scratch texture well with mipmaps
bsalomon 2015/08/26 18:30:11 I think we should just include mip status in the s
cblume 2015/08/26 18:58:00 Thinking out loud: A bool of "is mipmapped" may no
bsalomon 2015/08/27 13:22:49 Why don't we just require either just a base level
+ if (!caps->reuseScratchTextures() && !isRT) {
+ tex->resourcePriv().removeScratchKey();
+ }
+ */
+ fStats.incTextureCreates();
+ if (!texels.empty()) {
+ if (texels[0].fTexels) {
+ fStats.incTextureUploads();
+ }
+ }
}
+ return tex;
}
- return tex;
+}
+
+GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, bool budgeted,
+ const void* srcData, size_t rowBytes) {
+ SkMipMapLevel level(srcData, rowBytes);
+
+ const int mipLevelCount = 1;
+ SkTArray<SkMipMapLevel> levels(mipLevelCount);
+ levels.push_back(level);
+
+ return createTexture(desc, budgeted, levels);
}
bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) {
@@ -243,17 +279,28 @@ bool GrGpu::readPixels(GrRenderTarget* target,
bool GrGpu::writeTexturePixels(GrTexture* texture,
int left, int top, int width, int height,
- GrPixelConfig config, const void* buffer,
- size_t rowBytes) {
+ GrPixelConfig config,
+ SkTArray<SkMipMapLevel>& texels) {
this->handleDirtyContext();
if (this->onWriteTexturePixels(texture, left, top, width, height,
- config, buffer, rowBytes)) {
+ config, texels)) {
fStats.incTextureUploads();
return true;
}
return false;
}
+bool GrGpu::writeTexturePixels(GrTexture* texture,
+ int left, int top, int width, int height,
+ GrPixelConfig config, const void* buffer,
+ size_t rowBytes) {
+ SkMipMapLevel mipLevel(buffer, rowBytes);
+ SkTArray<SkMipMapLevel> texels;
+ texels.push_back(mipLevel);
+
+ writeTexturePixels(texture, left, top, width, height, config, texels);
+}
+
void GrGpu::resolveRenderTarget(GrRenderTarget* target) {
SkASSERT(target);
this->handleDirtyContext();
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrTextureProvider.cpp » ('j') | src/gpu/GrTextureProvider.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698