Chris Blume | 4142339 | 2018-11-06 11:47:03 -0800 | [diff] [blame] | 1 | /* |
| 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 Blume | 4142339 | 2018-11-06 11:47:03 -0800 | [diff] [blame] | 21 | #include <SkImageInfo.h> |
John Reck | 283bb46 | 2018-12-13 16:40:14 -0800 | [diff] [blame] | 22 | #include <ui/GraphicBuffer.h> |
| 23 | #include <utils/RefBase.h> |
Chris Blume | 4142339 | 2018-11-06 11:47:03 -0800 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | namespace 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 | */ |
| 33 | class VkFunctorDrawHandler : public FunctorDrawable::GpuDrawHandler { |
| 34 | public: |
Bo Liu | 7b8c1eb | 2019-01-08 20:17:55 -0800 | [diff] [blame] | 35 | VkFunctorDrawHandler(sp<WebViewFunctor::Handle> functor_handle, const SkMatrix& matrix, |
| 36 | const SkIRect& clip, const SkImageInfo& image_info); |
Chris Blume | 4142339 | 2018-11-06 11:47:03 -0800 | [diff] [blame] | 37 | ~VkFunctorDrawHandler() override; |
| 38 | |
| 39 | void draw(const GrBackendDrawableInfo& info) override; |
John Reck | 283bb46 | 2018-12-13 16:40:14 -0800 | [diff] [blame] | 40 | |
Chris Blume | 4142339 | 2018-11-06 11:47:03 -0800 | [diff] [blame] | 41 | private: |
| 42 | typedef GpuDrawHandler INHERITED; |
Bo Liu | 7b8c1eb | 2019-01-08 20:17:55 -0800 | [diff] [blame] | 43 | sp<WebViewFunctor::Handle> mFunctorHandle; |
| 44 | const SkMatrix mMatrix; |
| 45 | const SkIRect mClip; |
| 46 | const SkImageInfo mImageInfo; |
Bo Liu | d25d134 | 2019-02-04 14:55:02 -0800 | [diff] [blame] | 47 | |
| 48 | bool mDrawn = false; |
Chris Blume | 4142339 | 2018-11-06 11:47:03 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * This drawable wraps a Vulkan functor enabling it to be recorded into a list of Skia drawing |
| 53 | * commands. |
| 54 | */ |
| 55 | class VkFunctorDrawable : public FunctorDrawable { |
| 56 | public: |
John Reck | 283bb46 | 2018-12-13 16:40:14 -0800 | [diff] [blame] | 57 | using FunctorDrawable::FunctorDrawable; |
Chris Blume | 4142339 | 2018-11-06 11:47:03 -0800 | [diff] [blame] | 58 | |
John Reck | 283bb46 | 2018-12-13 16:40:14 -0800 | [diff] [blame] | 59 | ~VkFunctorDrawable() override; |
Chris Blume | 4142339 | 2018-11-06 11:47:03 -0800 | [diff] [blame] | 60 | |
| 61 | protected: |
| 62 | // SkDrawable functions: |
| 63 | void onDraw(SkCanvas* canvas) override; |
John Reck | 283bb46 | 2018-12-13 16:40:14 -0800 | [diff] [blame] | 64 | std::unique_ptr<FunctorDrawable::GpuDrawHandler> onSnapGpuDrawHandler( |
Bo Liu | 7b8c1eb | 2019-01-08 20:17:55 -0800 | [diff] [blame] | 65 | GrBackendApi backendApi, const SkMatrix& matrix, const SkIRect& clip, |
| 66 | const SkImageInfo& image_info) override; |
Chris Blume | 4142339 | 2018-11-06 11:47:03 -0800 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // namespace skiapipeline |
| 70 | } // namespace uirenderer |
| 71 | } // namespace android |