blob: 360bcf65e57e08905b4a28c2fc410ae06813c39b [file] [log] [blame]
bsalomon@google.com669fdc42011-04-05 17:08:27 +00001/*
2 Copyright 2011 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17#include "GrTexture.h"
18#include "GrContext.h"
bsalomon@google.com05ef5102011-05-02 21:14:59 +000019#include "GrGpu.h"
bsalomon@google.com669fdc42011-04-05 17:08:27 +000020
21bool GrRenderTarget::readPixels(int left, int top, int width, int height,
22 GrPixelConfig config, void* buffer) {
23 // go through context so that all necessary flushing occurs
24 GrContext* context = this->getGpu()->getContext();
25 GrAssert(NULL != context);
26 return context->readRenderTargetPixels(this,
27 left, top,
28 width, height,
29 config, buffer);
30}
31
bsalomon@google.comcee661a2011-07-26 12:32:36 +000032size_t GrRenderTarget::sizeInBytes() const {
33 int colorBits;
34 if (kUnknown_GrPixelConfig == fConfig) {
35 colorBits = 32; // don't know, make a guess
36 } else {
37 colorBits = GrBytesPerPixel(fConfig);
38 }
39 return fWidth * fHeight * (fStencilBits + colorBits);
40}
41
bsalomon@google.com8295dc12011-05-02 12:53:34 +000042void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) {
43 if (kCanResolve_ResolveType == getResolveType()) {
44 if (NULL != rect) {
reed@google.com20efde72011-05-09 17:00:02 +000045 fResolveRect.join(*rect);
46 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
47 fResolveRect.setEmpty();
48 }
bsalomon@google.com8295dc12011-05-02 12:53:34 +000049 } else {
50 fResolveRect.setLTRB(0, 0, this->width(), this->height());
51 }
52 }
53}
54
55void GrRenderTarget::overrideResolveRect(const GrIRect rect) {
56 fResolveRect = rect;
57 if (fResolveRect.isEmpty()) {
58 fResolveRect.setLargestInverted();
59 } else {
reed@google.com20efde72011-05-09 17:00:02 +000060 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
bsalomon@google.com8295dc12011-05-02 12:53:34 +000061 fResolveRect.setLargestInverted();
62 }
63 }
64}
65
bsalomon@google.com669fdc42011-04-05 17:08:27 +000066bool GrTexture::readPixels(int left, int top, int width, int height,
67 GrPixelConfig config, void* buffer) {
68 // go through context so that all necessary flushing occurs
69 GrContext* context = this->getGpu()->getContext();
70 GrAssert(NULL != context);
71 return context->readTexturePixels(this,
72 left, top,
73 width, height,
74 config, buffer);
75}
bsalomon@google.comcee661a2011-07-26 12:32:36 +000076