TestsInterface.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019-2023 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUI_TESTS_TESTSINTERFACE_H
  29. #define RMLUI_TESTS_TESTSINTERFACE_H
  30. #include <RmlUi/Core/Mesh.h>
  31. #include <RmlUi/Core/RenderInterface.h>
  32. #include <RmlUi/Core/SystemInterface.h>
  33. #include <Shell.h>
  34. class TestsSystemInterface : public Rml::SystemInterface {
  35. public:
  36. ~TestsSystemInterface();
  37. double GetElapsedTime() override;
  38. bool LogMessage(Rml::Log::Type type, const Rml::String& message) override;
  39. // Checks and clears previously logged messages, then sets the number of expected
  40. // warnings and errors until the next call.
  41. void SetNumExpectedWarnings(int num_expected_warnings);
  42. void SetTime(double t);
  43. private:
  44. double elapsed_time = 0.0;
  45. int num_logged_warnings = 0;
  46. int num_expected_warnings = 0;
  47. Rml::StringList warnings;
  48. };
  49. class TestsRenderInterface : public Rml::RenderInterface {
  50. public:
  51. struct Counters {
  52. size_t compile_geometry;
  53. size_t render_geometry;
  54. size_t release_geometry;
  55. size_t load_texture;
  56. size_t generate_texture;
  57. size_t release_texture;
  58. size_t enable_scissor;
  59. size_t set_scissor;
  60. size_t enable_clip_mask;
  61. size_t render_to_clip_mask;
  62. size_t set_transform;
  63. size_t compile_filter;
  64. size_t release_filter;
  65. size_t compile_shader;
  66. size_t render_shader;
  67. size_t release_shader;
  68. };
  69. Rml::CompiledGeometryHandle CompileGeometry(Rml::Span<const Rml::Vertex> vertices, Rml::Span<const int> indices) override;
  70. void RenderGeometry(Rml::CompiledGeometryHandle handle, Rml::Vector2f translation, Rml::TextureHandle texture) override;
  71. void ReleaseGeometry(Rml::CompiledGeometryHandle handle) override;
  72. Rml::TextureHandle LoadTexture(Rml::Vector2i& texture_dimensions, const Rml::String& source) override;
  73. Rml::TextureHandle GenerateTexture(Rml::Span<const Rml::byte> source_data, Rml::Vector2i source_dimensions) override;
  74. void ReleaseTexture(Rml::TextureHandle texture_handle) override;
  75. void EnableScissorRegion(bool enable) override;
  76. void SetScissorRegion(Rml::Rectanglei region) override;
  77. void EnableClipMask(bool enable) override;
  78. void RenderToClipMask(Rml::ClipMaskOperation mask_operation, Rml::CompiledGeometryHandle geometry, Rml::Vector2f translation) override;
  79. void SetTransform(const Rml::Matrix4f* transform) override;
  80. Rml::CompiledFilterHandle CompileFilter(const Rml::String& name, const Rml::Dictionary& parameters) override;
  81. void ReleaseFilter(Rml::CompiledFilterHandle filter) override;
  82. Rml::CompiledShaderHandle CompileShader(const Rml::String& name, const Rml::Dictionary& parameters) override;
  83. void RenderShader(Rml::CompiledShaderHandle shader, Rml::CompiledGeometryHandle geometry, Rml::Vector2f translation,
  84. Rml::TextureHandle texture) override;
  85. void ReleaseShader(Rml::CompiledShaderHandle shader) override;
  86. const Counters& GetCounters() const { return counters; }
  87. void ResetCounters();
  88. const Counters& GetCountersFromPreviousReset() const { return counters_from_previous_reset; }
  89. void ExpectCompileGeometry(Rml::Vector<Rml::Mesh> meshes);
  90. void Reset();
  91. private:
  92. void VerifyMeshes();
  93. Counters counters = {};
  94. Counters counters_from_previous_reset = {};
  95. Rml::Vector<Rml::Mesh> meshes;
  96. bool meshes_set = false;
  97. };
  98. #endif