blob: b6566fe4ee496ac8750a74becd3147b9c7d007ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_COMPOSITOR_COMPOSITOR_H_
#define UI_GFX_COMPOSITOR_COMPOSITOR_H_
#pragma once
#include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
#include "base/observer_list.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebLayer.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebLayerTreeView.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebLayerTreeViewClient.h"
#include "ui/gfx/compositor/compositor_export.h"
#include "ui/gfx/transform.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/size.h"
class SkBitmap;
class SkCanvas;
namespace gfx {
class GLContext;
class GLSurface;
class GLShareGroup;
class Point;
class Rect;
class ScopedMakeCurrent;
}
namespace ui {
class CompositorObserver;
class Layer;
class COMPOSITOR_EXPORT SharedResources {
public:
static SharedResources* GetInstance();
// Creates an instance of ScopedMakeCurrent.
// Note: Caller is responsible for managing lifetime of returned pointer.
gfx::ScopedMakeCurrent* GetScopedMakeCurrent();
void* GetDisplay();
gfx::GLShareGroup* GetShareGroup();
private:
friend struct DefaultSingletonTraits<SharedResources>;
SharedResources();
~SharedResources();
bool Initialize();
void Destroy();
bool initialized_;
scoped_refptr<gfx::GLContext> context_;
scoped_refptr<gfx::GLSurface> surface_;
DISALLOW_COPY_AND_ASSIGN(SharedResources);
};
// Texture provide an abstraction over the external texture that can be passed
// to a layer.
class COMPOSITOR_EXPORT Texture : public base::RefCounted<Texture> {
public:
Texture();
virtual ~Texture();
unsigned int texture_id() const { return texture_id_; }
bool flipped() const { return flipped_; }
gfx::Size size() const { return size_; }
protected:
unsigned int texture_id_;
bool flipped_;
gfx::Size size_;
private:
DISALLOW_COPY_AND_ASSIGN(Texture);
};
// An interface to allow the compositor to communicate with its owner.
class COMPOSITOR_EXPORT CompositorDelegate {
public:
// Requests the owner to schedule a redraw of the layer tree.
virtual void ScheduleDraw() = 0;
protected:
virtual ~CompositorDelegate() {}
};
// Compositor object to take care of GPU painting.
// A Browser compositor object is responsible for generating the final
// displayable form of pixels comprising a single widget's contents. It draws an
// appropriately transformed texture for each transformed view in the widget's
// view hierarchy.
class COMPOSITOR_EXPORT Compositor
: public base::RefCounted<Compositor>,
NON_EXPORTED_BASE(public WebKit::WebLayerTreeViewClient) {
public:
Compositor(CompositorDelegate* delegate,
gfx::AcceleratedWidget widget,
const gfx::Size& size);
virtual ~Compositor();
static void Initialize(bool useThread);
static void Terminate();
// Schedules a redraw of the layer tree associated with this compositor.
void ScheduleDraw();
// Sets the root of the layer tree drawn by this Compositor. The root layer
// must have no parent. The compositor's root layer is reset if the root layer
// is destroyed. NULL can be passed to reset the root layer, in which case the
// compositor will stop drawing anything.
// The Compositor does not own the root layer.
const Layer* root_layer() const { return root_layer_; }
Layer* root_layer() { return root_layer_; }
void SetRootLayer(Layer* root_layer);
// Draws the scene created by the layer tree and any visual effects. If
// |force_clear| is true, this will cause the compositor to clear before
// compositing.
void Draw(bool force_clear);
// Reads the region |bounds| of the contents of the last rendered frame
// into the given bitmap.
// Returns false if the pixels could not be read.
bool ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds);
// Notifies the compositor that the size of the widget that it is
// drawing to has changed.
void WidgetSizeChanged(const gfx::Size& size);
// Returns the size of the widget that is being drawn to.
const gfx::Size& size() { return size_; }
// Compositor does not own observers. It is the responsibility of the
// observer to remove itself when it is done observing.
void AddObserver(CompositorObserver* observer);
void RemoveObserver(CompositorObserver* observer);
bool HasObserver(CompositorObserver* observer);
// WebLayerTreeViewClient implementation.
virtual void updateAnimations(double frameBeginTime);
virtual void layout();
virtual void applyScrollAndScale(const WebKit::WebSize& scrollDelta,
float scaleFactor);
virtual WebKit::WebGraphicsContext3D* createContext3D();
virtual void didCompleteSwapBuffers();
virtual void didRebindGraphicsContext(bool success);
virtual void scheduleComposite();
private:
// When reading back pixel data we often get RGBA rather than BGRA pixels and
// and the image often needs to be flipped vertically.
static void SwizzleRGBAToBGRAAndFlip(unsigned char* pixels,
const gfx::Size& image_size);
// Notifies the compositor that compositing is complete.
void NotifyEnd();
CompositorDelegate* delegate_;
gfx::Size size_;
// The root of the Layer tree drawn by this compositor.
Layer* root_layer_;
ObserverList<CompositorObserver> observer_list_;
gfx::AcceleratedWidget widget_;
WebKit::WebLayer root_web_layer_;
WebKit::WebLayerTreeView host_;
friend class base::RefCounted<Compositor>;
};
} // namespace ui
#endif // UI_GFX_COMPOSITOR_COMPOSITOR_H_
|