CanvasState.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  3. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/HTML/Canvas/CanvasState.h>
  8. namespace Web::HTML {
  9. // https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-save
  10. void CanvasState::save()
  11. {
  12. // The save() method steps are to push a copy of the current drawing state onto the drawing state stack.
  13. m_drawing_state_stack.append(m_drawing_state);
  14. }
  15. // https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-restore
  16. void CanvasState::restore()
  17. {
  18. // The restore() method steps are to pop the top entry in the drawing state stack, and reset the drawing state it describes. If there is no saved state, then the method must do nothing.
  19. if (m_drawing_state_stack.is_empty())
  20. return;
  21. m_drawing_state = m_drawing_state_stack.take_last();
  22. }
  23. // https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-reset
  24. void CanvasState::reset()
  25. {
  26. // The reset() method steps are to reset the rendering context to its default state.
  27. reset_to_default_state();
  28. }
  29. // https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-iscontextlost
  30. bool CanvasState::is_context_lost()
  31. {
  32. // The isContextLost() method steps are to return this's context lost.
  33. return m_context_lost;
  34. }
  35. }