1
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 #include "GrStencilBuffer.h"
15
readPixels(int left,int top,int width,int height,GrPixelConfig config,void * buffer,size_t rowBytes)16 bool GrRenderTarget::readPixels(int left, int top, int width, int height,
17 GrPixelConfig config, void* buffer,
18 size_t rowBytes) {
19 // go through context so that all necessary flushing occurs
20 GrContext* context = this->getContext();
21 if (NULL == context) {
22 return false;
23 }
24 return context->readRenderTargetPixels(this,
25 left, top,
26 width, height,
27 config, buffer, rowBytes);
28 }
29
writePixels(int left,int top,int width,int height,GrPixelConfig config,const void * buffer,size_t rowBytes)30 void GrRenderTarget::writePixels(int left, int top, int width, int height,
31 GrPixelConfig config, const void* buffer,
32 size_t rowBytes) {
33 // go through context so that all necessary flushing occurs
34 GrContext* context = this->getContext();
35 if (NULL == context) {
36 return;
37 }
38 context->writeRenderTargetPixels(this,
39 left, top,
40 width, height,
41 config, buffer, rowBytes);
42 }
43
resolve()44 void GrRenderTarget::resolve() {
45 // go through context so that all necessary flushing occurs
46 GrContext* context = this->getContext();
47 if (NULL == context) {
48 return;
49 }
50 context->resolveRenderTarget(this);
51 }
52
sizeInBytes() const53 size_t GrRenderTarget::sizeInBytes() const {
54 int colorBits;
55 if (kUnknown_GrPixelConfig == fConfig) {
56 colorBits = 32; // don't know, make a guess
57 } else {
58 colorBits = GrBytesPerPixel(fConfig);
59 }
60 uint64_t size = fWidth;
61 size *= fHeight;
62 size *= colorBits;
63 size *= GrMax(1,fSampleCnt);
64 return (size_t)(size / 8);
65 }
66
flagAsNeedingResolve(const GrIRect * rect)67 void GrRenderTarget::flagAsNeedingResolve(const GrIRect* rect) {
68 if (kCanResolve_ResolveType == getResolveType()) {
69 if (NULL != rect) {
70 fResolveRect.join(*rect);
71 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
72 fResolveRect.setEmpty();
73 }
74 } else {
75 fResolveRect.setLTRB(0, 0, this->width(), this->height());
76 }
77 }
78 }
79
overrideResolveRect(const GrIRect rect)80 void GrRenderTarget::overrideResolveRect(const GrIRect rect) {
81 fResolveRect = rect;
82 if (fResolveRect.isEmpty()) {
83 fResolveRect.setLargestInverted();
84 } else {
85 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
86 fResolveRect.setLargestInverted();
87 }
88 }
89 }
90
setStencilBuffer(GrStencilBuffer * stencilBuffer)91 void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) {
92 if (NULL != fStencilBuffer) {
93 fStencilBuffer->wasDetachedFromRenderTarget(this);
94 fStencilBuffer->unref();
95 }
96 fStencilBuffer = stencilBuffer;
97 if (NULL != fStencilBuffer) {
98 fStencilBuffer->wasAttachedToRenderTarget(this);
99 fStencilBuffer->ref();
100 }
101 }
102