fake_output_surface.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_VIZ_TEST_FAKE_OUTPUT_SURFACE_H_
  5. #define COMPONENTS_VIZ_TEST_FAKE_OUTPUT_SURFACE_H_
  6. #include <stddef.h>
  7. #include <memory>
  8. #include <utility>
  9. #include "base/callback.h"
  10. #include "base/memory/ptr_util.h"
  11. #include "base/memory/raw_ptr.h"
  12. #include "build/build_config.h"
  13. #include "build/chromeos_buildflags.h"
  14. #include "components/viz/common/frame_sinks/begin_frame_args.h"
  15. #include "components/viz/service/display/output_surface.h"
  16. #include "components/viz/service/display/output_surface_frame.h"
  17. #include "components/viz/service/display/software_output_device.h"
  18. #include "components/viz/test/test_context_provider.h"
  19. #include "ui/gfx/overlay_transform.h"
  20. namespace viz {
  21. class FakeSoftwareOutputSurface : public OutputSurface {
  22. public:
  23. explicit FakeSoftwareOutputSurface(
  24. std::unique_ptr<SoftwareOutputDevice> software_device);
  25. ~FakeSoftwareOutputSurface() override;
  26. OutputSurfaceFrame* last_sent_frame() { return last_sent_frame_.get(); }
  27. size_t num_sent_frames() { return num_sent_frames_; }
  28. // OutputSurface implementation.
  29. void BindToClient(OutputSurfaceClient* client) override;
  30. void EnsureBackbuffer() override {}
  31. void DiscardBackbuffer() override {}
  32. void SetDrawRectangle(const gfx::Rect& rect) override;
  33. void SetEnableDCLayers(bool enabled) override;
  34. void Reshape(const ReshapeParams& params) override;
  35. void SwapBuffers(OutputSurfaceFrame frame) override;
  36. bool IsDisplayedAsOverlayPlane() const override;
  37. void SetUpdateVSyncParametersCallback(
  38. UpdateVSyncParametersCallback callback) override;
  39. void SetDisplayTransformHint(gfx::OverlayTransform transform) override;
  40. gfx::OverlayTransform GetDisplayTransform() override;
  41. // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
  42. // of lacros-chrome is complete.
  43. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
  44. void SetNeedsSwapSizeNotifications(
  45. bool needs_swap_size_notifications) override;
  46. #endif
  47. const gfx::ColorSpace& last_reshape_color_space() {
  48. return last_reshape_color_space_;
  49. }
  50. void set_support_display_transform_hint(bool support) {
  51. support_display_transform_hint_ = support;
  52. }
  53. protected:
  54. raw_ptr<OutputSurfaceClient> client_ = nullptr;
  55. std::unique_ptr<OutputSurfaceFrame> last_sent_frame_;
  56. size_t num_sent_frames_ = 0;
  57. gfx::ColorSpace last_reshape_color_space_;
  58. bool support_display_transform_hint_ = false;
  59. gfx::OverlayTransform display_transform_hint_ = gfx::OVERLAY_TRANSFORM_NONE;
  60. private:
  61. void SwapBuffersAck();
  62. base::WeakPtrFactory<FakeSoftwareOutputSurface> weak_ptr_factory_{this};
  63. };
  64. } // namespace viz
  65. #endif // COMPONENTS_VIZ_TEST_FAKE_OUTPUT_SURFACE_H_