blob: f641537e0f3b23bb7e988856c43da043a22c6bf6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/demo/demo_window.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/ozone/demo/renderer.h"
#include "ui/ozone/demo/renderer_factory.h"
#include "ui/ozone/demo/window_manager.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/platform_window/platform_window.h"
namespace ui {
DemoWindow::DemoWindow(WindowManager* window_manager,
RendererFactory* renderer_factory,
const gfx::Rect& bounds)
: window_manager_(window_manager),
renderer_factory_(renderer_factory),
weak_ptr_factory_(this) {
platform_window_ =
OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds);
platform_window_->Show();
}
DemoWindow::~DemoWindow() {}
gfx::AcceleratedWidget DemoWindow::GetAcceleratedWidget() {
// TODO(spang): We should start rendering asynchronously.
DCHECK_NE(widget_, gfx::kNullAcceleratedWidget)
<< "Widget not available synchronously";
return widget_;
}
gfx::Size DemoWindow::GetSize() {
return platform_window_->GetBounds().size();
}
void DemoWindow::Start() {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&DemoWindow::StartOnGpu, weak_ptr_factory_.GetWeakPtr()));
}
void DemoWindow::Quit() {
window_manager_->Quit();
}
void DemoWindow::OnBoundsChanged(const gfx::Rect& new_bounds) {}
void DemoWindow::OnDamageRect(const gfx::Rect& damaged_region) {}
void DemoWindow::DispatchEvent(Event* event) {
if (event->IsKeyEvent() && event->AsKeyEvent()->code() == DomCode::US_Q)
Quit();
}
void DemoWindow::OnCloseRequest() {
Quit();
}
void DemoWindow::OnClosed() {}
void DemoWindow::OnWindowStateChanged(PlatformWindowState new_state) {}
void DemoWindow::OnLostCapture() {}
void DemoWindow::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
float device_pixel_ratio) {
DCHECK_NE(widget, gfx::kNullAcceleratedWidget);
widget_ = widget;
}
void DemoWindow::OnAcceleratedWidgetDestroyed() {
NOTREACHED();
}
void DemoWindow::OnActivationChanged(bool active) {}
void DemoWindow::StartOnGpu() {
renderer_ =
renderer_factory_->CreateRenderer(GetAcceleratedWidget(), GetSize());
if (!renderer_->Initialize())
LOG(ERROR) << "Failed to initialize renderer.";
}
} // namespace ui
|