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/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "cc/trees/layer_tree_host_client.h"
13 #include "content/common/content_export.h"
14 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
15 #include "content/public/browser/android/compositor.h"
20 class InputHandlerClient
;
26 class GraphicsContext
;
28 // -----------------------------------------------------------------------------
29 // Browser-side compositor that manages a tree of content and UI layers.
30 // -----------------------------------------------------------------------------
31 class CONTENT_EXPORT CompositorImpl
33 public cc::LayerTreeHostClient
,
34 public WebGraphicsContext3DSwapBuffersClient
{
36 explicit CompositorImpl(Compositor::Client
* client
);
37 virtual ~CompositorImpl();
39 static bool IsInitialized();
40 static bool IsThreadingEnabled();
42 // Returns true if initialized with DIRECT_CONTEXT_ON_DRAW_THREAD.
43 static bool UsesDirectGL();
45 // Returns the Java Surface object for a given view surface id.
46 static jobject
GetSurface(int surface_id
);
48 // Compositor implementation.
49 virtual void SetRootLayer(scoped_refptr
<cc::Layer
> root
) OVERRIDE
;
50 virtual void SetWindowSurface(ANativeWindow
* window
) OVERRIDE
;
51 virtual void SetSurface(jobject surface
) OVERRIDE
;
52 virtual void SetVisible(bool visible
) OVERRIDE
;
53 virtual void setDeviceScaleFactor(float factor
) OVERRIDE
;
54 virtual void SetWindowBounds(const gfx::Size
& size
) OVERRIDE
;
55 virtual void SetHasTransparentBackground(bool flag
) OVERRIDE
;
56 virtual bool CompositeAndReadback(
57 void *pixels
, const gfx::Rect
& rect
) OVERRIDE
;
58 virtual void SetNeedsRedraw() OVERRIDE
;
59 virtual void Composite() OVERRIDE
;
60 virtual WebKit::WebGLId
GenerateTexture(gfx::JavaBitmap
& bitmap
) OVERRIDE
;
61 virtual WebKit::WebGLId
GenerateCompressedTexture(
62 gfx::Size
& size
, int data_size
, void* data
) OVERRIDE
;
63 virtual void DeleteTexture(WebKit::WebGLId texture_id
) OVERRIDE
;
64 virtual bool CopyTextureToBitmap(WebKit::WebGLId texture_id
,
65 gfx::JavaBitmap
& bitmap
) OVERRIDE
;
66 virtual bool CopyTextureToBitmap(WebKit::WebGLId texture_id
,
67 const gfx::Rect
& sub_rect
,
68 gfx::JavaBitmap
& bitmap
) OVERRIDE
;
70 // LayerTreeHostClient implementation.
71 virtual void WillBeginFrame() OVERRIDE
{}
72 virtual void DidBeginFrame() OVERRIDE
{}
73 virtual void Animate(double frame_begin_time
) OVERRIDE
{}
74 virtual void Layout() OVERRIDE
{}
75 virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta
,
76 float page_scale
) OVERRIDE
{}
77 virtual scoped_ptr
<cc::OutputSurface
> CreateOutputSurface() OVERRIDE
;
78 virtual void DidInitializeOutputSurface(bool success
) OVERRIDE
{}
79 virtual void WillCommit() OVERRIDE
{}
80 virtual void DidCommit() OVERRIDE
{}
81 virtual void DidCommitAndDrawFrame() OVERRIDE
{}
82 virtual void DidCompleteSwapBuffers() OVERRIDE
;
83 virtual void ScheduleComposite() OVERRIDE
;
84 virtual scoped_refptr
<cc::ContextProvider
>
85 OffscreenContextProviderForMainThread() OVERRIDE
;
86 virtual scoped_refptr
<cc::ContextProvider
>
87 OffscreenContextProviderForCompositorThread() OVERRIDE
;
89 // WebGraphicsContext3DSwapBuffersClient implementation.
90 virtual void OnViewContextSwapBuffersPosted() OVERRIDE
;
91 virtual void OnViewContextSwapBuffersComplete() OVERRIDE
;
92 virtual void OnViewContextSwapBuffersAborted() OVERRIDE
;
95 WebKit::WebGLId
BuildBasicTexture();
96 WebKit::WGC3Denum
GetGLFormatForBitmap(gfx::JavaBitmap
& bitmap
);
97 WebKit::WGC3Denum
GetGLTypeForBitmap(gfx::JavaBitmap
& bitmap
);
99 scoped_refptr
<cc::Layer
> root_layer_
;
100 scoped_ptr
<cc::LayerTreeHost
> host_
;
103 bool has_transparent_background_
;
105 ANativeWindow
* window_
;
108 Compositor::Client
* client_
;
109 base::WeakPtrFactory
<CompositorImpl
> weak_factory_
;
111 scoped_refptr
<cc::ContextProvider
> null_offscreen_context_provider_
;
113 DISALLOW_COPY_AND_ASSIGN(CompositorImpl
);
116 } // namespace content
118 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_