blob: 8a73a84f6791a81e6337182ebfb79f970bbcb064 [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.com0168afc2011-08-08 13:21:05 +000034 return fAllocatedWidth * fAllocatedHeight * colorBits * GrMax(1,fSampleCnt);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000035}
36
37void 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
50void 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.com81c3f8d2011-08-03 15:18:33 +000059}
60
61void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) {
62 GrSafeAssign(fStencilBuffer, stencilBuffer);
bsalomon@google.com4043ae22011-08-02 14:19:11 +000063}