blob: de3bce91148e41b19626a7f732e8ea406aa25ef1 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
bsalomon@google.com669fdc42011-04-05 17:08:27 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.
bsalomon@google.com669fdc42011-04-05 17:08:27 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
bsalomon@google.com669fdc42011-04-05 17:08:27 +000010#include "GrTexture.h"
11#include "GrContext.h"
bsalomon@google.com05ef5102011-05-02 21:14:59 +000012#include "GrGpu.h"
bsalomon@google.com669fdc42011-04-05 17:08:27 +000013
14bool GrRenderTarget::readPixels(int left, int top, int width, int height,
15 GrPixelConfig config, void* buffer) {
16 // go through context so that all necessary flushing occurs
17 GrContext* context = this->getGpu()->getContext();
18 GrAssert(NULL != context);
19 return context->readRenderTargetPixels(this,
20 left, top,
21 width, height,
22 config, buffer);
23}
24
bsalomon@google.comcee661a2011-07-26 12:32:36 +000025size_t GrRenderTarget::sizeInBytes() const {
26 int colorBits;
27 if (kUnknown_GrPixelConfig == fConfig) {
28 colorBits = 32; // don't know, make a guess
29 } else {
30 colorBits = GrBytesPerPixel(fConfig);
31 }
32 return fWidth * fHeight * (fStencilBits + colorBits);
33}
34
bsalomon@google.com8295dc12011-05-02 12:53:34 +000035void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) {
36 if (kCanResolve_ResolveType == getResolveType()) {
37 if (NULL != rect) {
reed@google.com20efde72011-05-09 17:00:02 +000038 fResolveRect.join(*rect);
39 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
40 fResolveRect.setEmpty();
41 }
bsalomon@google.com8295dc12011-05-02 12:53:34 +000042 } else {
43 fResolveRect.setLTRB(0, 0, this->width(), this->height());
44 }
45 }
46}
47
48void GrRenderTarget::overrideResolveRect(const GrIRect rect) {
49 fResolveRect = rect;
50 if (fResolveRect.isEmpty()) {
51 fResolveRect.setLargestInverted();
52 } else {
reed@google.com20efde72011-05-09 17:00:02 +000053 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
bsalomon@google.com8295dc12011-05-02 12:53:34 +000054 fResolveRect.setLargestInverted();
55 }
56 }
57}
58
bsalomon@google.com669fdc42011-04-05 17:08:27 +000059bool GrTexture::readPixels(int left, int top, int width, int height,
60 GrPixelConfig config, void* buffer) {
61 // go through context so that all necessary flushing occurs
62 GrContext* context = this->getGpu()->getContext();
63 GrAssert(NULL != context);
64 return context->readTexturePixels(this,
65 left, top,
66 width, height,
67 config, buffer);
68}
bsalomon@google.comcee661a2011-07-26 12:32:36 +000069