• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
Make(GrContext * ctx,const SkImageInfo & imageInfo,const GrVkDrawableInfo & vkInfo,const SkSurfaceProps * props)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 
26     if (ctx->backend() != GrBackendApi::kVulkan) {
27         return nullptr;
28     }
29 
30     sk_sp<GrRenderTargetContext> rtc(
31             ctx->contextPriv().makeVulkanSecondaryCBRenderTargetContext(imageInfo, vkInfo, props));
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 
GrVkSecondaryCBDrawContext(sk_sp<SkGpuDevice> device)45 GrVkSecondaryCBDrawContext::GrVkSecondaryCBDrawContext(sk_sp<SkGpuDevice> device)
46     : fDevice(device) {}
47 
~GrVkSecondaryCBDrawContext()48 GrVkSecondaryCBDrawContext::~GrVkSecondaryCBDrawContext() {
49     SkASSERT(!fDevice);
50     SkASSERT(!fCachedCanvas.get());
51 }
52 
getCanvas()53 SkCanvas* GrVkSecondaryCBDrawContext::getCanvas() {
54     if (!fCachedCanvas) {
55         fCachedCanvas = std::unique_ptr<SkCanvas>(new SkCanvas(fDevice));
56     }
57     return fCachedCanvas.get();
58 }
59 
flush()60 void GrVkSecondaryCBDrawContext::flush() {
61     fDevice->flush();
62 }
63 
wait(int numSemaphores,const GrBackendSemaphore waitSemaphores[])64 bool GrVkSecondaryCBDrawContext::wait(int numSemaphores,
65                                       const GrBackendSemaphore waitSemaphores[]) {
66     return fDevice->wait(numSemaphores, waitSemaphores);
67 }
68 
releaseResources()69 void GrVkSecondaryCBDrawContext::releaseResources() {
70     fCachedCanvas.reset();
71     fDevice.reset();
72 }
73 
74