1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrRenderTarget.h"
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrRenderTargetContext.h"
#include "GrGpu.h"
#include "GrRenderTargetOpList.h"
#include "GrRenderTargetPriv.h"
#include "GrStencilAttachment.h"
#include "GrStencilSettings.h"
#include "SkRectPriv.h"
GrRenderTarget::GrRenderTarget(GrGpu* gpu, const GrSurfaceDesc& desc,
GrRenderTargetFlags flags,
GrStencilAttachment* stencil)
: INHERITED(gpu, desc)
, fSampleCnt(desc.fSampleCnt)
, fStencilAttachment(stencil)
, fMultisampleSpecsID(0)
, fFlags(flags) {
SkASSERT(desc.fFlags & kRenderTarget_GrSurfaceFlag);
SkASSERT(!(fFlags & GrRenderTargetFlags::kMixedSampled) || fSampleCnt > 1);
SkASSERT(!(fFlags & GrRenderTargetFlags::kWindowRectsSupport) ||
gpu->caps()->maxWindowRectangles() > 0);
fResolveRect = SkRectPriv::MakeILargestInverted();
}
void GrRenderTarget::flagAsNeedingResolve(const SkIRect* rect) {
if (kCanResolve_ResolveType == getResolveType()) {
if (rect) {
fResolveRect.join(*rect);
if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
fResolveRect.setEmpty();
}
} else {
fResolveRect.setLTRB(0, 0, this->width(), this->height());
}
}
}
void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
fResolveRect = rect;
if (fResolveRect.isEmpty()) {
fResolveRect = SkRectPriv::MakeILargestInverted();
} else {
if (!fResolveRect.intersect(0, 0, this->width(), this->height())) {
fResolveRect = SkRectPriv::MakeILargestInverted();
}
}
}
void GrRenderTarget::flagAsResolved() {
fResolveRect = SkRectPriv::MakeILargestInverted();
}
void GrRenderTarget::onRelease() {
SkSafeSetNull(fStencilAttachment);
INHERITED::onRelease();
}
void GrRenderTarget::onAbandon() {
SkSafeSetNull(fStencilAttachment);
INHERITED::onAbandon();
}
///////////////////////////////////////////////////////////////////////////////
bool GrRenderTargetPriv::attachStencilAttachment(sk_sp<GrStencilAttachment> stencil) {
if (!stencil && !fRenderTarget->fStencilAttachment) {
// No need to do any work since we currently don't have a stencil attachment and
// we're not actually adding one.
return true;
}
fRenderTarget->fStencilAttachment = stencil.release();
if (!fRenderTarget->completeStencilAttachment()) {
SkSafeSetNull(fRenderTarget->fStencilAttachment);
return false;
}
return true;
}
int GrRenderTargetPriv::numStencilBits() const {
SkASSERT(this->getStencilAttachment());
return this->getStencilAttachment()->bits();
}
const GrGpu::MultisampleSpecs&
GrRenderTargetPriv::getMultisampleSpecs(const GrPipeline& pipeline) const {
SkASSERT(fRenderTarget == pipeline.renderTarget()); // TODO: remove RT from pipeline.
GrGpu* gpu = fRenderTarget->getGpu();
if (auto id = fRenderTarget->fMultisampleSpecsID) {
SkASSERT(gpu->queryMultisampleSpecs(pipeline).fUniqueID == id);
return gpu->getMultisampleSpecs(id);
}
const GrGpu::MultisampleSpecs& specs = gpu->queryMultisampleSpecs(pipeline);
fRenderTarget->fMultisampleSpecsID = specs.fUniqueID;
return specs;
}
|