| 53 | } |
| 54 | |
| 55 | void RuntimeDrawTask::execute(CommandEncoder* encoder) { |
| 56 | TASK_MARK(tgfx::inspect::OpTaskType::RuntimeDrawTask); |
| 57 | std::vector<std::shared_ptr<TextureView>> textures = {}; |
| 58 | textures.reserve(inputTextures.size()); |
| 59 | for (size_t i = 0; i < inputTextures.size(); i++) { |
| 60 | std::shared_ptr<TextureView> textureView = nullptr; |
| 61 | if (auto inputProxy = inputTextures[i]) { |
| 62 | textureView = GetFlatTextureView(encoder, std::move(inputProxy), inputVertexBuffers[i].get()); |
| 63 | } |
| 64 | if (textureView == nullptr) { |
| 65 | LOGE("RuntimeDrawTask::execute() Failed to get the input %d texture view!", i); |
| 66 | return; |
| 67 | } |
| 68 | textures.push_back(textureView); |
| 69 | } |
| 70 | auto renderTarget = renderTargetProxy->getRenderTarget(); |
| 71 | if (renderTarget == nullptr) { |
| 72 | LOGE("RuntimeDrawTask::execute() Failed to get the render target!"); |
| 73 | return; |
| 74 | } |
| 75 | auto context = renderTarget->getContext(); |
| 76 | static auto RuntimeProgramType = UniqueID::Next(); |
| 77 | BytesKey programKey = {}; |
| 78 | programKey.write(RuntimeProgramType); |
| 79 | programKey.write(effect->programID()); |
| 80 | auto program = context->globalCache()->findProgram(programKey); |
| 81 | if (program == nullptr) { |
| 82 | program = RuntimeProgramWrapper::Wrap(effect->onCreateProgram(context)); |
| 83 | if (program == nullptr) { |
| 84 | LOGE("RuntimeDrawTask::execute() Failed to create the runtime program!"); |
| 85 | return; |
| 86 | } |
| 87 | context->globalCache()->addProgram(programKey, program); |
| 88 | } |
| 89 | std::vector<BackendTexture> backendTextures = {}; |
| 90 | backendTextures.reserve(textures.size()); |
| 91 | for (auto& textureView : textures) { |
| 92 | backendTextures.push_back(textureView->getBackendTexture()); |
| 93 | } |
| 94 | effect->onDraw(RuntimeProgramWrapper::Unwrap(program.get()), backendTextures, |
| 95 | renderTarget->getBackendRenderTarget(), offset); |
| 96 | // Reset GL state to prevent side effects from external GL calls. |
| 97 | context->gpu()->resetGLState(); |
| 98 | if (renderTarget->sampleCount() > 1) { |
| 99 | RenderPassDescriptor descriptor(renderTarget->getRenderTexture(), |
| 100 | renderTarget->getSampleTexture()); |
| 101 | auto renderPass = encoder->beginRenderPass(descriptor); |
| 102 | DEBUG_ASSERT(renderPass != nullptr); |
| 103 | renderPass->end(); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | std::shared_ptr<TextureView> RuntimeDrawTask::GetFlatTextureView( |
| 108 | CommandEncoder* encoder, std::shared_ptr<TextureProxy> textureProxy, |
nothing calls this directly
no test coverage detected