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