diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-05 17:08:27 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-05 17:08:27 +0000 |
commit | 669fdc4ed8ed461a141cb97d0afdd9ef72a82be1 (patch) | |
tree | 8c39d9d769e212749ce8e970129460f575a76f96 /gpu/src/GrContext.cpp | |
parent | 62ab7addb06bbc5b93460eaf2f70a9f8399308d3 (diff) |
Adds read pixels to GrTexture and GrRenderTarget
Adds SkGrRenderTargetPixelRef for SkBitmaps that are backed by RTs that aren't textures.
Adds onReadPixels implementations for SkGr pixel ref types
git-svn-id: http://skia.googlecode.com/svn/trunk@1056 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/src/GrContext.cpp')
-rw-r--r-- | gpu/src/GrContext.cpp | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/gpu/src/GrContext.cpp b/gpu/src/GrContext.cpp index d093d7c4c1..a0f5c51f9b 100644 --- a/gpu/src/GrContext.cpp +++ b/gpu/src/GrContext.cpp @@ -206,7 +206,7 @@ GrTextureEntry* GrContext::createAndLockTexture(GrTextureKey* key, // no longer need to clamp at min RT size. rtDesc.fWidth = GrNextPow2(desc.fWidth); rtDesc.fHeight = GrNextPow2(desc.fHeight); - int bpp = GrTexture::BytesPerPixel(desc.fFormat); + int bpp = GrBytesPerPixel(desc.fFormat); GrAutoSMalloc<128*128*4> stretchedPixels(bpp * rtDesc.fWidth * rtDesc.fHeight); @@ -609,14 +609,39 @@ void GrContext::flushDrawBuffer() { #endif } -bool GrContext::readPixels(int left, int top, int width, int height, - GrTexture::PixelConfig config, void* buffer) { - this->flush(true); - return fGpu->readPixels(left, top, width, height, config, buffer); +bool GrContext::readTexturePixels(GrTexture* texture, + int left, int top, int width, int height, + GrPixelConfig config, void* buffer) { + + // TODO: code read pixels for textures that aren't rendertargets + + this->flush(); + GrRenderTarget* target = texture->asRenderTarget(); + if (NULL != target) { + return fGpu->readPixels(target, + left, top, width, height, + config, buffer); + } else { + return false; + } +} + +bool GrContext::readRenderTargetPixels(GrRenderTarget* target, + int left, int top, int width, int height, + GrPixelConfig config, void* buffer) { + uint32_t flushFlags = 0; + if (NULL == target) { + flushFlags |= GrContext::kForceCurrentRenderTarget_FlushBit; + } + + this->flush(flushFlags); + return fGpu->readPixels(target, + left, top, width, height, + config, buffer); } void GrContext::writePixels(int left, int top, int width, int height, - GrTexture::PixelConfig config, const void* buffer, + GrPixelConfig config, const void* buffer, size_t stride) { // TODO: when underlying api has a direct way to do this we should use it @@ -764,6 +789,7 @@ GrContext::GrContext(GrGpu* gpu) : fGpu = gpu; fGpu->ref(); + fGpu->setContext(this); fCustomPathRenderer = GrPathRenderer::CreatePathRenderer(); fGpu->setClipPathRenderer(fCustomPathRenderer); |