blob: e43c910fd0ca8fc132c450a4d5fb1989696e2197 [file] [log] [blame]
bsalomon@google.comaa5b6732011-07-29 15:13:20 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9#include "GrRenderTarget.h"
10
11#include "GrContext.h"
robertphillips4fd74ae2016-08-03 14:26:53 -070012#include "GrContextPriv.h"
Brian Osman11052242016-10-27 14:47:55 -040013#include "GrRenderTargetContext.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000014#include "GrGpu.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040015#include "GrRenderTargetOpList.h"
bsalomon6bc1b5f2015-02-23 09:06:38 -080016#include "GrRenderTargetPriv.h"
egdaniel8dc7c3a2015-04-16 11:22:42 -070017#include "GrStencilAttachment.h"
csmartdaltonc633abb2016-11-01 08:55:55 -070018#include "GrStencilSettings.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000019
Robert Phillipsc4f0a822017-06-13 08:11:36 -040020GrRenderTarget::GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc,
21 GrRenderTargetFlags flags,
csmartdaltonf9635992016-08-10 11:09:07 -070022 GrStencilAttachment* stencil)
Brian Salomond34edf32017-05-19 15:45:48 -040023 : INHERITED(gpu, desc)
24 , fSampleCnt(desc.fSampleCnt)
25 , fStencilAttachment(stencil)
26 , fMultisampleSpecsID(0)
27 , fFlags(flags) {
28 SkASSERT(desc.fFlags & kRenderTarget_GrSurfaceFlag);
Robert Phillipsc4f0a822017-06-13 08:11:36 -040029 SkASSERT(!(fFlags & GrRenderTargetFlags::kMixedSampled) || fSampleCnt > 0);
30 SkASSERT(!(fFlags & GrRenderTargetFlags::kWindowRectsSupport) ||
31 gpu->caps()->maxWindowRectangles() > 0);
csmartdaltonf9635992016-08-10 11:09:07 -070032 fResolveRect.setLargestInverted();
33}
34
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000035void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000036 if (kCanResolve_ResolveType == getResolveType()) {
bsalomon49f085d2014-09-05 13:34:00 -070037 if (rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000038 fResolveRect.join(*rect);
39 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
40 fResolveRect.setEmpty();
41 }
42 } else {
43 fResolveRect.setLTRB(0, 0, this->width(), this->height());
44 }
45 }
46}
47
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000048void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000049 fResolveRect = rect;
50 if (fResolveRect.isEmpty()) {
51 fResolveRect.setLargestInverted();
52 } else {
53 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
54 fResolveRect.setLargestInverted();
55 }
56 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000057}
58
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000059void GrRenderTarget::onRelease() {
egdanielec00d942015-09-14 12:56:10 -070060 SkSafeSetNull(fStencilAttachment);
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);
robertphillips498d7ac2015-10-30 10:11:30 -070067
robertphillips@google.comd3645542012-09-05 18:37:39 +000068 INHERITED::onAbandon();
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000069}
bsalomon6bc1b5f2015-02-23 09:06:38 -080070
71///////////////////////////////////////////////////////////////////////////////
72
egdanielec00d942015-09-14 12:56:10 -070073bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) {
egdaniel79bd2ae2015-09-15 08:46:13 -070074 if (!stencil && !fRenderTarget->fStencilAttachment) {
75 // No need to do any work since we currently don't have a stencil attachment and
Robert Phillips29e52f12016-11-03 10:19:14 -040076 // we're not actually adding one.
egdaniel79bd2ae2015-09-15 08:46:13 -070077 return true;
78 }
egdanielec00d942015-09-14 12:56:10 -070079 fRenderTarget->fStencilAttachment = stencil;
80 if (!fRenderTarget->completeStencilAttachment()) {
81 SkSafeSetNull(fRenderTarget->fStencilAttachment);
82 return false;
halcanary9d524f22016-03-29 09:03:52 -070083 }
egdanielec00d942015-09-14 12:56:10 -070084 return true;
bsalomon6bc1b5f2015-02-23 09:06:38 -080085}
cdalton28f45b92016-03-07 13:58:26 -080086
cdalton193d9cf2016-05-12 11:52:02 -070087int GrRenderTargetPriv::numStencilBits() const {
csmartdaltonc633abb2016-11-01 08:55:55 -070088 SkASSERT(this->getStencilAttachment());
89 return this->getStencilAttachment()->bits();
cdalton193d9cf2016-05-12 11:52:02 -070090}
91
cdalton28f45b92016-03-07 13:58:26 -080092const GrGpu::MultisampleSpecs&
csmartdaltonc633abb2016-11-01 08:55:55 -070093GrRenderTargetPriv::getMultisampleSpecs(const GrPipeline& pipeline) const {
Robert Phillips2890fbf2017-07-26 15:48:41 -040094 SkASSERT(fRenderTarget == pipeline.renderTarget()); // TODO: remove RT from pipeline.
csmartdaltonc25c5d72016-11-01 07:03:59 -070095 GrGpu* gpu = fRenderTarget->getGpu();
96 if (auto id = fRenderTarget->fMultisampleSpecsID) {
csmartdaltonc633abb2016-11-01 08:55:55 -070097 SkASSERT(gpu->queryMultisampleSpecs(pipeline).fUniqueID == id);
csmartdaltonc25c5d72016-11-01 07:03:59 -070098 return gpu->getMultisampleSpecs(id);
99 }
csmartdaltonc633abb2016-11-01 08:55:55 -0700100 const GrGpu::MultisampleSpecs& specs = gpu->queryMultisampleSpecs(pipeline);
csmartdaltonc25c5d72016-11-01 07:03:59 -0700101 fRenderTarget->fMultisampleSpecsID = specs.fUniqueID;
102 return specs;
cdalton28f45b92016-03-07 13:58:26 -0800103}
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700104