Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Unified Diff: examples/sample_app/sample_app.cc

Issue 878933005: Remove NativeViewportClient (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: examples/sample_app/sample_app.cc
diff --git a/examples/sample_app/sample_app.cc b/examples/sample_app/sample_app.cc
index c0ff70ef78bfcec2d7066b6f4694b396c403ccb2..17fee2e377afd67551beca68ef35cee39eca93f1 100644
--- a/examples/sample_app/sample_app.cc
+++ b/examples/sample_app/sample_app.cc
@@ -21,12 +21,11 @@
namespace examples {
-class SampleApp
- : public mojo::ApplicationDelegate,
- public mojo::NativeViewportClient,
- public mojo::InterfaceImpl<mojo::NativeViewportEventDispatcher> {
+class SampleApp : public mojo::ApplicationDelegate,
+ public mojo::NativeViewportEventDispatcher,
+ public mojo::ErrorHandler {
public:
- SampleApp() : weak_factory_(this) {}
+ SampleApp() : dispatcher_binding_(this), weak_factory_(this) {}
~SampleApp() override {
// TODO(darin): Fix shutdown so we don't need to leak this.
@@ -35,7 +34,7 @@ class SampleApp
void Initialize(mojo::ApplicationImpl* app) override {
app->ConnectToService("mojo:native_viewport_service", &viewport_);
- viewport_.set_client(this);
+ viewport_.set_error_handler(this);
SetEventDispatcher();
@@ -51,12 +50,12 @@ class SampleApp
viewport_->Show();
}
- void OnDestroyed() override { mojo::RunLoop::current()->Quit(); }
-
- void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override {
+ void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) {
assert(metrics);
if (gles2_client_)
gles2_client_->SetSize(*metrics->size);
+ viewport_->RequestMetrics(
+ base::Bind(&SampleApp::OnMetricsChanged, weak_factory_.GetWeakPtr()));
sky 2015/01/28 19:26:41 As this class owns the viewport_ it seems like it
}
void OnEvent(mojo::EventPtr event,
@@ -69,27 +68,31 @@ class SampleApp
private:
void SetEventDispatcher() {
- mojo::NativeViewportEventDispatcherPtr proxy;
- mojo::WeakBindToProxy(this, &proxy);
- viewport_->SetEventDispatcher(proxy.Pass());
+ mojo::NativeViewportEventDispatcherPtr ptr;
+ dispatcher_binding_.Bind(GetProxy(&ptr));
+ viewport_->SetEventDispatcher(ptr.Pass());
}
- void OnCreatedNativeViewport(uint64_t native_viewport_id) {
- mojo::SizePtr size = mojo::Size::New();
- size->width = 800;
- size->height = 600;
+ void OnCreatedNativeViewport(uint64_t native_viewport_id,
+ mojo::ViewportMetricsPtr metrics) {
mojo::ViewportParameterListenerPtr listener;
mojo::CommandBufferPtr command_buffer;
// TODO(jamesr): Output to a surface instead.
- gpu_service_->CreateOnscreenGLES2Context(native_viewport_id, size.Pass(),
- GetProxy(&command_buffer),
- listener.Pass());
+ gpu_service_->CreateOnscreenGLES2Context(
+ native_viewport_id, metrics->size.Clone(), GetProxy(&command_buffer),
+ listener.Pass());
gles2_client_.reset(new GLES2ClientImpl(command_buffer.Pass()));
+ viewport_->RequestMetrics(
+ base::Bind(&SampleApp::OnMetricsChanged, weak_factory_.GetWeakPtr()));
}
+ // ErrorHandler implementation.
+ void OnConnectionError() override { mojo::RunLoop::current()->Quit(); }
+
scoped_ptr<GLES2ClientImpl> gles2_client_;
mojo::NativeViewportPtr viewport_;
mojo::GpuPtr gpu_service_;
+ mojo::Binding<NativeViewportEventDispatcher> dispatcher_binding_;
base::WeakPtrFactory<SampleApp> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(SampleApp);

Powered by Google App Engine
This is Rietveld 408576698