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