blob: 186fe8e55285a9381c608a0bd7fd705cca80cee0 [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"
14
15bool 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
26size_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.com4043ae22011-08-02 14:19:11 +000033 return fWidth * fHeight * (fStencilBits + colorBits);
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000034}
35
36void 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
49void 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.com4043ae22011-08-02 14:19:11 +000058}