blob: e81a9cfd8382700485dc6f98463d9301b81e6e79 [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00001
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"
robertphillipsea461502015-05-26 11:38:03 -070013#include "GrDrawContext.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000014#include "GrGpu.h"
bsalomon6bc1b5f2015-02-23 09:06:38 -080015#include "GrRenderTargetPriv.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070016#include "GrStencilAttachment.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000017
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000018void GrRenderTarget::discard() {
19 // go through context so that all necessary flushing occurs
20 GrContext* context = this->getContext();
robertphillipsc9a37062015-09-01 08:34:28 -070021 if (!context) {
22 return;
23 }
24
robertphillips2e1e51f2015-10-15 08:01:48 -070025 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(this));
robertphillipsea461502015-05-26 11:38:03 -070026 if (!drawContext) {
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000027 return;
28 }
robertphillipsea461502015-05-26 11:38:03 -070029
robertphillips2e1e51f2015-10-15 08:01:48 -070030 drawContext->discard();
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000031}
32
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000033void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000034 if (kCanResolve_ResolveType == getResolveType()) {
bsalomon49f085d2014-09-05 13:34:00 -070035 if (rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000036 fResolveRect.join(*rect);
37 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
38 fResolveRect.setEmpty();
39 }
40 } else {
41 fResolveRect.setLTRB(0, 0, this->width(), this->height());
42 }
43 }
44}
45
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000046void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000047 fResolveRect = rect;
48 if (fResolveRect.isEmpty()) {
49 fResolveRect.setLargestInverted();
50 } else {
51 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
52 fResolveRect.setLargestInverted();
53 }
54 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000055}
56
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000057void GrRenderTarget::onRelease() {
egdanielec00d942015-09-14 12:56:10 -070058 SkSafeSetNull(fStencilAttachment);
robertphillips@google.comd3645542012-09-05 18:37:39 +000059
60 INHERITED::onRelease();
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000061}
62
63void GrRenderTarget::onAbandon() {
egdanielec00d942015-09-14 12:56:10 -070064 SkSafeSetNull(fStencilAttachment);
robertphillips@google.comd3645542012-09-05 18:37:39 +000065
66 INHERITED::onAbandon();
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000067}
bsalomon6bc1b5f2015-02-23 09:06:38 -080068
69///////////////////////////////////////////////////////////////////////////////
70
egdanielec00d942015-09-14 12:56:10 -070071bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) {
egdaniel79bd2ae2015-09-15 08:46:13 -070072 if (!stencil && !fRenderTarget->fStencilAttachment) {
73 // No need to do any work since we currently don't have a stencil attachment and
74 // we're not acctually adding one.
75 return true;
76 }
egdanielec00d942015-09-14 12:56:10 -070077 fRenderTarget->fStencilAttachment = stencil;
78 if (!fRenderTarget->completeStencilAttachment()) {
79 SkSafeSetNull(fRenderTarget->fStencilAttachment);
80 return false;
81 }
82 return true;
bsalomon6bc1b5f2015-02-23 09:06:38 -080083}