blob: 7b2681197d7cf4fe267992fce1f4e51c5a0dfa6d [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00001
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.com81c3f8d2011-08-03 15:18:33 +000014#include "GrStencilBuffer.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000015
16bool 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
27size_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.com558a75b2011-08-08 17:01:14 +000034 return (size_t) fAllocatedWidth *
35 fAllocatedHeight *
36 colorBits *
37 GrMax(1,fSampleCnt);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000038}
39
40void 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
53void 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.com81c3f8d2011-08-03 15:18:33 +000062}
63
64void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) {
bsalomon@google.com558a75b2011-08-08 17:01:14 +000065 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.com4043ae22011-08-02 14:19:11 +000074}