bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 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. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #include "GrRenderTarget.h" |
| 11 | |
| 12 | #include "GrContext.h" |
| 13 | #include "GrGpu.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 14 | #include "GrStencilBuffer.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 15 | |
| 16 | bool GrRenderTarget::readPixels(int left, int top, int width, int height, |
| 17 | GrPixelConfig config, void* buffer) { |
| 18 | // go through context so that all necessary flushing occurs |
| 19 | GrContext* context = this->getGpu()->getContext(); |
| 20 | GrAssert(NULL != context); |
| 21 | return context->readRenderTargetPixels(this, |
| 22 | left, top, |
| 23 | width, height, |
| 24 | config, buffer); |
| 25 | } |
| 26 | |
| 27 | size_t GrRenderTarget::sizeInBytes() const { |
| 28 | int colorBits; |
| 29 | if (kUnknown_GrPixelConfig == fConfig) { |
| 30 | colorBits = 32; // don't know, make a guess |
| 31 | } else { |
| 32 | colorBits = GrBytesPerPixel(fConfig); |
| 33 | } |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 34 | return fAllocatedWidth * fAllocatedHeight * colorBits * GrMax(1,fSampleCnt); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) { |
| 38 | if (kCanResolve_ResolveType == getResolveType()) { |
| 39 | if (NULL != rect) { |
| 40 | fResolveRect.join(*rect); |
| 41 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 42 | fResolveRect.setEmpty(); |
| 43 | } |
| 44 | } else { |
| 45 | fResolveRect.setLTRB(0, 0, this->width(), this->height()); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void GrRenderTarget::overrideResolveRect(const GrIRect rect) { |
| 51 | fResolveRect = rect; |
| 52 | if (fResolveRect.isEmpty()) { |
| 53 | fResolveRect.setLargestInverted(); |
| 54 | } else { |
| 55 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 56 | fResolveRect.setLargestInverted(); |
| 57 | } |
| 58 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) { |
| 62 | GrSafeAssign(fStencilBuffer, stencilBuffer); |
bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 63 | } |