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 | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame^] | 34 | return (size_t) fAllocatedWidth * |
| 35 | fAllocatedHeight * |
| 36 | colorBits * |
| 37 | GrMax(1,fSampleCnt); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) { |
| 41 | if (kCanResolve_ResolveType == getResolveType()) { |
| 42 | if (NULL != rect) { |
| 43 | fResolveRect.join(*rect); |
| 44 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 45 | fResolveRect.setEmpty(); |
| 46 | } |
| 47 | } else { |
| 48 | fResolveRect.setLTRB(0, 0, this->width(), this->height()); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | void GrRenderTarget::overrideResolveRect(const GrIRect rect) { |
| 54 | fResolveRect = rect; |
| 55 | if (fResolveRect.isEmpty()) { |
| 56 | fResolveRect.setLargestInverted(); |
| 57 | } else { |
| 58 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 59 | fResolveRect.setLargestInverted(); |
| 60 | } |
| 61 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame^] | 65 | if (NULL != fStencilBuffer) { |
| 66 | fStencilBuffer->wasDetachedFromRenderTarget(this); |
| 67 | fStencilBuffer->unref(); |
| 68 | } |
| 69 | fStencilBuffer = stencilBuffer; |
| 70 | if (NULL != fStencilBuffer) { |
| 71 | fStencilBuffer->wasAttachedToRenderTarget(this); |
| 72 | fStencilBuffer->ref(); |
| 73 | } |
bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 74 | } |