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 21 #include <SkImageInfo.h> 22 #include <ui/GraphicBuffer.h> 23 #include <utils/RefBase.h> 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: 35 VkFunctorDrawHandler(sp<WebViewFunctor::Handle> functor_handle, const SkMatrix& matrix, 36 const SkIRect& clip, const SkImageInfo& image_info); 37 ~VkFunctorDrawHandler() override; 38 39 void draw(const GrBackendDrawableInfo& info) override; 40 41 private: 42 typedef GpuDrawHandler INHERITED; 43 sp<WebViewFunctor::Handle> mFunctorHandle; 44 const SkMatrix mMatrix; 45 const SkIRect mClip; 46 const SkImageInfo mImageInfo; 47 48 bool mDrawn = false; 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: 57 using FunctorDrawable::FunctorDrawable; 58 59 ~VkFunctorDrawable() override; 60 61 protected: 62 // SkDrawable functions: 63 void onDraw(SkCanvas* canvas) override; 64 std::unique_ptr<FunctorDrawable::GpuDrawHandler> onSnapGpuDrawHandler( 65 GrBackendApi backendApi, const SkMatrix& matrix, const SkIRect& clip, 66 const SkImageInfo& image_info) override; 67 }; 68 69 } // namespace skiapipeline 70 } // namespace uirenderer 71 } // namespace android 72