1 /*
2 * Copyright 2016 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 #include "src/gpu/GrOpsRenderPass.h"
9 
10 #include "include/core/SkRect.h"
11 #include "include/gpu/GrContext.h"
12 #include "src/gpu/GrCaps.h"
13 #include "src/gpu/GrContextPriv.h"
14 #include "src/gpu/GrFixedClip.h"
15 #include "src/gpu/GrGpu.h"
16 #include "src/gpu/GrMesh.h"
17 #include "src/gpu/GrPrimitiveProcessor.h"
18 #include "src/gpu/GrProgramInfo.h"
19 #include "src/gpu/GrRenderTarget.h"
20 #include "src/gpu/GrRenderTargetPriv.h"
21 #include "src/gpu/GrTexturePriv.h"
22 
clear(const GrFixedClip & clip,const SkPMColor4f & color)23 void GrOpsRenderPass::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
24     SkASSERT(fRenderTarget);
25     // A clear at this level will always be a true clear, so make sure clears were not supposed to
26     // be redirected to draws instead
27     SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws());
28     SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
29     this->onClear(clip, color);
30 }
31 
clearStencilClip(const GrFixedClip & clip,bool insideStencilMask)32 void GrOpsRenderPass::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
33     // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings
34     SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws());
35     this->onClearStencilClip(clip, insideStencilMask);
36 }
37 
draw(const GrProgramInfo & programInfo,const GrMesh meshes[],int meshCount,const SkRect & bounds)38 bool GrOpsRenderPass::draw(const GrProgramInfo& programInfo,
39                            const GrMesh meshes[], int meshCount, const SkRect& bounds) {
40     if (!meshCount) {
41         return true;
42     }
43 
44 #ifdef SK_DEBUG
45     SkASSERT(!programInfo.primProc().hasInstanceAttributes() ||
46              this->gpu()->caps()->instanceAttribSupport());
47 
48     programInfo.compatibleWithMeshes(meshes, meshCount);
49     programInfo.checkAllInstantiated();
50     programInfo.checkMSAAAndMIPSAreResolved();
51 #endif
52 
53     if (programInfo.primProc().numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
54         this->gpu()->stats()->incNumFailedDraws();
55         return false;
56     }
57     this->onDraw(programInfo, meshes, meshCount, bounds);
58 
59 #ifdef SK_DEBUG
60     GrProcessor::CustomFeatures processorFeatures = programInfo.requestedFeatures();
61     if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) {
62         // Verify we always have the same sample pattern key, regardless of graphics state.
63         SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget)
64                          == fRenderTarget->renderTargetPriv().getSamplePatternKey());
65     }
66 #endif
67     return true;
68 }
69