| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "GrRenderTarget.h" | 10 #include "GrRenderTarget.h" |
| 11 | 11 |
| 12 #include "GrContext.h" | 12 #include "GrContext.h" |
| 13 #include "GrDrawContext.h" | 13 #include "GrDrawContext.h" |
| 14 #include "GrDrawTarget.h" | 14 #include "GrDrawTarget.h" |
| 15 #include "GrGpu.h" | 15 #include "GrGpu.h" |
| 16 #include "GrRenderTargetPriv.h" | 16 #include "GrRenderTargetPriv.h" |
| 17 #include "GrStencilAttachment.h" | 17 #include "GrStencilAttachment.h" |
| 18 | 18 |
| 19 GrRenderTarget::~GrRenderTarget() { |
| 20 if (fLastDrawTarget) { |
| 21 fLastDrawTarget->clearRT(); |
| 22 } |
| 23 SkSafeUnref(fLastDrawTarget); |
| 24 } |
| 25 |
| 19 void GrRenderTarget::discard() { | 26 void GrRenderTarget::discard() { |
| 20 // go through context so that all necessary flushing occurs | 27 // go through context so that all necessary flushing occurs |
| 21 GrContext* context = this->getContext(); | 28 GrContext* context = this->getContext(); |
| 22 if (!context) { | 29 if (!context) { |
| 23 return; | 30 return; |
| 24 } | 31 } |
| 25 | 32 |
| 26 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(this)); | 33 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(this)); |
| 27 if (!drawContext) { | 34 if (!drawContext) { |
| 28 return; | 35 return; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 50 fResolveRect.setLargestInverted(); | 57 fResolveRect.setLargestInverted(); |
| 51 } else { | 58 } else { |
| 52 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { | 59 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 53 fResolveRect.setLargestInverted(); | 60 fResolveRect.setLargestInverted(); |
| 54 } | 61 } |
| 55 } | 62 } |
| 56 } | 63 } |
| 57 | 64 |
| 58 void GrRenderTarget::onRelease() { | 65 void GrRenderTarget::onRelease() { |
| 59 SkSafeSetNull(fStencilAttachment); | 66 SkSafeSetNull(fStencilAttachment); |
| 60 fLastDrawTarget = nullptr; | |
| 61 | 67 |
| 62 INHERITED::onRelease(); | 68 INHERITED::onRelease(); |
| 63 } | 69 } |
| 64 | 70 |
| 65 void GrRenderTarget::onAbandon() { | 71 void GrRenderTarget::onAbandon() { |
| 66 SkSafeSetNull(fStencilAttachment); | 72 SkSafeSetNull(fStencilAttachment); |
| 67 fLastDrawTarget = nullptr; | 73 |
| 74 // The contents of this renderTarget are gone/invalid. It isn't useful to po
int back |
| 75 // the creating drawTarget. |
| 76 this->setLastDrawTarget(nullptr); |
| 68 | 77 |
| 69 INHERITED::onAbandon(); | 78 INHERITED::onAbandon(); |
| 70 } | 79 } |
| 71 | 80 |
| 72 void GrRenderTarget::setLastDrawTarget(GrDrawTarget* dt) { | 81 void GrRenderTarget::setLastDrawTarget(GrDrawTarget* dt) { |
| 73 if (fLastDrawTarget) { | 82 if (fLastDrawTarget) { |
| 83 // The non-MDB world never closes so we can't check this condition |
| 84 #ifdef ENABLE_MDB |
| 74 SkASSERT(fLastDrawTarget->isClosed()); | 85 SkASSERT(fLastDrawTarget->isClosed()); |
| 86 #endif |
| 87 fLastDrawTarget->clearRT(); |
| 75 } | 88 } |
| 76 | 89 |
| 77 fLastDrawTarget = dt; | 90 SkRefCnt_SafeAssign(fLastDrawTarget, dt); |
| 78 } | 91 } |
| 79 | 92 |
| 80 /////////////////////////////////////////////////////////////////////////////// | 93 /////////////////////////////////////////////////////////////////////////////// |
| 81 | 94 |
| 82 bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) { | 95 bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) { |
| 83 if (!stencil && !fRenderTarget->fStencilAttachment) { | 96 if (!stencil && !fRenderTarget->fStencilAttachment) { |
| 84 // No need to do any work since we currently don't have a stencil attach
ment and | 97 // No need to do any work since we currently don't have a stencil attach
ment and |
| 85 // we're not acctually adding one. | 98 // we're not acctually adding one. |
| 86 return true; | 99 return true; |
| 87 } | 100 } |
| 88 fRenderTarget->fStencilAttachment = stencil; | 101 fRenderTarget->fStencilAttachment = stencil; |
| 89 if (!fRenderTarget->completeStencilAttachment()) { | 102 if (!fRenderTarget->completeStencilAttachment()) { |
| 90 SkSafeSetNull(fRenderTarget->fStencilAttachment); | 103 SkSafeSetNull(fRenderTarget->fStencilAttachment); |
| 91 return false; | 104 return false; |
| 92 } | 105 } |
| 93 return true; | 106 return true; |
| 94 } | 107 } |
| OLD | NEW |