BackgroundBorder.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 <RmlUi/Core/Context.h>
  30. #include <RmlUi/Core/Element.h>
  31. #include <RmlUi/Core/ElementDocument.h>
  32. #include <RmlUi/Core/Types.h>
  33. #include <doctest.h>
  34. #include <nanobench.h>
  35. using namespace ankerl;
  36. using namespace Rml;
  37. static String document_rml = R"(
  38. <rml>
  39. <head>
  40. <link type="text/rcss" href="/../Tests/Data/style.rcss"/>
  41. <style>
  42. div > div {
  43. margin: 50px auto;
  44. width: 300px;
  45. height: 200px;
  46. background: #c3c3c3;
  47. border-color: #55f #f57 #55f #afa;
  48. }
  49. #no-radius > div {
  50. border-width: 8px 10px;
  51. }
  52. #small-radius > div {
  53. border-width: 40px 20px;
  54. border-radius: 5px;
  55. }
  56. #large-radius > div {
  57. border-width: 10px 5px 25px 20px;
  58. border-radius: 80px 30px;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <div id="no-radius">
  64. <div/><div/><div/><div/><div/><div/><div/><div/><div/><div/>
  65. </div>
  66. <div id="small-radius">
  67. <div/><div/><div/><div/><div/><div/><div/><div/><div/><div/>
  68. </div>
  69. <div id="large-radius">
  70. <div/><div/><div/><div/><div/><div/><div/><div/><div/><div/>
  71. </div>
  72. </body>
  73. </rml>
  74. )";
  75. TEST_CASE("backgrounds_and_borders")
  76. {
  77. Context* context = TestsShell::GetContext();
  78. REQUIRE(context);
  79. ElementDocument* document = context->LoadDocumentFromMemory(document_rml);
  80. REQUIRE(document);
  81. document->Show();
  82. const String msg = TestsShell::GetRenderStats();
  83. MESSAGE(msg);
  84. nanobench::Bench bench;
  85. bench.title("Backgrounds and borders");
  86. bench.relative(true);
  87. bench.minEpochIterations(100);
  88. bench.warmup(50);
  89. TestsShell::RenderLoop();
  90. bench.run("Reference (update + render)", [&] {
  91. context->Update();
  92. context->Render();
  93. });
  94. {
  95. ElementList elements;
  96. document->QuerySelectorAll(elements, "div > div");
  97. REQUIRE(!elements.empty());
  98. bench.run("Background all", [&] {
  99. // Force regeneration of backgrounds without changing layout
  100. for (auto& element : elements)
  101. element->SetProperty(Rml::PropertyId::BackgroundColor, Rml::Property(Colourb(), Property::COLOUR));
  102. context->Update();
  103. context->Render();
  104. });
  105. bench.run("Border all", [&] {
  106. // Force regeneration of borders without changing layout
  107. for (auto& element : elements)
  108. element->SetProperty(Rml::PropertyId::BorderLeftColor, Rml::Property(Colourb(), Property::COLOUR));
  109. context->Update();
  110. context->Render();
  111. });
  112. }
  113. for (const String id : {"no-radius", "small-radius", "large-radius"})
  114. {
  115. ElementList elements;
  116. document->QuerySelectorAll(elements, "#" + id + " > div");
  117. REQUIRE(!elements.empty());
  118. bench.run("Border " + id, [&] {
  119. for (auto& element : elements)
  120. element->SetProperty(Rml::PropertyId::BorderLeftColor, Rml::Property(Colourb(), Property::COLOUR));
  121. context->Update();
  122. context->Render();
  123. });
  124. }
  125. document->Close();
  126. }