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 "GrRenderTargetPriv.h"
15 #include "GrStencilAttachment.h"
16
discard()17 void GrRenderTarget::discard() {
18 // go through context so that all necessary flushing occurs
19 GrContext* context = this->getContext();
20 if (NULL == context) {
21 return;
22 }
23 context->discardRenderTarget(this);
24 }
25
flagAsNeedingResolve(const SkIRect * rect)26 void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
27 if (kCanResolve_ResolveType == getResolveType()) {
28 if (rect) {
29 fResolveRect.join(*rect);
30 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
31 fResolveRect.setEmpty();
32 }
33 } else {
34 fResolveRect.setLTRB(0, 0, this->width(), this->height());
35 }
36 }
37 }
38
overrideResolveRect(const SkIRect rect)39 void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
40 fResolveRect = rect;
41 if (fResolveRect.isEmpty()) {
42 fResolveRect.setLargestInverted();
43 } else {
44 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
45 fResolveRect.setLargestInverted();
46 }
47 }
48 }
49
onRelease()50 void GrRenderTarget::onRelease() {
51 this->renderTargetPriv().didAttachStencilAttachment(NULL);
52
53 INHERITED::onRelease();
54 }
55
onAbandon()56 void GrRenderTarget::onAbandon() {
57 this->renderTargetPriv().didAttachStencilAttachment(NULL);
58
59 INHERITED::onAbandon();
60 }
61
62 ///////////////////////////////////////////////////////////////////////////////
63
didAttachStencilAttachment(GrStencilAttachment * stencilAttachment)64 void GrRenderTargetPriv::didAttachStencilAttachment(GrStencilAttachment* stencilAttachment) {
65 SkRefCnt_SafeAssign(fRenderTarget->fStencilAttachment, stencilAttachment);
66 }
67
attachStencilAttachment() const68 GrStencilAttachment* GrRenderTargetPriv::attachStencilAttachment() const {
69 if (fRenderTarget->fStencilAttachment) {
70 return fRenderTarget->fStencilAttachment;
71 }
72 if (!fRenderTarget->wasDestroyed() && fRenderTarget->canAttemptStencilAttachment()) {
73 fRenderTarget->getGpu()->attachStencilAttachmentToRenderTarget(fRenderTarget);
74 }
75 return fRenderTarget->fStencilAttachment;
76 }
77