blob: 7618141912fc9babc576884717e927fb535df7f4 [file] [log] [blame]
Greg Danielb46add82019-01-02 14:51:29 -05001/*
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
18sk_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 Phillips4217ea72019-01-30 13:08:28 -050026 if (ctx->backend() != GrBackendApi::kVulkan) {
Greg Danielb46add82019-01-02 14:51:29 -050027 return nullptr;
28 }
29
30 sk_sp<GrRenderTargetContext> rtc(
Robert Phillips9da87e02019-02-04 13:26:26 -050031 ctx->priv().makeVulkanSecondaryCBRenderTargetContext(imageInfo, vkInfo, props));
Greg Danielb46add82019-01-02 14:51:29 -050032
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
45GrVkSecondaryCBDrawContext::GrVkSecondaryCBDrawContext(sk_sp<SkGpuDevice> device)
46 : fDevice(device) {}
47
48GrVkSecondaryCBDrawContext::~GrVkSecondaryCBDrawContext() {
49 SkASSERT(!fDevice);
50 SkASSERT(!fCachedCanvas.get());
51}
52
53SkCanvas* GrVkSecondaryCBDrawContext::getCanvas() {
54 if (!fCachedCanvas) {
55 fCachedCanvas = std::unique_ptr<SkCanvas>(new SkCanvas(fDevice));
56 }
57 return fCachedCanvas.get();
58}
59
60void GrVkSecondaryCBDrawContext::flush() {
61 fDevice->flush();
62}
63
Greg Daniel3d92a492019-01-07 12:59:03 -050064bool GrVkSecondaryCBDrawContext::wait(int numSemaphores,
65 const GrBackendSemaphore waitSemaphores[]) {
66 return fDevice->wait(numSemaphores, waitSemaphores);
67}
68
Greg Danielb46add82019-01-02 14:51:29 -050069void GrVkSecondaryCBDrawContext::releaseResources() {
70 fCachedCanvas.reset();
71 fDevice.reset();
72}
73