Line data Source code
1 : /*
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"
12 : #include "GrContextPriv.h"
13 : #include "GrRenderTargetContext.h"
14 : #include "GrGpu.h"
15 : #include "GrRenderTargetOpList.h"
16 : #include "GrRenderTargetPriv.h"
17 : #include "GrStencilAttachment.h"
18 : #include "GrStencilSettings.h"
19 :
20 0 : GrRenderTarget::GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc, Flags flags,
21 0 : GrStencilAttachment* stencil)
22 : : INHERITED(gpu, desc)
23 : , fStencilAttachment(stencil)
24 : , fMultisampleSpecsID(0)
25 0 : , fFlags(flags) {
26 0 : SkASSERT(!(fFlags & Flags::kMixedSampled) || fDesc.fSampleCnt > 0);
27 0 : SkASSERT(!(fFlags & Flags::kWindowRectsSupport) || gpu->caps()->maxWindowRectangles() > 0);
28 0 : fResolveRect.setLargestInverted();
29 0 : }
30 :
31 0 : void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
32 0 : if (kCanResolve_ResolveType == getResolveType()) {
33 0 : if (rect) {
34 0 : fResolveRect.join(*rect);
35 0 : if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
36 0 : fResolveRect.setEmpty();
37 : }
38 : } else {
39 0 : fResolveRect.setLTRB(0, 0, this->width(), this->height());
40 : }
41 : }
42 0 : }
43 :
44 0 : void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
45 0 : fResolveRect = rect;
46 0 : if (fResolveRect.isEmpty()) {
47 0 : fResolveRect.setLargestInverted();
48 : } else {
49 0 : if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
50 0 : fResolveRect.setLargestInverted();
51 : }
52 : }
53 0 : }
54 :
55 0 : void GrRenderTarget::onRelease() {
56 0 : SkSafeSetNull(fStencilAttachment);
57 :
58 0 : INHERITED::onRelease();
59 0 : }
60 :
61 0 : void GrRenderTarget::onAbandon() {
62 0 : SkSafeSetNull(fStencilAttachment);
63 :
64 : // The contents of this renderTarget are gone/invalid. It isn't useful to point back
65 : // the creating opList.
66 0 : this->setLastOpList(nullptr);
67 :
68 0 : INHERITED::onAbandon();
69 0 : }
70 :
71 : ///////////////////////////////////////////////////////////////////////////////
72 :
73 0 : bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) {
74 0 : if (!stencil && !fRenderTarget->fStencilAttachment) {
75 : // No need to do any work since we currently don't have a stencil attachment and
76 : // we're not actually adding one.
77 0 : return true;
78 : }
79 0 : fRenderTarget->fStencilAttachment = stencil;
80 0 : if (!fRenderTarget->completeStencilAttachment()) {
81 0 : SkSafeSetNull(fRenderTarget->fStencilAttachment);
82 0 : return false;
83 : }
84 0 : return true;
85 : }
86 :
87 0 : int GrRenderTargetPriv::numStencilBits() const {
88 0 : SkASSERT(this->getStencilAttachment());
89 0 : return this->getStencilAttachment()->bits();
90 : }
91 :
92 : const GrGpu::MultisampleSpecs&
93 0 : GrRenderTargetPriv::getMultisampleSpecs(const GrPipeline& pipeline) const {
94 0 : SkASSERT(fRenderTarget == pipeline.getRenderTarget()); // TODO: remove RT from pipeline.
95 0 : GrGpu* gpu = fRenderTarget->getGpu();
96 0 : if (auto id = fRenderTarget->fMultisampleSpecsID) {
97 0 : SkASSERT(gpu->queryMultisampleSpecs(pipeline).fUniqueID == id);
98 0 : return gpu->getMultisampleSpecs(id);
99 : }
100 0 : const GrGpu::MultisampleSpecs& specs = gpu->queryMultisampleSpecs(pipeline);
101 0 : fRenderTarget->fMultisampleSpecsID = specs.fUniqueID;
102 0 : return specs;
103 : }
104 :
|