bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2011 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "GrTexture.h" |
| 18 | #include "GrContext.h" |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 19 | #include "GrGpu.h" |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 20 | |
| 21 | bool GrRenderTarget::readPixels(int left, int top, int width, int height, |
| 22 | GrPixelConfig config, void* buffer) { |
| 23 | // go through context so that all necessary flushing occurs |
| 24 | GrContext* context = this->getGpu()->getContext(); |
| 25 | GrAssert(NULL != context); |
| 26 | return context->readRenderTargetPixels(this, |
| 27 | left, top, |
| 28 | width, height, |
| 29 | config, buffer); |
| 30 | } |
| 31 | |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame^] | 32 | size_t GrRenderTarget::sizeInBytes() const { |
| 33 | int colorBits; |
| 34 | if (kUnknown_GrPixelConfig == fConfig) { |
| 35 | colorBits = 32; // don't know, make a guess |
| 36 | } else { |
| 37 | colorBits = GrBytesPerPixel(fConfig); |
| 38 | } |
| 39 | return fWidth * fHeight * (fStencilBits + colorBits); |
| 40 | } |
| 41 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 42 | void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) { |
| 43 | if (kCanResolve_ResolveType == getResolveType()) { |
| 44 | if (NULL != rect) { |
reed@google.com | 20efde7 | 2011-05-09 17:00:02 +0000 | [diff] [blame] | 45 | fResolveRect.join(*rect); |
| 46 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 47 | fResolveRect.setEmpty(); |
| 48 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 49 | } else { |
| 50 | fResolveRect.setLTRB(0, 0, this->width(), this->height()); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | void GrRenderTarget::overrideResolveRect(const GrIRect rect) { |
| 56 | fResolveRect = rect; |
| 57 | if (fResolveRect.isEmpty()) { |
| 58 | fResolveRect.setLargestInverted(); |
| 59 | } else { |
reed@google.com | 20efde7 | 2011-05-09 17:00:02 +0000 | [diff] [blame] | 60 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 61 | fResolveRect.setLargestInverted(); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 66 | bool GrTexture::readPixels(int left, int top, int width, int height, |
| 67 | GrPixelConfig config, void* buffer) { |
| 68 | // go through context so that all necessary flushing occurs |
| 69 | GrContext* context = this->getGpu()->getContext(); |
| 70 | GrAssert(NULL != context); |
| 71 | return context->readTexturePixels(this, |
| 72 | left, top, |
| 73 | width, height, |
| 74 | config, buffer); |
| 75 | } |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame^] | 76 | |