LCOV - code coverage report
Current view: top level - xenolith/platform - XLPlatformViewInterface.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2024-05-12 00:16:13 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef XENOLITH_PLATFORM_XLPLATFORMVIEWINTERFACE_H_
      24             : #define XENOLITH_PLATFORM_XLPLATFORMVIEWINTERFACE_H_
      25             : 
      26             : #include "XLCoreInput.h"
      27             : #include "XLCoreInfo.h"
      28             : 
      29             : namespace STAPPLER_VERSIONIZED stappler::xenolith::platform {
      30             : 
      31             : class ViewInterface {
      32             : public:
      33          21 :         virtual ~ViewInterface() { }
      34             : 
      35             :         virtual void update(bool displayLink) = 0;
      36             :         virtual void end() = 0;
      37             : 
      38             :         virtual void handleInputEvent(const core::InputEventData &) = 0;
      39             :         virtual void handleInputEvents(Vector<core::InputEventData> &&) = 0;
      40             : 
      41             :         virtual Extent2 getExtent() const = 0;
      42             : 
      43             :         virtual bool isInputEnabled() const = 0;
      44             : 
      45             :         virtual void deprecateSwapchain(bool fast = false) = 0;
      46             : 
      47             :         virtual uint64_t retainView() = 0;
      48             :         virtual void releaseView(uint64_t) = 0;
      49             : 
      50             :         virtual void setReadyForNextFrame() = 0;
      51             : 
      52             :         virtual void linkWithNativeWindow(void *) = 0;
      53             :         virtual void stopNativeWindow() = 0;
      54             : 
      55             :         virtual void setContentPadding(const Padding &) = 0;
      56             : 
      57             :         virtual uint64_t getBackButtonCounter() const = 0;
      58             : 
      59             :         virtual void readFromClipboard(Function<void(BytesView, StringView)> &&, Ref *) = 0;
      60             :         virtual void writeToClipboard(BytesView, StringView contentType = StringView()) = 0;
      61             : };
      62             : 
      63             : class ViewInterfaceRef final {
      64             : public:
      65             :         ~ViewInterfaceRef() {
      66             :                 set(nullptr);
      67             :         }
      68             : 
      69             :         ViewInterfaceRef() { }
      70             : 
      71             :         ViewInterfaceRef(ViewInterface *iface) {
      72             :                 set(iface);
      73             :         }
      74             : 
      75             :         ViewInterfaceRef(const ViewInterfaceRef &r) {
      76             :                 set(r.get());
      77             :         }
      78             : 
      79             :         ViewInterfaceRef(ViewInterfaceRef &&r) : refId(r.refId), ref(r.ref) {
      80             :                 r.refId = 0;
      81             :                 r.ref = nullptr;
      82             :         }
      83             : 
      84             :         ViewInterfaceRef &operator=(ViewInterface *iface) {
      85             :                 set(iface);
      86             :                 return *this;
      87             :         }
      88             : 
      89             :         ViewInterfaceRef &operator=(const ViewInterfaceRef &r) {
      90             :                 set(r.get());
      91             :                 return *this;
      92             :         }
      93             : 
      94             :         ViewInterfaceRef &operator=(ViewInterfaceRef &&r) {
      95             :                 set(nullptr);
      96             :                 refId = r.refId;
      97             :                 ref = r.ref;
      98             :                 r.refId = 0;
      99             :                 r.ref = nullptr;
     100             :                 return *this;
     101             :         }
     102             : 
     103             :         ViewInterface *get() const { return ref; }
     104             : 
     105             :         inline operator ViewInterface * () const { return get(); }
     106             :         inline explicit operator bool () const { return ref != nullptr; }
     107             :         inline ViewInterface * operator->() const { return get(); }
     108             : 
     109             : private:
     110             :         void set(ViewInterface *r) {
     111             :                 if (ref) {
     112             :                         ref->releaseView(refId);
     113             :                 }
     114             :                 ref = r;
     115             :                 if (ref) {
     116             :                         refId = ref->retainView();
     117             :                 } else {
     118             :                         refId = 0;
     119             :                 }
     120             :         }
     121             : 
     122             :         uint64_t refId = 0;
     123             :         ViewInterface *ref = nullptr;
     124             : };
     125             : 
     126             : }
     127             : 
     128             : #endif /* XENOLITH_PLATFORM_XLPLATFORMVIEWINTERFACE_H_ */

Generated by: LCOV version 1.14