void set_dynamic_scissor_state(GrVkGpu* gpu, GrVkCommandBuffer* cmdBuffer, const GrPipeline& pipeline, const GrRenderTarget& target) { // We always use one scissor and if it is disabled we just make it the size of the RT const GrScissorState& scissorState = pipeline.getScissorState(); VkRect2D scissor; if (scissorState.enabled() && !scissorState.rect().contains(0, 0, target.width(), target.height())) { // This all assumes the scissorState has previously been clipped to the device space render // target. scissor.offset.x = scissorState.rect().fLeft; scissor.extent.width = scissorState.rect().width(); if (kTopLeft_GrSurfaceOrigin == target.origin()) { scissor.offset.y = scissorState.rect().fTop; } else { SkASSERT(kBottomLeft_GrSurfaceOrigin == target.origin()); scissor.offset.y = target.height() - scissorState.rect().fBottom; } scissor.extent.height = scissorState.rect().height(); SkASSERT(scissor.offset.x >= 0); SkASSERT(scissor.offset.x + scissor.extent.width <= (uint32_t)target.width()); SkASSERT(scissor.offset.y >= 0); SkASSERT(scissor.offset.y + scissor.extent.height <= (uint32_t)target.height()); } else { scissor.extent.width = target.width(); scissor.extent.height = target.height(); scissor.offset.x = 0; scissor.offset.y = 0; } cmdBuffer->setScissor(gpu, 0, 1, &scissor); }
void setup_viewport_scissor_state(const GrVkGpu* gpu, const GrPipeline& pipeline, const GrVkRenderTarget* vkRT, VkPipelineViewportStateCreateInfo* viewportInfo, VkViewport* viewport, VkRect2D* scissor) { memset(viewportInfo, 0, sizeof(VkPipelineViewportStateCreateInfo)); viewportInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; viewportInfo->pNext = nullptr; viewportInfo->flags = 0; viewport->x = 0.0f; viewport->y = 0.0f; viewport->width = SkIntToScalar(vkRT->width()); viewport->height = SkIntToScalar(vkRT->height()); viewport->minDepth = 0.0f; viewport->maxDepth = 1.0f; viewportInfo->viewportCount = 1; viewportInfo->pViewports = viewport; const GrScissorState& scissorState = pipeline.getScissorState(); if (scissorState.enabled() && !scissorState.rect().contains(0, 0, vkRT->width(), vkRT->height())) { // This all assumes the scissorState has previously been clipped to the device space render // target. scissor->offset.x = scissorState.rect().fLeft; scissor->extent.width = scissorState.rect().width(); if (kTopLeft_GrSurfaceOrigin == vkRT->origin()) { scissor->offset.y = scissorState.rect().fTop; } else { SkASSERT(kBottomLeft_GrSurfaceOrigin == vkRT->origin()); scissor->offset.y = vkRT->height() - scissorState.rect().fBottom; } scissor->extent.height = scissorState.rect().height(); viewportInfo->scissorCount = 1; viewportInfo->pScissors = scissor; SkASSERT(scissor->offset.x >= 0); SkASSERT(scissor->offset.x + scissor->extent.width <= (uint32_t)vkRT->width()); SkASSERT(scissor->offset.y >= 0); SkASSERT(scissor->offset.y + scissor->extent.height <= (uint32_t)vkRT->height()); } else { scissor->extent.width = vkRT->width(); scissor->extent.height = vkRT->height(); scissor->offset.x = 0; scissor->offset.y = 0; viewportInfo->scissorCount = 1; viewportInfo->pScissors = scissor; } SkASSERT(viewportInfo->viewportCount == viewportInfo->scissorCount); }