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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/containers/scoped_ptr_hash_map.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "cc/resources/ui_resource_client.h"
13 #include "cc/trees/layer_tree_host_client.h"
14 #include "cc/trees/layer_tree_host_single_thread_client.h"
15 #include "content/browser/renderer_host/image_transport_factory_android.h"
16 #include "content/common/content_export.h"
17 #include "content/public/browser/android/compositor.h"
18 #include "third_party/khronos/GLES2/gl2.h"
19 #include "ui/base/android/window_android_compositor.h"
25 class InputHandlerClient
;
31 class CompositorClient
;
32 class GraphicsContext
;
34 // -----------------------------------------------------------------------------
35 // Browser-side compositor that manages a tree of content and UI layers.
36 // -----------------------------------------------------------------------------
37 class CONTENT_EXPORT CompositorImpl
39 public cc::LayerTreeHostClient
,
40 public cc::LayerTreeHostSingleThreadClient
,
41 public ImageTransportFactoryAndroidObserver
,
42 public ui::WindowAndroidCompositor
{
44 CompositorImpl(CompositorClient
* client
, gfx::NativeWindow root_window
);
45 virtual ~CompositorImpl();
47 static bool IsInitialized();
49 // Creates a surface texture and returns a surface texture id. Returns -1 on
51 static int CreateSurfaceTexture(int child_process_id
);
53 // Destroy all surface textures associated with |child_process_id|.
54 static void DestroyAllSurfaceTextures(int child_process_id
);
56 // Compositor implementation.
57 virtual void SetRootLayer(scoped_refptr
<cc::Layer
> root
) OVERRIDE
;
58 virtual void SetWindowSurface(ANativeWindow
* window
) OVERRIDE
;
59 virtual void SetSurface(jobject surface
) OVERRIDE
;
60 virtual void SetVisible(bool visible
) OVERRIDE
;
61 virtual void setDeviceScaleFactor(float factor
) OVERRIDE
;
62 virtual void SetWindowBounds(const gfx::Size
& size
) OVERRIDE
;
63 virtual void SetHasTransparentBackground(bool flag
) OVERRIDE
;
64 virtual bool CompositeAndReadback(
65 void *pixels
, const gfx::Rect
& rect
) OVERRIDE
;
66 virtual void Composite() OVERRIDE
;
67 virtual cc::UIResourceId
GenerateUIResource(const SkBitmap
& bitmap
,
68 bool is_transient
) OVERRIDE
;
69 virtual cc::UIResourceId
GenerateCompressedUIResource(const gfx::Size
& size
,
73 virtual void DeleteUIResource(cc::UIResourceId resource_id
) OVERRIDE
;
75 // LayerTreeHostClient implementation.
76 virtual void WillBeginMainFrame(int frame_id
) OVERRIDE
{}
77 virtual void DidBeginMainFrame() OVERRIDE
{}
78 virtual void Animate(base::TimeTicks frame_begin_time
) OVERRIDE
{}
79 virtual void Layout() OVERRIDE
{}
80 virtual void ApplyScrollAndScale(const gfx::Vector2d
& scroll_delta
,
81 float page_scale
) OVERRIDE
{}
82 virtual scoped_ptr
<cc::OutputSurface
> CreateOutputSurface(bool fallback
)
84 virtual void DidInitializeOutputSurface() OVERRIDE
{}
85 virtual void WillCommit() OVERRIDE
{}
86 virtual void DidCommit() OVERRIDE
;
87 virtual void DidCommitAndDrawFrame() OVERRIDE
{}
88 virtual void DidCompleteSwapBuffers() OVERRIDE
;
90 // LayerTreeHostSingleThreadClient implementation.
91 virtual void ScheduleComposite() OVERRIDE
;
92 virtual void ScheduleAnimation() OVERRIDE
;
93 virtual void DidPostSwapBuffers() OVERRIDE
;
94 virtual void DidAbortSwapBuffers() OVERRIDE
;
96 // ImageTransportFactoryAndroidObserver implementation.
97 virtual void OnLostResources() OVERRIDE
;
99 // WindowAndroidCompositor implementation.
100 virtual void AttachLayerForReadback(scoped_refptr
<cc::Layer
> layer
) OVERRIDE
;
103 cc::UIResourceId
GenerateUIResourceFromUIResourceBitmap(
104 const cc::UIResourceBitmap
& bitmap
,
107 scoped_refptr
<cc::Layer
> root_layer_
;
108 scoped_ptr
<cc::LayerTreeHost
> host_
;
111 bool has_transparent_background_
;
112 float device_scale_factor_
;
114 ANativeWindow
* window_
;
117 CompositorClient
* client_
;
119 typedef base::ScopedPtrHashMap
<cc::UIResourceId
, cc::UIResourceClient
>
121 UIResourceMap ui_resource_map_
;
123 gfx::NativeWindow root_window_
;
125 DISALLOW_COPY_AND_ASSIGN(CompositorImpl
);
128 } // namespace content
130 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_