blob: 7a53c0b301d7fc518ab6cd8c53a9393c02fcd9d3 [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.com99621082011-11-15 16:47:16 +000034 uint64_t size = fWidth;
35 size *= fHeight;
bsalomon@google.comf6ff4952011-08-09 13:32:14 +000036 size *= colorBits;
37 size *= GrMax(1,fSampleCnt);
38 return (size_t)(size / 8);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000039}
40
41void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) {
42 if (kCanResolve_ResolveType == getResolveType()) {
43 if (NULL != rect) {
44 fResolveRect.join(*rect);
45 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
46 fResolveRect.setEmpty();
47 }
48 } else {
49 fResolveRect.setLTRB(0, 0, this->width(), this->height());
50 }
51 }
52}
53
54void GrRenderTarget::overrideResolveRect(const GrIRect rect) {
55 fResolveRect = rect;
56 if (fResolveRect.isEmpty()) {
57 fResolveRect.setLargestInverted();
58 } else {
59 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
60 fResolveRect.setLargestInverted();
61 }
62 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000063}
64
65void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) {
bsalomon@google.com558a75b2011-08-08 17:01:14 +000066 if (NULL != fStencilBuffer) {
67 fStencilBuffer->wasDetachedFromRenderTarget(this);
68 fStencilBuffer->unref();
69 }
70 fStencilBuffer = stencilBuffer;
71 if (NULL != fStencilBuffer) {
72 fStencilBuffer->wasAttachedToRenderTarget(this);
73 fStencilBuffer->ref();
74 }
bsalomon@google.comf6ff4952011-08-09 13:32:14 +000075}