epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 10 | #include "GrTexture.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 11 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 12 | #include "GrContext.h" |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 13 | #include "GrGpu.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 14 | #include "GrRenderTarget.h" |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 15 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 16 | bool GrTexture::readPixels(int left, int top, int width, int height, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame^] | 17 | GrPixelConfig config, void* buffer, |
| 18 | size_t rowBytes) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 19 | // go through context so that all necessary flushing occurs |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame^] | 20 | GrContext* context = this->getContext(); |
| 21 | if (NULL == context) { |
| 22 | return false; |
| 23 | } |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 24 | return context->readTexturePixels(this, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame^] | 25 | left, top, |
| 26 | width, height, |
| 27 | config, buffer, rowBytes); |
| 28 | } |
| 29 | |
| 30 | void GrTexture::writePixels(int left, int top, int width, int height, |
| 31 | GrPixelConfig config, const void* buffer, |
| 32 | size_t rowBytes) { |
| 33 | // go through context so that all necessary flushing occurs |
| 34 | GrContext* context = this->getContext(); |
| 35 | if (NULL == context) { |
| 36 | return; |
| 37 | } |
| 38 | context->writeTexturePixels(this, |
| 39 | left, top, |
| 40 | width, height, |
| 41 | config, buffer, rowBytes); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 42 | } |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 43 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 44 | void GrTexture::releaseRenderTarget() { |
| 45 | if (NULL != fRenderTarget) { |
| 46 | GrAssert(fRenderTarget->asTexture() == this); |
| 47 | fRenderTarget->onTextureReleaseRenderTarget(); |
| 48 | fRenderTarget->unref(); |
| 49 | fRenderTarget = NULL; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | void GrTexture::onAbandon() { |
| 54 | if (NULL != fRenderTarget) { |
| 55 | fRenderTarget->abandon(); |
| 56 | } |
| 57 | } |
| 58 | |