Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 "vk/GrVkSecondaryCBDrawContext.h" |
| 9 | |
| 10 | #include "GrContext.h" |
| 11 | #include "GrContextPriv.h" |
| 12 | #include "GrRenderTargetContext.h" |
| 13 | #include "SkGpuDevice.h" |
| 14 | #include "SkImageInfo.h" |
| 15 | #include "SkSurfaceProps.h" |
| 16 | #include "vk/GrVkTypes.h" |
| 17 | |
| 18 | sk_sp<GrVkSecondaryCBDrawContext> GrVkSecondaryCBDrawContext::Make(GrContext* ctx, |
| 19 | const SkImageInfo& imageInfo, |
| 20 | const GrVkDrawableInfo& vkInfo, |
| 21 | const SkSurfaceProps* props) { |
| 22 | if (!ctx) { |
| 23 | return nullptr; |
| 24 | } |
| 25 | |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 26 | if (ctx->backend() != GrBackendApi::kVulkan) { |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 27 | return nullptr; |
| 28 | } |
| 29 | |
| 30 | sk_sp<GrRenderTargetContext> rtc( |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 31 | ctx->priv().makeVulkanSecondaryCBRenderTargetContext(imageInfo, vkInfo, props)); |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 32 | |
| 33 | int width = rtc->width(); |
| 34 | int height = rtc->height(); |
| 35 | |
| 36 | sk_sp<SkGpuDevice> device(SkGpuDevice::Make(ctx, std::move(rtc), width, height, |
| 37 | SkGpuDevice::kUninit_InitContents)); |
| 38 | if (!device) { |
| 39 | return nullptr; |
| 40 | } |
| 41 | |
| 42 | return sk_sp<GrVkSecondaryCBDrawContext>(new GrVkSecondaryCBDrawContext(std::move(device))); |
| 43 | } |
| 44 | |
| 45 | GrVkSecondaryCBDrawContext::GrVkSecondaryCBDrawContext(sk_sp<SkGpuDevice> device) |
| 46 | : fDevice(device) {} |
| 47 | |
| 48 | GrVkSecondaryCBDrawContext::~GrVkSecondaryCBDrawContext() { |
| 49 | SkASSERT(!fDevice); |
| 50 | SkASSERT(!fCachedCanvas.get()); |
| 51 | } |
| 52 | |
| 53 | SkCanvas* GrVkSecondaryCBDrawContext::getCanvas() { |
| 54 | if (!fCachedCanvas) { |
| 55 | fCachedCanvas = std::unique_ptr<SkCanvas>(new SkCanvas(fDevice)); |
| 56 | } |
| 57 | return fCachedCanvas.get(); |
| 58 | } |
| 59 | |
| 60 | void GrVkSecondaryCBDrawContext::flush() { |
| 61 | fDevice->flush(); |
| 62 | } |
| 63 | |
Greg Daniel | 3d92a49 | 2019-01-07 12:59:03 -0500 | [diff] [blame] | 64 | bool GrVkSecondaryCBDrawContext::wait(int numSemaphores, |
| 65 | const GrBackendSemaphore waitSemaphores[]) { |
| 66 | return fDevice->wait(numSemaphores, waitSemaphores); |
| 67 | } |
| 68 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 69 | void GrVkSecondaryCBDrawContext::releaseResources() { |
| 70 | fCachedCanvas.reset(); |
| 71 | fDevice.reset(); |
| 72 | } |
| 73 | |