~abreu-alexandre/oxide/remove-chromedriver-build

« back to all changes in this revision

Viewing changes to shared/browser/compositor/oxide_mailbox_buffer_map.cc

  • Committer: Chris Coulson
  • Date: 2016-02-26 18:27:48 UTC
  • Revision ID: chris.coulson@canonical.com-20160226182748-bqhc23qxs09cpg33
Switch to a single-threaded webview compositor

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
 
// Copyright (C) 2015 Canonical Ltd.
 
2
// Copyright (C) 2015-2016 Canonical Ltd.
3
3
 
4
4
// This library is free software; you can redistribute it and/or
5
5
// modify it under the terms of the GNU Lesser General Public
28
28
 
29
29
namespace oxide {
30
30
 
31
 
void MailboxBufferMap::AddMapping(const gpu::Mailbox& mailbox,
 
31
bool MailboxBufferMap::AddMapping(const gpu::Mailbox& mailbox,
32
32
                                  const MailboxBufferData& data,
33
33
                                  DelayedFrameQueue* ready_frames) {
34
 
  lock_.AssertAcquired();
 
34
  DCHECK(CalledOnValidThread());
 
35
  DCHECK(map_.find(mailbox) == map_.end());
35
36
 
36
 
  map_[mailbox] = data;
 
37
  bool added = false;
 
38
  if (data.surface_id == surface_id_) {
 
39
    added = true;
 
40
    map_[mailbox] = data;
 
41
  }
37
42
 
38
43
  while (!delayed_frames_.empty()) {
39
 
    const linked_ptr<CompositorFrameData>& frame = delayed_frames_.front();
40
 
    if (map_.find(frame->gl_frame_data->mailbox) == map_.end() &&
41
 
        frame->surface_id == surface_id_) {
 
44
    scoped_ptr<CompositorFrameData>& frame = delayed_frames_.front();
 
45
    DCHECK_EQ(frame->surface_id, surface_id_);
 
46
 
 
47
    if (map_.find(frame->gl_frame_data->mailbox) == map_.end()) {
42
48
      break;
43
49
    }
44
50
 
45
 
    ready_frames->push(frame);
 
51
    ready_frames->push(std::move(frame));
46
52
    delayed_frames_.pop();
47
53
  }
 
54
 
 
55
  return added;
48
56
}
49
57
 
50
58
MailboxBufferMap::MailboxBufferMap(CompositingMode mode)
54
62
MailboxBufferMap::~MailboxBufferMap() {}
55
63
 
56
64
void MailboxBufferMap::SetOutputSurfaceID(uint32_t surface_id) {
57
 
  base::AutoLock lock(lock_);
 
65
  DCHECK(CalledOnValidThread());
58
66
 
59
67
  surface_id_ = surface_id;
60
68
 
61
69
  for (auto it = map_.begin(); it != map_.end(); ) {
62
 
    if (it->second.surface_id == surface_id) {
63
 
      ++it;
64
 
      continue;
65
 
    }
 
70
    DCHECK_NE(it->second.surface_id, surface_id);
66
71
 
67
72
    if (mode_ == COMPOSITING_MODE_TEXTURE) {
68
73
      auto e = it++;
98
103
  DCHECK_EQ(mode_, COMPOSITING_MODE_TEXTURE);
99
104
  DCHECK_NE(texture, 0U);
100
105
 
101
 
  base::AutoLock lock(lock_);
102
 
 
103
 
  if (surface_id != surface_id_) {
104
 
    return false;
105
 
  }
106
 
 
107
 
  DCHECK(map_.find(mailbox) == map_.end());
108
 
 
109
106
  MailboxBufferData data;
110
107
  data.surface_id = surface_id;
111
108
  data.data.texture = texture;
112
109
 
113
 
  AddMapping(mailbox, data, ready_frames);
114
 
 
115
 
  return true;
 
110
  return AddMapping(mailbox, data, ready_frames);
116
111
}
117
112
 
118
113
bool MailboxBufferMap::AddEGLImageMapping(
123
118
  DCHECK_EQ(mode_, COMPOSITING_MODE_EGLIMAGE);
124
119
  DCHECK_NE(egl_image, EGL_NO_IMAGE_KHR);
125
120
 
126
 
  base::AutoLock lock(lock_);
127
 
 
128
 
  if (surface_id != surface_id_) {
129
 
    return false;
130
 
  }
131
 
 
132
 
  DCHECK(map_.find(mailbox) == map_.end());
133
 
 
134
121
  MailboxBufferData data;
135
122
  data.surface_id = surface_id;
136
123
  data.data.image.live = true;
137
124
  data.data.image.ref_count = 0;
138
125
  data.data.image.egl_image = egl_image;
139
126
 
140
 
  AddMapping(mailbox, data, ready_frames);
141
 
 
142
 
  return true;
 
127
  return AddMapping(mailbox, data, ready_frames);
143
128
}
144
129
 
145
130
void MailboxBufferMap::MailboxBufferDestroyed(const gpu::Mailbox& mailbox) {
146
 
  base::AutoLock lock(lock_);
 
131
  DCHECK(CalledOnValidThread());
147
132
 
148
133
  if (mode_ == COMPOSITING_MODE_TEXTURE) {
149
134
    map_.erase(mailbox);
167
152
 
168
153
GLuint MailboxBufferMap::ConsumeTextureFromMailbox(
169
154
    const gpu::Mailbox& mailbox) {
 
155
  DCHECK(CalledOnValidThread());
170
156
  DCHECK_EQ(mode_, COMPOSITING_MODE_TEXTURE);
171
157
 
172
 
  base::AutoLock lock(lock_);
173
158
  auto it = map_.find(mailbox);
174
159
  if (it == map_.end()) {
175
160
    return 0;
180
165
 
181
166
EGLImageKHR MailboxBufferMap::ConsumeEGLImageFromMailbox(
182
167
    const gpu::Mailbox& mailbox) {
 
168
  DCHECK(CalledOnValidThread());
183
169
  DCHECK_EQ(mode_, COMPOSITING_MODE_EGLIMAGE);
184
170
 
185
 
  base::AutoLock lock(lock_);
186
171
  auto it = map_.find(mailbox);
187
172
  if (it == map_.end() || !it->second.data.image.live) {
188
173
    return EGL_NO_IMAGE_KHR;
194
179
 
195
180
void MailboxBufferMap::ReclaimMailboxBufferResources(
196
181
    const gpu::Mailbox& mailbox) {
 
182
  DCHECK(CalledOnValidThread());
 
183
 
197
184
  if (mode_ == COMPOSITING_MODE_TEXTURE) {
198
185
    return;
199
186
  }
200
187
 
201
188
  DCHECK_EQ(mode_, COMPOSITING_MODE_EGLIMAGE);
202
189
 
203
 
  base::AutoLock lock(lock_);
204
 
 
205
190
  auto it = map_.find(mailbox);
206
191
  DCHECK(it != map_.end());
207
192
  DCHECK_GT(it->second.data.image.ref_count, 0);
218
203
}
219
204
 
220
205
bool MailboxBufferMap::CanBeginFrameSwap(CompositorFrameData* frame) {
 
206
  DCHECK(CalledOnValidThread());
221
207
  DCHECK(frame->gl_frame_data);
222
208
 
223
 
  base::AutoLock lock(lock_);
 
209
  if (frame->surface_id != surface_id_) {
 
210
    return false;
 
211
  }
224
212
 
225
213
  if (!delayed_frames_.empty()) {
226
214
    scoped_ptr<CompositorFrameData> frame_copy =
227
215
        CompositorFrameData::AllocFrom(frame);
228
 
    delayed_frames_.push(make_linked_ptr(frame_copy.release()));
 
216
    delayed_frames_.push(std::move(frame_copy));
229
217
    return false;
230
218
  }
231
219
 
232
 
  if (frame->surface_id != surface_id_) {
233
 
    return true;
234
 
  }
235
 
 
236
220
  if (map_.find(frame->gl_frame_data->mailbox) == map_.end()) {
237
221
    scoped_ptr<CompositorFrameData> frame_copy =
238
222
        CompositorFrameData::AllocFrom(frame);
239
 
    delayed_frames_.push(make_linked_ptr(frame_copy.release()));
 
223
    delayed_frames_.push(std::move(frame_copy));
240
224
    return false;
241
225
  }
242
226