Home | History | Annotate | Download | only in compositor_app
      1 // Copyright 2013 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 
      5 #include <stdio.h>
      6 #include <string>
      7 
      8 #include "base/macros.h"
      9 #include "mojo/examples/compositor_app/compositor_host.h"
     10 #include "mojo/public/cpp/application/application.h"
     11 #include "mojo/public/cpp/gles2/gles2.h"
     12 #include "mojo/public/cpp/system/core.h"
     13 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
     14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
     15 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h"
     16 #include "ui/gfx/rect.h"
     17 
     18 namespace mojo {
     19 namespace examples {
     20 
     21 class SampleApp : public Application, public NativeViewportClient {
     22  public:
     23   SampleApp() {}
     24   virtual ~SampleApp() {}
     25 
     26   virtual void Initialize() OVERRIDE {
     27     ConnectTo("mojo:mojo_native_viewport_service", &viewport_);
     28     viewport_.set_client(this);
     29 
     30     viewport_->Create(Rect::From(gfx::Rect(10, 10, 800, 600)));
     31     viewport_->Show();
     32 
     33     MessagePipe pipe;
     34     viewport_->CreateGLES2Context(
     35         MakeRequest<CommandBuffer>(pipe.handle0.Pass()));
     36     host_.reset(new CompositorHost(pipe.handle1.Pass()));
     37   }
     38 
     39   virtual void OnCreated() OVERRIDE {
     40   }
     41 
     42   virtual void OnDestroyed() OVERRIDE {
     43     base::MessageLoop::current()->Quit();
     44   }
     45 
     46   virtual void OnBoundsChanged(RectPtr bounds) OVERRIDE {
     47     host_->SetSize(gfx::Size(bounds->width, bounds->height));
     48   }
     49 
     50   virtual void OnEvent(EventPtr event,
     51                        const mojo::Callback<void()>& callback) OVERRIDE {
     52     callback.Run();
     53   }
     54 
     55  private:
     56   mojo::GLES2Initializer gles2;
     57   NativeViewportPtr viewport_;
     58   scoped_ptr<CompositorHost> host_;
     59   DISALLOW_COPY_AND_ASSIGN(SampleApp);
     60 };
     61 
     62 }  // namespace examples
     63 
     64 // static
     65 Application* Application::Create() {
     66   return new examples::SampleApp();
     67 }
     68 
     69 }  // namespace mojo
     70