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 <SkCanvas.h> 20 #include <SkDrawable.h> 21 22 #include <WebViewFunctorManager.h> 23 #include <utils/Functor.h> 24 #include <variant> 25 26 namespace android { 27 namespace uirenderer { 28 29 namespace skiapipeline { 30 31 /** 32 * This drawable wraps a functor enabling it to be recorded into a list 33 * of Skia drawing commands. 34 */ 35 class FunctorDrawable : public SkDrawable { 36 public: FunctorDrawable(int functor,SkCanvas * canvas)37 FunctorDrawable(int functor, SkCanvas* canvas) 38 : mBounds(canvas->getLocalClipBounds()) 39 , mWebViewHandle(WebViewFunctorManager::instance().handleFor(functor)) {} 40 ~FunctorDrawable()41 virtual ~FunctorDrawable() {} 42 syncFunctor(const WebViewSyncData & data)43 virtual void syncFunctor(const WebViewSyncData& data) const { 44 mWebViewHandle->sync(data); 45 } 46 onRemovedFromTree()47 virtual void onRemovedFromTree() { 48 mWebViewHandle->onRemovedFromTree(); 49 } 50 51 protected: onGetBounds()52 virtual SkRect onGetBounds() override { return mBounds; } 53 54 const SkRect mBounds; 55 sp<WebViewFunctor::Handle> mWebViewHandle; 56 }; 57 58 } // namespace skiapipeline 59 } // namespace uirenderer 60 } // namespace android 61