Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / renderer_host / compositor_impl_android.h
blobeafafc3374fd0a9f6cdc825ed97ba25045a0150d
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"
17 struct ANativeWindow;
19 namespace cc {
20 class InputHandlerClient;
21 class Layer;
22 class LayerTreeHost;
25 namespace content {
26 class GraphicsContext;
28 // -----------------------------------------------------------------------------
29 // Browser-side compositor that manages a tree of content and UI layers.
30 // -----------------------------------------------------------------------------
31 class CONTENT_EXPORT CompositorImpl
32 : public Compositor,
33 public cc::LayerTreeHostClient,
34 public WebGraphicsContext3DSwapBuffersClient {
35 public:
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;
94 private:
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_;
102 gfx::Size size_;
103 bool has_transparent_background_;
105 ANativeWindow* window_;
106 int surface_id_;
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_