Upstream version 11.39.266.0
[platform/framework/web/crosswalk.git] / src / mojo / examples / surfaces_app / child_impl.h
1 // Copyright 2014 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 #ifndef MOJO_EXAMPLES_SURFACES_APP_CHILD_IMPL_H_
6 #define MOJO_EXAMPLES_SURFACES_APP_CHILD_IMPL_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "cc/surfaces/surface_id.h"
11 #include "cc/surfaces/surface_id_allocator.h"
12 #include "mojo/examples/surfaces_app/child.mojom.h"
13 #include "mojo/public/cpp/bindings/string.h"
14 #include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h"
15 #include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h"
16 #include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h"
17 #include "third_party/skia/include/core/SkColor.h"
18 #include "ui/gfx/size.h"
19
20 namespace cc {
21 class CompositorFrame;
22 }
23
24 namespace mojo {
25
26 class ApplicationConnection;
27
28 namespace surfaces {
29 class Surface;
30 }
31
32 namespace examples {
33
34 // Simple example of a child app using surfaces.
35 class ChildImpl : public InterfaceImpl<Child>, public SurfaceClient {
36  public:
37   class Context {
38    public:
39     virtual ApplicationConnection* ShellConnection(
40         const mojo::String& application_url) = 0;
41   };
42   explicit ChildImpl(ApplicationConnection* surfaces_service_connection);
43   virtual ~ChildImpl();
44
45   // SurfaceClient implementation
46   virtual void ReturnResources(
47       Array<ReturnedResourcePtr> resources) OVERRIDE;
48
49  private:
50   // Child implementation.
51   virtual void ProduceFrame(
52       ColorPtr color,
53       SizePtr size,
54       const mojo::Callback<void(SurfaceIdPtr id)>& callback) OVERRIDE;
55
56   void SurfaceConnectionCreated(SurfacePtr surface, uint32_t id_namespace);
57   void Draw();
58
59   SkColor color_;
60   gfx::Size size_;
61   scoped_ptr<cc::SurfaceIdAllocator> allocator_;
62   SurfacesServicePtr surfaces_service_;
63   SurfacePtr surface_;
64   cc::SurfaceId id_;
65   mojo::Callback<void(SurfaceIdPtr id)> produce_callback_;
66   base::WeakPtrFactory<ChildImpl> weak_factory_;
67
68   DISALLOW_COPY_AND_ASSIGN(ChildImpl);
69 };
70
71 }  // namespace examples
72 }  // namespace mojo
73
74 #endif  // MOJO_EXAMPLES_SURFACES_APP_CHILD_IMPL_H_