bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 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" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 14 | #include "GrStencilBuffer.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 15 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 16 | void GrRenderTarget::discard() { |
| 17 | // go through context so that all necessary flushing occurs |
| 18 | GrContext* context = this->getContext(); |
| 19 | if (NULL == context) { |
| 20 | return; |
| 21 | } |
| 22 | context->discardRenderTarget(this); |
| 23 | } |
| 24 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 25 | void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 26 | if (kCanResolve_ResolveType == getResolveType()) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 27 | if (rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 28 | fResolveRect.join(*rect); |
| 29 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 30 | fResolveRect.setEmpty(); |
| 31 | } |
| 32 | } else { |
| 33 | fResolveRect.setLTRB(0, 0, this->width(), this->height()); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 38 | void GrRenderTarget::overrideResolveRect(const SkIRect rect) { |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 39 | fResolveRect = rect; |
| 40 | if (fResolveRect.isEmpty()) { |
| 41 | fResolveRect.setLargestInverted(); |
| 42 | } else { |
| 43 | if (!fResolveRect.intersect(0, 0, this->width(), this->height())) { |
| 44 | fResolveRect.setLargestInverted(); |
| 45 | } |
| 46 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void GrRenderTarget::setStencilBuffer(GrStencilBuffer* stencilBuffer) { |
bsalomon@google.com | 76202b8 | 2013-05-10 19:08:22 +0000 | [diff] [blame] | 50 | SkRefCnt_SafeAssign(fStencilBuffer, stencilBuffer); |
bsalomon@google.com | f6ff495 | 2011-08-09 13:32:14 +0000 | [diff] [blame] | 51 | } |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 52 | |
| 53 | void GrRenderTarget::onRelease() { |
| 54 | this->setStencilBuffer(NULL); |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 55 | |
| 56 | INHERITED::onRelease(); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void GrRenderTarget::onAbandon() { |
| 60 | this->setStencilBuffer(NULL); |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 61 | |
| 62 | INHERITED::onAbandon(); |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 63 | } |