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" |
| 11 | #include "GrContext.h" |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 12 | #include "GrGpu.h" |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 13 | |
| 14 | bool GrRenderTarget::readPixels(int left, int top, int width, int height, |
| 15 | GrPixelConfig config, void* buffer) { |
| 16 | // go through context so that all necessary flushing occurs |
| 17 | GrContext* context = this->getGpu()->getContext(); |
| 18 | GrAssert(NULL != context); |
| 19 | return context->readRenderTargetPixels(this, |
| 20 | left, top, |
| 21 | width, height, |
| 22 | config, buffer); |
| 23 | } |
| 24 | |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 25 | size_t GrRenderTarget::sizeInBytes() const { |
| 26 | int colorBits; |
| 27 | if (kUnknown_GrPixelConfig == fConfig) { |
| 28 | colorBits = 32; // don't know, make a guess |
| 29 | } else { |
| 30 | colorBits = GrBytesPerPixel(fConfig); |
| 31 | } |
| 32 | return fWidth * fHeight * (fStencilBits + colorBits); |
| 33 | } |
| 34 | |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 35 | void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) { |
| 36 | if (kCanResolve_ResolveType == getResolveType()) { |
| 37 | if (NULL != rect) { |
reed@google.com | 20efde7 | 2011-05-09 17:00:02 +0000 | [diff] [blame] | 38 | fResolveRect.join(*rect); |
| 39 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 40 | fResolveRect.setEmpty(); |
| 41 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 42 | } else { |
| 43 | fResolveRect.setLTRB(0, 0, this->width(), this->height()); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void GrRenderTarget::overrideResolveRect(const GrIRect rect) { |
| 49 | fResolveRect = rect; |
| 50 | if (fResolveRect.isEmpty()) { |
| 51 | fResolveRect.setLargestInverted(); |
| 52 | } else { |
reed@google.com | 20efde7 | 2011-05-09 17:00:02 +0000 | [diff] [blame] | 53 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 54 | fResolveRect.setLargestInverted(); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 59 | bool GrTexture::readPixels(int left, int top, int width, int height, |
| 60 | GrPixelConfig config, void* buffer) { |
| 61 | // go through context so that all necessary flushing occurs |
| 62 | GrContext* context = this->getGpu()->getContext(); |
| 63 | GrAssert(NULL != context); |
| 64 | return context->readTexturePixels(this, |
| 65 | left, top, |
| 66 | width, height, |
| 67 | config, buffer); |
| 68 | } |
bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 69 | |