WebViewTexture.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright aXiuShen. All Rights Reserved.
  2. #pragma once
  3. #include "CoreTypes.h"
  4. #include "Containers/EnumAsByte.h"
  5. #include "Engine/Texture.h"
  6. #include "Math/Color.h"
  7. #include "Math/IntPoint.h"
  8. #include "Misc/Timespan.h"
  9. #include "Templates/SharedPointer.h"
  10. #include "UObject/ObjectMacros.h"
  11. #include "UObject/ScriptMacros.h"
  12. #include "WebViewTextureSample.h"
  13. #include "WebViewTexture.generated.h"
  14. /**
  15. * Implements a texture asset for rendering mobilebrowser output for Android.
  16. *
  17. * probably should have derived from UTexture2DDynamic (not UTexture)
  18. */
  19. UCLASS(hidecategories = (Adjustments, Compositing, LevelOfDetail, Object))
  20. class BASEBROWSER_API UWebViewTexture
  21. : public UTexture
  22. {
  23. GENERATED_UCLASS_BODY()
  24. public:
  25. /** The addressing mode to use for the X axis. */
  26. TEnumAsByte<TextureAddress> AddressX;
  27. /** The addressing mode to use for the Y axis. */
  28. TEnumAsByte<TextureAddress> AddressY;
  29. /** Whether to clear the texture when no media is being played (default = enabled). */
  30. bool AutoClear;
  31. /** The color used to clear the texture if AutoClear is enabled (default = black). */
  32. FLinearColor ClearColor;
  33. public:
  34. /**
  35. * Gets the current aspect ratio of the texture.
  36. *
  37. * @return Texture aspect ratio.
  38. * @see GetHeight, GetWidth
  39. */
  40. float GetAspectRatio() const;
  41. /**
  42. * Gets the current height of the texture.
  43. *
  44. * @return Texture height (in pixels).
  45. * @see GetAspectRatio, GetWidth
  46. */
  47. int32 GetHeight() const;
  48. /**
  49. * Gets the current width of the texture.
  50. *
  51. * @return Texture width (in pixels).
  52. * @see GetAspectRatio, GetHeight
  53. */
  54. int32 GetWidth() const;
  55. public:
  56. //~ UTexture interface.
  57. virtual void BeginDestroy() override;
  58. virtual FTextureResource* CreateResource() override;
  59. virtual EMaterialValueType GetMaterialType() const override;
  60. virtual float GetSurfaceWidth() const override;
  61. virtual float GetSurfaceHeight() const override;
  62. virtual FGuid GetExternalTextureGuid() const override;
  63. #if WEBVIEW_ENGINE_VERSION>=50300
  64. virtual float GetSurfaceDepth() const override { return 0; }
  65. virtual uint32 GetSurfaceArraySize() const override { return 0; }
  66. virtual ETextureClass GetTextureClass() const override { return ETextureClass::Other2DNoSource; }
  67. #endif
  68. public:
  69. //~ UObject interface.
  70. virtual FString GetDesc() override;
  71. virtual void GetResourceSizeEx(FResourceSizeEx& CumulativeResourceSize) override;
  72. void TickResource(TSharedPtr<FWebViewTextureSample, ESPMode::ThreadSafe> Sample);
  73. void SetExternalTextureGuid(FGuid guid);
  74. protected:
  75. /** Unregister the player's external texture GUID. */
  76. void UnregisterPlayerGuid();
  77. private:
  78. /** Current width and height of the resource (in pixels). */
  79. FIntPoint Dimensions;
  80. /** The previously used player GUID. */
  81. FGuid WebPlayerGuid;
  82. /** Texture sample queue. */
  83. TSharedPtr<FWebViewTextureSampleQueue, ESPMode::ThreadSafe> SampleQueue;
  84. /** Current size of the resource (in bytes).*/
  85. SIZE_T Size;
  86. };