blob: ad56cf761fff6e62afc5380d2532d9c82af48708 [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"
robertphillipsa106c622015-10-16 09:07:06 -070014#include "GrDrawTarget.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000015#include "GrGpu.h"
bsalomon6bc1b5f2015-02-23 09:06:38 -080016#include "GrRenderTargetPriv.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070017#include "GrStencilAttachment.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000018
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000019void GrRenderTarget::discard() {
20 // go through context so that all necessary flushing occurs
21 GrContext* context = this->getContext();
robertphillipsc9a37062015-09-01 08:34:28 -070022 if (!context) {
23 return;
24 }
25
robertphillips2e1e51f2015-10-15 08:01:48 -070026 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(this));
robertphillipsea461502015-05-26 11:38:03 -070027 if (!drawContext) {
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000028 return;
29 }
robertphillipsea461502015-05-26 11:38:03 -070030
robertphillips2e1e51f2015-10-15 08:01:48 -070031 drawContext->discard();
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000032}
33
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000034void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000035 if (kCanResolve_ResolveType == getResolveType()) {
bsalomon49f085d2014-09-05 13:34:00 -070036 if (rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000037 fResolveRect.join(*rect);
38 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
39 fResolveRect.setEmpty();
40 }
41 } else {
42 fResolveRect.setLTRB(0, 0, this->width(), this->height());
43 }
44 }
45}
46
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000047void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000048 fResolveRect = rect;
49 if (fResolveRect.isEmpty()) {
50 fResolveRect.setLargestInverted();
51 } else {
52 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
53 fResolveRect.setLargestInverted();
54 }
55 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000056}
57
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000058void GrRenderTarget::onRelease() {
egdanielec00d942015-09-14 12:56:10 -070059 SkSafeSetNull(fStencilAttachment);
robertphillipsa352b142015-10-22 05:31:32 -070060 fLastDrawTarget = nullptr;
robertphillips@google.comd3645542012-09-05 18:37:39 +000061
62 INHERITED::onRelease();
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000063}
64
65void GrRenderTarget::onAbandon() {
egdanielec00d942015-09-14 12:56:10 -070066 SkSafeSetNull(fStencilAttachment);
robertphillipsa352b142015-10-22 05:31:32 -070067 fLastDrawTarget = nullptr;
robertphillips@google.comd3645542012-09-05 18:37:39 +000068
69 INHERITED::onAbandon();
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000070}
bsalomon6bc1b5f2015-02-23 09:06:38 -080071
robertphillipsa106c622015-10-16 09:07:06 -070072void GrRenderTarget::setLastDrawTarget(GrDrawTarget* dt) {
73 if (fLastDrawTarget) {
74 SkASSERT(fLastDrawTarget->isClosed());
75 }
76
robertphillipsa352b142015-10-22 05:31:32 -070077 fLastDrawTarget = dt;
robertphillipsa106c622015-10-16 09:07:06 -070078}
79
bsalomon6bc1b5f2015-02-23 09:06:38 -080080///////////////////////////////////////////////////////////////////////////////
81
egdanielec00d942015-09-14 12:56:10 -070082bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) {
egdaniel79bd2ae2015-09-15 08:46:13 -070083 if (!stencil && !fRenderTarget->fStencilAttachment) {
84 // No need to do any work since we currently don't have a stencil attachment and
85 // we're not acctually adding one.
86 return true;
87 }
egdanielec00d942015-09-14 12:56:10 -070088 fRenderTarget->fStencilAttachment = stencil;
89 if (!fRenderTarget->completeStencilAttachment()) {
90 SkSafeSetNull(fRenderTarget->fStencilAttachment);
91 return false;
92 }
93 return true;
bsalomon6bc1b5f2015-02-23 09:06:38 -080094}