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_PUBLIC_BROWSER_ANDROID_COMPOSITOR_H_
6 #define CONTENT_PUBLIC_BROWSER_ANDROID_COMPOSITOR_H_
8 #include "base/callback.h"
9 #include "cc/resources/ui_resource_bitmap.h"
10 #include "cc/resources/ui_resource_client.h"
11 #include "content/common/content_export.h"
12 #include "ui/gfx/native_widget_types.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/size.h"
27 class CompositorClient;
29 // An interface to the browser-side compositor.
30 class CONTENT_EXPORT Compositor {
32 virtual ~Compositor() {}
34 // Performs the global initialization needed before any compositor
35 // instance can be used. This should be called only once.
36 static void Initialize();
38 // Creates and returns a compositor instance. |root_window| needs to outlive
39 // the compositor as it manages callbacks on the compositor.
40 static Compositor* Create(CompositorClient* client,
41 gfx::NativeWindow root_window);
43 // Attaches the layer tree.
44 virtual void SetRootLayer(scoped_refptr<cc::Layer> root) = 0;
46 // Set the scale factor from DIP to pixel.
47 virtual void setDeviceScaleFactor(float factor) = 0;
49 // Set the output surface bounds.
50 virtual void SetWindowBounds(const gfx::Size& size) = 0;
52 // Sets the window visibility. When becoming invisible, resources will get
53 // freed and other calls into the compositor are not allowed until after
54 // having been made visible again.
55 virtual void SetVisible(bool visible) = 0;
57 // Set the output surface handle which the compositor renders into.
58 // DEPRECATED: Use SetSurface() which takes a Java Surface object.
59 virtual void SetWindowSurface(ANativeWindow* window) = 0;
61 // Set the output surface which the compositor renders into.
62 virtual void SetSurface(jobject surface) = 0;
64 // Tells the view tree to assume a transparent background when rendering.
65 virtual void SetHasTransparentBackground(bool flag) = 0;
67 // Attempts to composite and read back the result into the provided buffer.
68 // The buffer must be at least window width * height * 4 (RGBA) bytes large.
69 // The buffer is not modified if false is returned.
70 virtual bool CompositeAndReadback(void *pixels, const gfx::Rect& rect) = 0;
72 // Composite immediately. Used in single-threaded mode.
73 virtual void Composite() = 0;
75 // Generates a UIResource and returns a UIResourceId. |is_transient|
76 // indicates whether or not to release the resource once the bitmap
77 // has been uploaded. May return 0.
78 virtual cc::UIResourceId GenerateUIResource(const SkBitmap& bitmap,
79 bool is_transient) = 0;
81 // Generates an ETC1 compressed UIResource. See above for |is_transient|.
83 virtual cc::UIResourceId GenerateCompressedUIResource(const gfx::Size& size,
85 bool is_transient) = 0;
87 // Deletes a UIResource.
88 virtual void DeleteUIResource(cc::UIResourceId resource_id) = 0;
94 } // namespace content
96 #endif // CONTENT_PUBLIC_BROWSER_ANDROID_COMPOSITOR_H_