test_compositor_host_win.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) 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. #include "ui/compositor/test/test_compositor_host.h"
  5. #include <memory>
  6. #include "base/compiler_specific.h"
  7. #include "base/threading/thread_task_runner_handle.h"
  8. #include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
  9. #include "ui/compositor/compositor.h"
  10. #include "ui/gfx/win/window_impl.h"
  11. #include <windows.h>
  12. namespace ui {
  13. class TestCompositorHostWin : public TestCompositorHost,
  14. public gfx::WindowImpl {
  15. public:
  16. TestCompositorHostWin(const gfx::Rect& bounds,
  17. ui::ContextFactory* context_factory) {
  18. Init(NULL, bounds);
  19. compositor_ = std::make_unique<ui::Compositor>(
  20. context_factory->AllocateFrameSinkId(), context_factory,
  21. base::ThreadTaskRunnerHandle::Get(), false /* enable_pixel_canvas */);
  22. allocator_.GenerateId();
  23. compositor_->SetAcceleratedWidget(hwnd());
  24. compositor_->SetScaleAndSize(1.0f, GetSize(),
  25. allocator_.GetCurrentLocalSurfaceId());
  26. }
  27. TestCompositorHostWin(const TestCompositorHostWin&) = delete;
  28. TestCompositorHostWin& operator=(const TestCompositorHostWin&) = delete;
  29. ~TestCompositorHostWin() override { DestroyWindow(hwnd()); }
  30. // Overridden from TestCompositorHost:
  31. void Show() override {
  32. ShowWindow(hwnd(), SW_SHOWNORMAL);
  33. compositor_->SetVisible(true);
  34. }
  35. ui::Compositor* GetCompositor() override { return compositor_.get(); }
  36. private:
  37. CR_BEGIN_MSG_MAP_EX(TestCompositorHostWin)
  38. CR_MSG_WM_PAINT(OnPaint)
  39. CR_END_MSG_MAP()
  40. void OnPaint(HDC dc) {
  41. compositor_->ScheduleFullRedraw();
  42. ValidateRect(hwnd(), NULL);
  43. }
  44. gfx::Size GetSize() {
  45. RECT r;
  46. GetClientRect(hwnd(), &r);
  47. return gfx::Rect(r).size();
  48. }
  49. std::unique_ptr<ui::Compositor> compositor_;
  50. viz::ParentLocalSurfaceIdAllocator allocator_;
  51. CR_MSG_MAP_CLASS_DECLARATIONS(TestCompositorHostWin)
  52. };
  53. TestCompositorHost* TestCompositorHost::Create(
  54. const gfx::Rect& bounds,
  55. ui::ContextFactory* context_factory) {
  56. return new TestCompositorHostWin(bounds, context_factory);
  57. }
  58. } // namespace ui