blob: d3f97773b91d7f12f54763179d7cce1e26bdc454 [file] [log] [blame]
Chris Blume41423392018-11-06 11:47:03 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include "FunctorDrawable.h"
20
Chris Blume41423392018-11-06 11:47:03 -080021#include <SkImageInfo.h>
John Reck283bb462018-12-13 16:40:14 -080022#include <ui/GraphicBuffer.h>
23#include <utils/RefBase.h>
Chris Blume41423392018-11-06 11:47:03 -080024
25namespace android {
26namespace uirenderer {
27namespace skiapipeline {
28
29/**
30 * This draw handler will be returned by VkFunctorDrawable's onSnapGpuDrawHandler. It allows us to
31 * issue Vulkan commands while the command buffer is being flushed.
32 */
33class VkFunctorDrawHandler : public FunctorDrawable::GpuDrawHandler {
34public:
Bo Liu7b8c1eb2019-01-08 20:17:55 -080035 VkFunctorDrawHandler(sp<WebViewFunctor::Handle> functor_handle, const SkMatrix& matrix,
36 const SkIRect& clip, const SkImageInfo& image_info);
Chris Blume41423392018-11-06 11:47:03 -080037 ~VkFunctorDrawHandler() override;
38
39 void draw(const GrBackendDrawableInfo& info) override;
John Reck283bb462018-12-13 16:40:14 -080040
Chris Blume41423392018-11-06 11:47:03 -080041private:
42 typedef GpuDrawHandler INHERITED;
Bo Liu7b8c1eb2019-01-08 20:17:55 -080043 sp<WebViewFunctor::Handle> mFunctorHandle;
44 const SkMatrix mMatrix;
45 const SkIRect mClip;
46 const SkImageInfo mImageInfo;
Bo Liud25d1342019-02-04 14:55:02 -080047
48 bool mDrawn = false;
Chris Blume41423392018-11-06 11:47:03 -080049};
50
51/**
52 * This drawable wraps a Vulkan functor enabling it to be recorded into a list of Skia drawing
53 * commands.
54 */
55class VkFunctorDrawable : public FunctorDrawable {
56public:
John Reck283bb462018-12-13 16:40:14 -080057 using FunctorDrawable::FunctorDrawable;
Chris Blume41423392018-11-06 11:47:03 -080058
John Reck283bb462018-12-13 16:40:14 -080059 ~VkFunctorDrawable() override;
Chris Blume41423392018-11-06 11:47:03 -080060
61protected:
62 // SkDrawable functions:
63 void onDraw(SkCanvas* canvas) override;
John Reck283bb462018-12-13 16:40:14 -080064 std::unique_ptr<FunctorDrawable::GpuDrawHandler> onSnapGpuDrawHandler(
Bo Liu7b8c1eb2019-01-08 20:17:55 -080065 GrBackendApi backendApi, const SkMatrix& matrix, const SkIRect& clip,
66 const SkImageInfo& image_info) override;
Chris Blume41423392018-11-06 11:47:03 -080067};
68
69} // namespace skiapipeline
70} // namespace uirenderer
71} // namespace android