BackgroundBorder.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 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. #include "../Common/TestsShell.h"
  29. #include "../Common/TestsInterface.h"
  30. #include <RmlUi/Core/Context.h>
  31. #include <RmlUi/Core/Element.h>
  32. #include <RmlUi/Core/ElementDocument.h>
  33. #include <RmlUi/Core/Types.h>
  34. #include <doctest.h>
  35. #include <nanobench.h>
  36. using namespace ankerl;
  37. using namespace Rml;
  38. static String document_rml = R"(
  39. <rml>
  40. <head>
  41. <link type="text/rcss" href="/../Tests/Data/style.rcss"/>
  42. <style>
  43. div > div {
  44. margin: 50px auto;
  45. width: 300px;
  46. height: 200px;
  47. background: #c3c3c3;
  48. border-color: #55f #f57 #55f #afa;
  49. }
  50. #no-radius > div {
  51. border-width: 8px 10px;
  52. }
  53. #small-radius > div {
  54. border-width: 40px 20px;
  55. border-radius: 5px;
  56. }
  57. #large-radius > div {
  58. border-width: 10px 5px 25px 20px;
  59. border-radius: 80px 30px;
  60. }
  61. </style>
  62. </head>
  63. <body>
  64. <div id="no-radius">
  65. <div/><div/><div/><div/><div/><div/><div/><div/><div/><div/>
  66. </div>
  67. <div id="small-radius">
  68. <div/><div/><div/><div/><div/><div/><div/><div/><div/><div/>
  69. </div>
  70. <div id="large-radius">
  71. <div/><div/><div/><div/><div/><div/><div/><div/><div/><div/>
  72. </div>
  73. </body>
  74. </rml>
  75. )";
  76. TEST_CASE("Backgrounds and borders")
  77. {
  78. TestsRenderInterface render_interface;
  79. Context* context = TestsShell::CreateContext("background_dummy", &render_interface);
  80. REQUIRE(context);
  81. ElementDocument* document = context->LoadDocumentFromMemory(document_rml);
  82. REQUIRE(document);
  83. document->Show();
  84. render_interface.ResetCounters();
  85. context->Update();
  86. context->Render();
  87. auto& counters = render_interface.GetCounters();
  88. const String msg = CreateString(512,
  89. "\nStats for Context::Render(): \n"
  90. "Render calls: %zu\n"
  91. "Scissor enable: %zu\n"
  92. "Scissor set: %zu\n"
  93. "Texture load: %zu\n"
  94. "Texture generate: %zu\n"
  95. "Texture release: %zu\n"
  96. "Transform set: %zu\n",
  97. counters.render_calls,
  98. counters.enable_scissor,
  99. counters.set_scissor,
  100. counters.load_texture,
  101. counters.generate_texture,
  102. counters.release_texture,
  103. counters.set_transform
  104. );
  105. MESSAGE(msg);
  106. nanobench::Bench bench;
  107. bench.title("Backgrounds and borders");
  108. bench.relative(true);
  109. bench.minEpochIterations(100);
  110. bench.warmup(50);
  111. bench.run("Reference (update + render)", [&] {
  112. context->Update();
  113. context->Render();
  114. });
  115. {
  116. ElementList elements;
  117. document->QuerySelectorAll(elements, "div > div");
  118. REQUIRE(!elements.empty());
  119. bench.run("Background all", [&] {
  120. // Force regeneration of backgrounds without changing layout
  121. for (auto& element : elements)
  122. element->SetProperty(Rml::PropertyId::BackgroundColor, Rml::Property(Colourb(), Property::COLOUR));
  123. context->Update();
  124. context->Render();
  125. });
  126. bench.run("Border all", [&] {
  127. // Force regeneration of borders without changing layout
  128. for (auto& element : elements)
  129. element->SetProperty(Rml::PropertyId::BorderLeftColor, Rml::Property(Colourb(), Property::COLOUR));
  130. context->Update();
  131. context->Render();
  132. });
  133. }
  134. for (const String id : {"no-radius", "small-radius", "large-radius"})
  135. {
  136. ElementList elements;
  137. document->QuerySelectorAll(elements, "#" + id + " > div");
  138. REQUIRE(!elements.empty());
  139. bench.run("Border " + id, [&] {
  140. for (auto& element : elements)
  141. element->SetProperty(Rml::PropertyId::BorderLeftColor, Rml::Property(Colourb(), Property::COLOUR));
  142. context->Update();
  143. context->Render();
  144. });
  145. }
  146. document->Close();
  147. TestsShell::RemoveContext(context);
  148. }