blob: f0c370a6a40482e62ba55431698adcd425d2b67f (
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
|
// Copyright (c) 2011 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/observer_list.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 SkCanvas;
namespace gfx {
class Point;
class Rect;
}
namespace ui {
class CompositorObserver;
struct TextureDrawParams {
TextureDrawParams() : transform(), blend(false), compositor_size() {}
// The transform to be applied to the texture.
ui::Transform transform;
// If this is true, then the texture is blended with the pixels behind it.
// Otherwise, the drawn pixels clobber the old pixels.
bool blend;
// The size of the surface that the texture is drawn to.
gfx::Size compositor_size;
// Copy and assignment are allowed.
};
// Textures are created by a Compositor for managing an accelerated view.
// Any time a View with a texture needs to redraw itself it invokes SetCanvas().
// When the view is ready to be drawn Draw() is invoked.
//
// Texture is really a proxy to the gpu. Texture does not itself keep a copy of
// the bitmap.
//
// Views own the Texture.
class COMPOSITOR_EXPORT Texture : public base::RefCounted<Texture> {
public:
// Sets the canvas of this texture. The origin is at |origin|.
// |overall_size| gives the total size of texture.
virtual void SetCanvas(const SkCanvas& canvas,
const gfx::Point& origin,
const gfx::Size& overall_size) = 0;
// Draws the portion of the texture contained within clip_bounds
virtual void Draw(const ui::TextureDrawParams& params,
const gfx::Rect& clip_bounds_in_texture) = 0;
protected:
virtual ~Texture() {}
private:
friend class base::RefCounted<Texture>;
};
// An interface to allow the compositor to communicate with its owner.
class COMPOSITOR_EXPORT CompositorDelegate {
public:
// Requests the owner to schedule a paint.
virtual void ScheduleCompositorPaint() = 0;
};
// 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> {
public:
// Create a compositor from the provided handle.
static Compositor* Create(CompositorDelegate* delegate,
gfx::AcceleratedWidget widget,
const gfx::Size& size);
// Creates a new texture. The caller owns the returned object.
virtual Texture* CreateTexture() = 0;
// Notifies the compositor that compositing is about to start. If |clear| is
// true, this will cause the compositor to clear before compositing.
void NotifyStart(bool clear);
// Notifies the compositor that compositing is complete.
void NotifyEnd();
// Blurs the specific region in the compositor.
virtual void Blur(const gfx::Rect& bounds) = 0;
// Schedules a paint on the widget this Compositor was created for.
void SchedulePaint() {
delegate_->ScheduleCompositorPaint();
}
// Notifies the compositor that the size of the widget that it is
// drawing to has changed.
void WidgetSizeChanged(const gfx::Size& size) {
size_ = size;
OnWidgetSizeChanged();
}
// Returns the size of the widget that is being drawn to.
const gfx::Size& size() { return size_; }
// Layers do 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);
protected:
Compositor(CompositorDelegate* delegate, const gfx::Size& size);
virtual ~Compositor();
// Notifies the compositor that compositing is about to start.
virtual void OnNotifyStart(bool clear) = 0;
// Notifies the compositor that compositing is complete.
virtual void OnNotifyEnd() = 0;
virtual void OnWidgetSizeChanged() = 0;
CompositorDelegate* delegate() { return delegate_; }
private:
CompositorDelegate* delegate_;
gfx::Size size_;
ObserverList<CompositorObserver> observer_list_;
friend class base::RefCounted<Compositor>;
};
} // namespace ui
#endif // UI_GFX_COMPOSITOR_COMPOSITOR_H_
|