aboutsummaryrefslogtreecommitdiff
path: root/src/gpu/GrContext.cpp
diff options
context:
space:
mode:
authorbsalomon <bsalomon@google.com>2014-09-29 14:20:11 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-29 14:20:11 -0700
commitc0eb9b9818462471f5fc1c47fa549c6052d8bbae (patch)
tree9da0008e6fe68fbe2010ad14f5e6c54c7fa5008b /src/gpu/GrContext.cpp
parentc5e15a1afab2621e860a251c3fcf5917867ad49f (diff)
downloadskia-c0eb9b9818462471f5fc1c47fa549c6052d8bbae.tar.gz
Make "priv" classes for GrTexure and GrSurface.
R=robertphillips@google.com, egdaniel@google.com, joshualitt@google.com, joshualitt@chromium.org Author: bsalomon@google.com Review URL: https://codereview.chromium.org/596053002
Diffstat (limited to 'src/gpu/GrContext.cpp')
-rwxr-xr-xsrc/gpu/GrContext.cpp41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index d55aed92f..46a5576b1 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -30,7 +30,9 @@
#include "GrStencilBuffer.h"
#include "GrStencilAndCoverTextContext.h"
#include "GrStrokeInfo.h"
+#include "GrSurfacePriv.h"
#include "GrTextStrike.h"
+#include "GrTexturePriv.h"
#include "GrTraceMarker.h"
#include "GrTracing.h"
#include "SkDashPathPriv.h"
@@ -68,6 +70,25 @@ static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4;
#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
+GrTexture* GrAutoScratchTexture::detach() {
+ if (NULL == fTexture) {
+ return NULL;
+ }
+ GrTexture* texture = fTexture;
+ fTexture = NULL;
+
+ // This GrAutoScratchTexture has a ref from lockAndRefScratchTexture, which we give up now.
+ // The cache also has a ref which we are lending to the caller of detach(). When the caller
+ // lets go of the ref and the ref count goes to 0 internal_dispose will see this flag is
+ // set and re-ref the texture, thereby restoring the cache's ref.
+ SkASSERT(!texture->unique());
+ texture->texturePriv().setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit);
+ texture->unref();
+ SkASSERT(texture->getCacheEntry());
+
+ return texture;
+}
+
// Glorified typedef to avoid including GrDrawState.h in GrContext.h
class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {};
@@ -262,7 +283,7 @@ GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget,
GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc,
const GrCacheID& cacheID,
const GrTextureParams* params) {
- GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, cacheID);
+ GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, cacheID);
GrGpuResource* resource = fResourceCache->find(resourceKey);
SkSafeRef(resource);
return static_cast<GrTexture*>(resource);
@@ -271,7 +292,7 @@ GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc,
bool GrContext::isTextureInCache(const GrTextureDesc& desc,
const GrCacheID& cacheID,
const GrTextureParams* params) const {
- GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, cacheID);
+ GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, cacheID);
return fResourceCache->hasKey(resourceKey);
}
@@ -410,16 +431,16 @@ GrTexture* GrContext::createTexture(const GrTextureParams* params,
const void* srcData,
size_t rowBytes,
GrResourceKey* cacheKey) {
- GrResourceKey resourceKey = GrTextureImpl::ComputeKey(fGpu, params, desc, cacheID);
+ GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, cacheID);
GrTexture* texture;
- if (GrTextureImpl::NeedsResizing(resourceKey)) {
+ if (GrTexturePriv::NeedsResizing(resourceKey)) {
// We do not know how to resize compressed textures.
SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
texture = this->createResizedTexture(desc, cacheID,
srcData, rowBytes,
- GrTextureImpl::NeedsBilerp(resourceKey));
+ GrTexturePriv::NeedsBilerp(resourceKey));
} else {
texture = fGpu->createTexture(desc, srcData, rowBytes);
}
@@ -443,7 +464,7 @@ static GrTexture* create_scratch_texture(GrGpu* gpu,
const GrTextureDesc& desc) {
GrTexture* texture = gpu->createTexture(desc, NULL, 0);
if (texture) {
- GrResourceKey key = GrTextureImpl::ComputeScratchKey(texture->desc());
+ GrResourceKey key = GrTexturePriv::ComputeScratchKey(texture->desc());
// Adding a resource could put us overbudget. Try to free up the
// necessary space before adding it.
resourceCache->purgeAsNeeded(1, texture->gpuMemorySize());
@@ -483,7 +504,7 @@ GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, Scra
int origHeight = desc.fHeight;
do {
- GrResourceKey key = GrTextureImpl::ComputeScratchKey(desc);
+ GrResourceKey key = GrTexturePriv::ComputeScratchKey(desc);
// Ensure we have exclusive access to the texture so future 'find' calls don't return it
resource = fResourceCache->find(key, GrResourceCache::kHide_OwnershipFlag);
if (resource) {
@@ -578,7 +599,7 @@ void GrContext::unlockScratchTexture(GrTexture* texture) {
// Instead, give up the cache's ref and leave the decision up to
// addExistingTextureToCache once its ref count reaches 0. For
// this to work we need to leave it in the exclusive list.
- texture->impl()->setFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit);
+ texture->texturePriv().setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit);
// Give up the cache's ref to the texture
texture->unref();
}
@@ -1347,7 +1368,7 @@ bool GrContext::writeTexturePixels(GrTexture* texture,
}
}
- if (!(kDontFlush_PixelOpsFlag & flags) && texture->hasPendingIO()) {
+ if (!(kDontFlush_PixelOpsFlag & flags) && texture->surfacePriv().hasPendingIO()) {
this->flush();
}
@@ -1418,7 +1439,7 @@ bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
}
}
- if (!(kDontFlush_PixelOpsFlag & flags) && target->hasPendingWrite()) {
+ if (!(kDontFlush_PixelOpsFlag & flags) && target->surfacePriv().hasPendingWrite()) {
this->flush();
}