blob: 0bcde3bafe8e6c0d8a7ea64ede2194b98d0a1400 [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"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000018
csmartdaltonf9635992016-08-10 11:09:07 -070019GrRenderTarget::GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc, Flags flags,
20 GrStencilAttachment* stencil)
21 : INHERITED(gpu, desc)
22 , fStencilAttachment(stencil)
23 , fMultisampleSpecsID(0)
Robert Phillipsf2361d22016-10-25 14:20:06 -040024 , fFlags(flags) {
csmartdaltonf9635992016-08-10 11:09:07 -070025 SkASSERT(!(fFlags & Flags::kMixedSampled) || fDesc.fSampleCnt > 0);
26 SkASSERT(!(fFlags & Flags::kWindowRectsSupport) || gpu->caps()->maxWindowRectangles() > 0);
27 fResolveRect.setLargestInverted();
28}
29
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000030void GrRenderTarget::discard() {
31 // go through context so that all necessary flushing occurs
32 GrContext* context = this->getContext();
robertphillipsc9a37062015-09-01 08:34:28 -070033 if (!context) {
34 return;
35 }
36
Brian Osman11052242016-10-27 14:47:55 -040037 sk_sp<GrRenderTargetContext> renderTargetContext(
38 context->contextPriv().makeWrappedRenderTargetContext(sk_ref_sp(this), nullptr));
39 if (!renderTargetContext) {
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000040 return;
41 }
robertphillipsea461502015-05-26 11:38:03 -070042
Brian Osman11052242016-10-27 14:47:55 -040043 renderTargetContext->discard();
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +000044}
45
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000046void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000047 if (kCanResolve_ResolveType == getResolveType()) {
bsalomon49f085d2014-09-05 13:34:00 -070048 if (rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000049 fResolveRect.join(*rect);
50 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
51 fResolveRect.setEmpty();
52 }
53 } else {
54 fResolveRect.setLTRB(0, 0, this->width(), this->height());
55 }
56 }
57}
58
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000059void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000060 fResolveRect = rect;
61 if (fResolveRect.isEmpty()) {
62 fResolveRect.setLargestInverted();
63 } else {
64 if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
65 fResolveRect.setLargestInverted();
66 }
67 }
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000068}
69
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000070void GrRenderTarget::onRelease() {
egdanielec00d942015-09-14 12:56:10 -070071 SkSafeSetNull(fStencilAttachment);
robertphillips@google.comd3645542012-09-05 18:37:39 +000072
73 INHERITED::onRelease();
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000074}
75
76void GrRenderTarget::onAbandon() {
egdanielec00d942015-09-14 12:56:10 -070077 SkSafeSetNull(fStencilAttachment);
robertphillips498d7ac2015-10-30 10:11:30 -070078
79 // The contents of this renderTarget are gone/invalid. It isn't useful to point back
Robert Phillipsf2361d22016-10-25 14:20:06 -040080 // the creating opList.
81 this->setLastOpList(nullptr);
robertphillips@google.comd3645542012-09-05 18:37:39 +000082
83 INHERITED::onAbandon();
robertphillips@google.comd6bbbf82012-09-05 15:46:34 +000084}
bsalomon6bc1b5f2015-02-23 09:06:38 -080085
86///////////////////////////////////////////////////////////////////////////////
87
egdanielec00d942015-09-14 12:56:10 -070088bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) {
egdaniel79bd2ae2015-09-15 08:46:13 -070089 if (!stencil && !fRenderTarget->fStencilAttachment) {
90 // No need to do any work since we currently don't have a stencil attachment and
91 // we're not acctually adding one.
92 return true;
93 }
egdanielec00d942015-09-14 12:56:10 -070094 fRenderTarget->fStencilAttachment = stencil;
95 if (!fRenderTarget->completeStencilAttachment()) {
96 SkSafeSetNull(fRenderTarget->fStencilAttachment);
97 return false;
halcanary9d524f22016-03-29 09:03:52 -070098 }
egdanielec00d942015-09-14 12:56:10 -070099 return true;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800100}
cdalton28f45b92016-03-07 13:58:26 -0800101
cdalton193d9cf2016-05-12 11:52:02 -0700102int GrRenderTargetPriv::numStencilBits() const {
103 return fRenderTarget->fStencilAttachment ? fRenderTarget->fStencilAttachment->bits() : 0;
104}
105
cdalton28f45b92016-03-07 13:58:26 -0800106const GrGpu::MultisampleSpecs&
107GrRenderTargetPriv::getMultisampleSpecs(const GrStencilSettings& stencil) const {
108 return fRenderTarget->getGpu()->getMultisampleSpecs(fRenderTarget, stencil);
109}
csmartdaltonbf4a8f92016-09-06 10:01:06 -0700110
111int GrRenderTargetPriv::maxWindowRectangles() const {
112 return (this->flags() & Flags::kWindowRectsSupport) ?
113 fRenderTarget->getGpu()->caps()->maxWindowRectangles() : 0;
114}