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/GrGpuCommandBuffer.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/GrRenderTarget.h"
19 #include "src/gpu/GrRenderTargetPriv.h"
20
clear(const GrFixedClip & clip,const SkPMColor4f & color)21 void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
22 SkASSERT(fRenderTarget);
23 // A clear at this level will always be a true clear, so make sure clears were not supposed to
24 // be redirected to draws instead
25 SkASSERT(!this->gpu()->caps()->performColorClearsAsDraws());
26 SkASSERT(!clip.scissorEnabled() || !this->gpu()->caps()->performPartialClearsAsDraws());
27 this->onClear(clip, color);
28 }
29
clearStencilClip(const GrFixedClip & clip,bool insideStencilMask)30 void GrGpuRTCommandBuffer::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
31 // As above, make sure the stencil clear wasn't supposed to be a draw rect with stencil settings
32 SkASSERT(!this->gpu()->caps()->performStencilClearsAsDraws());
33 this->onClearStencilClip(clip, insideStencilMask);
34 }
35
draw(const GrPrimitiveProcessor & primProc,const GrPipeline & pipeline,const GrPipeline::FixedDynamicState * fixedDynamicState,const GrPipeline::DynamicStateArrays * dynamicStateArrays,const GrMesh meshes[],int meshCount,const SkRect & bounds)36 bool GrGpuRTCommandBuffer::draw(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline,
37 const GrPipeline::FixedDynamicState* fixedDynamicState,
38 const GrPipeline::DynamicStateArrays* dynamicStateArrays,
39 const GrMesh meshes[], int meshCount, const SkRect& bounds) {
40 #ifdef SK_DEBUG
41 SkASSERT(!primProc.hasInstanceAttributes() || this->gpu()->caps()->instanceAttribSupport());
42 for (int i = 0; i < meshCount; ++i) {
43 SkASSERT(!GrPrimTypeRequiresGeometryShaderSupport(meshes[i].primitiveType()) ||
44 this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
45 SkASSERT(primProc.hasVertexAttributes() == meshes[i].hasVertexData());
46 SkASSERT(primProc.hasInstanceAttributes() == meshes[i].hasInstanceData());
47 }
48 #endif
49 SkASSERT(!pipeline.isScissorEnabled() || fixedDynamicState ||
50 (dynamicStateArrays && dynamicStateArrays->fScissorRects));
51
52 SkASSERT(!pipeline.isBad());
53
54 #ifdef SK_DEBUG
55 if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) {
56 GrTextureProxy** processorProxies = fixedDynamicState->fPrimitiveProcessorTextures;
57 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
58 SkASSERT(processorProxies[i]->isInstantiated());
59 }
60 }
61 if (dynamicStateArrays && dynamicStateArrays->fPrimitiveProcessorTextures) {
62 int n = primProc.numTextureSamplers() * meshCount;
63 const auto* textures = dynamicStateArrays->fPrimitiveProcessorTextures;
64 for (int i = 0; i < n; ++i) {
65 SkASSERT(textures[i]->isInstantiated());
66 }
67 SkASSERT(meshCount >= 1);
68 const GrTextureProxy* const* primProcProxies =
69 dynamicStateArrays->fPrimitiveProcessorTextures;
70 for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
71 const GrBackendFormat& format = primProcProxies[i]->backendFormat();
72 GrTextureType type = primProcProxies[i]->textureType();
73 GrPixelConfig config = primProcProxies[i]->config();
74 for (int j = 1; j < meshCount; ++j) {
75 const GrTextureProxy* testProxy =
76 primProcProxies[j*primProc.numTextureSamplers() + i];
77 SkASSERT(testProxy->backendFormat() == format);
78 SkASSERT(testProxy->textureType() == type);
79 SkASSERT(testProxy->config() == config);
80 }
81 }
82 }
83 #endif
84
85 if (primProc.numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) {
86 this->gpu()->stats()->incNumFailedDraws();
87 return false;
88 }
89 this->onDraw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, meshes, meshCount,
90 bounds);
91 #ifdef SK_DEBUG
92 GrProcessor::CustomFeatures processorFeatures = primProc.requestedFeatures();
93 for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
94 processorFeatures |= pipeline.getFragmentProcessor(i).requestedFeatures();
95 }
96 processorFeatures |= pipeline.getXferProcessor().requestedFeatures();
97 if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) {
98 // Verify we always have the same sample pattern key, regardless of graphics state.
99 SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget)
100 == fRenderTarget->renderTargetPriv().getSamplePatternKey());
101 }
102 #endif
103 return true;
104 }
105