egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 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 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 8 | #include "src/gpu/GrOpsRenderPass.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkRect.h" |
| 11 | #include "include/gpu/GrContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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" |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrProgramInfo.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrRenderTargetPriv.h" |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 21 | #include "src/gpu/GrTexturePriv.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 22 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 23 | void GrOpsRenderPass::clear(const GrFixedClip& clip, const SkPMColor4f& color) { |
Robert Phillips | 4912d90 | 2018-04-27 12:09:35 -0400 | [diff] [blame] | 24 | SkASSERT(fRenderTarget); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 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()); |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 29 | this->onClear(clip, color); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 32 | void GrOpsRenderPass::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 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()); |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 35 | this->onClearStencilClip(clip, insideStencilMask); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 38 | bool GrOpsRenderPass::draw(const GrProgramInfo& programInfo, |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 39 | const GrMesh meshes[], int meshCount, const SkRect& bounds) { |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 40 | if (!meshCount) { |
| 41 | return true; |
| 42 | } |
| 43 | |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 44 | #ifdef SK_DEBUG |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 45 | SkASSERT(!programInfo.primProc().hasInstanceAttributes() || |
| 46 | this->gpu()->caps()->instanceAttribSupport()); |
Chris Dalton | ce425af | 2019-12-16 10:39:03 -0700 | [diff] [blame] | 47 | SkASSERT(!programInfo.pipeline().usesConservativeRaster() || |
| 48 | this->gpu()->caps()->conservativeRasterSupport()); |
Chris Dalton | 1215cda | 2019-12-17 21:44:04 -0700 | [diff] [blame^] | 49 | SkASSERT(!programInfo.pipeline().isWireframe() || |
| 50 | this->gpu()->caps()->wireframeSupport()); |
Robert Phillips | 865d8d6 | 2019-10-09 14:15:55 -0400 | [diff] [blame] | 51 | |
Robert Phillips | 2d8a95e | 2019-10-10 12:50:22 -0400 | [diff] [blame] | 52 | programInfo.compatibleWithMeshes(meshes, meshCount); |
| 53 | programInfo.checkAllInstantiated(); |
| 54 | programInfo.checkMSAAAndMIPSAreResolved(); |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 55 | #endif |
Robert Phillips | a91e0b7 | 2017-05-01 13:12:20 -0400 | [diff] [blame] | 56 | |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 57 | if (programInfo.primProc().numVertexAttributes() > this->gpu()->caps()->maxVertexAttributes()) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 58 | this->gpu()->stats()->incNumFailedDraws(); |
| 59 | return false; |
| 60 | } |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 61 | this->onDraw(programInfo, meshes, meshCount, bounds); |
| 62 | |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 63 | #ifdef SK_DEBUG |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 64 | GrProcessor::CustomFeatures processorFeatures = programInfo.requestedFeatures(); |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 65 | if (GrProcessor::CustomFeatures::kSampleLocations & processorFeatures) { |
| 66 | // Verify we always have the same sample pattern key, regardless of graphics state. |
| 67 | SkASSERT(this->gpu()->findOrAssignSamplePatternKey(fRenderTarget) |
| 68 | == fRenderTarget->renderTargetPriv().getSamplePatternKey()); |
| 69 | } |
| 70 | #endif |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 71 | return true; |
| 72 | } |