Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: ui/aura/bench/bench_main.cc

Issue 228083002: Make ReflectorImpl use mailboxes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if defined(USE_X11) 5 #if defined(USE_X11)
6 #include <X11/Xlib.h> 6 #include <X11/Xlib.h>
7 #endif 7 #endif
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 int frames() const { return frames_; } 131 int frames() const { return frames_; }
132 132
133 private: 133 private:
134 TimeTicks start_time_; 134 TimeTicks start_time_;
135 int frames_; 135 int frames_;
136 int max_frames_; 136 int max_frames_;
137 137
138 DISALLOW_COPY_AND_ASSIGN(BenchCompositorObserver); 138 DISALLOW_COPY_AND_ASSIGN(BenchCompositorObserver);
139 }; 139 };
140 140
141 class WebGLTexture : public ui::Texture { 141 void ReturnMailbox(scoped_refptr<cc::ContextProvider> context_provider,
142 public: 142 unsigned int texture,
danakj 2014/04/08 16:08:01 nit: uint32?
piman 2014/04/08 23:17:46 GLuint
143 WebGLTexture(gpu::gles2::GLES2Interface* gl, const gfx::Size& size) 143 unsigned int sync_point,
144 : ui::Texture(false, size, 1.0f), 144 bool is_lost) {
145 gl_(gl), 145 if (is_lost)
146 texture_id_(0u) { 146 return;
danakj 2014/04/08 16:08:01 Don't you want to delete the texture here, just be
piman 2014/04/08 23:17:46 Done.
147 gl->GenTextures(1, &texture_id_); 147 gpu::gles2::GLES2Interface* gl = context_provider->ContextGL();
148 gl->BindTexture(GL_TEXTURE_2D, texture_id_); 148 gl->WaitSyncPointCHROMIUM(sync_point);
149 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 149 gl->DeleteTextures(1, &texture);
150 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 150 gl->ShallowFlushCHROMIUM();
151 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 151 }
152 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
153 gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(),
154 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
155 }
156
157 virtual unsigned int PrepareTexture() OVERRIDE {
158 return texture_id_;
159 }
160
161 private:
162 virtual ~WebGLTexture() {
163 gl_->DeleteTextures(1, &texture_id_);
164 }
165
166 gpu::gles2::GLES2Interface* gl_;
167 GLuint texture_id_;
168
169 DISALLOW_COPY_AND_ASSIGN(WebGLTexture);
170 };
171 152
172 // A benchmark that adds a texture layer that is updated every frame. 153 // A benchmark that adds a texture layer that is updated every frame.
173 class WebGLBench : public BenchCompositorObserver { 154 class WebGLBench : public BenchCompositorObserver {
174 public: 155 public:
175 WebGLBench(Layer* parent, Compositor* compositor, int max_frames) 156 WebGLBench(Layer* parent, Compositor* compositor, int max_frames)
176 : BenchCompositorObserver(max_frames), 157 : BenchCompositorObserver(max_frames),
177 parent_(parent), 158 parent_(parent),
178 webgl_(ui::LAYER_TEXTURED), 159 webgl_(ui::LAYER_TEXTURED),
179 compositor_(compositor), 160 compositor_(compositor),
180 texture_(),
181 fbo_(0), 161 fbo_(0),
182 do_draw_(true) { 162 do_draw_(true) {
183 CommandLine* command_line = CommandLine::ForCurrentProcess(); 163 CommandLine* command_line = CommandLine::ForCurrentProcess();
184 do_draw_ = !command_line->HasSwitch("disable-draw"); 164 do_draw_ = !command_line->HasSwitch("disable-draw");
185 165
186 std::string webgl_size = command_line->GetSwitchValueASCII("webgl-size"); 166 std::string webgl_size = command_line->GetSwitchValueASCII("webgl-size");
187 int width = 0; 167 int width = 0;
188 int height = 0; 168 int height = 0;
189 if (!webgl_size.empty()) { 169 if (!webgl_size.empty()) {
190 std::vector<std::string> split_size; 170 std::vector<std::string> split_size;
191 base::SplitString(webgl_size, 'x', &split_size); 171 base::SplitString(webgl_size, 'x', &split_size);
192 if (split_size.size() == 2) { 172 if (split_size.size() == 2) {
193 width = atoi(split_size[0].c_str()); 173 width = atoi(split_size[0].c_str());
194 height = atoi(split_size[1].c_str()); 174 height = atoi(split_size[1].c_str());
195 } 175 }
196 } 176 }
197 if (!width || !height) { 177 if (!width || !height) {
198 width = 800; 178 width = 800;
199 height = 600; 179 height = 600;
200 } 180 }
201 gfx::Rect bounds(width, height); 181 gfx::Rect bounds(width, height);
202 webgl_.SetBounds(bounds); 182 webgl_.SetBounds(bounds);
203 parent_->Add(&webgl_); 183 parent_->Add(&webgl_);
204 184
205 context_provider_ = 185 context_provider_ =
206 ui::ContextFactory::GetInstance()->SharedMainThreadContextProvider(); 186 ui::ContextFactory::GetInstance()->SharedMainThreadContextProvider();
207 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); 187 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
208 texture_ = new WebGLTexture(gl, bounds.size()); 188 unsigned int texture = 0;
189 gl->GenTextures(1, &texture);
190 gl->BindTexture(GL_TEXTURE_2D, texture);
191 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
192 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
193 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
194 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
195 gl->TexImage2D(GL_TEXTURE_2D,
196 0,
197 GL_RGBA,
198 width,
199 height,
200 0,
201 GL_RGBA,
202 GL_UNSIGNED_BYTE,
203 NULL);
204 gpu::Mailbox mailbox;
205 gl->GenMailboxCHROMIUM(mailbox.name);
206 gl->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
207
209 gl->GenFramebuffers(1, &fbo_); 208 gl->GenFramebuffers(1, &fbo_);
210 compositor->AddObserver(this);
211 webgl_.SetExternalTexture(texture_.get());
212 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); 209 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
213 gl->FramebufferTexture2D( 210 gl->FramebufferTexture2D(
214 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 211 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
215 GL_TEXTURE_2D, texture_->PrepareTexture(), 0);
216 gl->ClearColor(0.f, 1.f, 0.f, 1.f); 212 gl->ClearColor(0.f, 1.f, 0.f, 1.f);
217 gl->Clear(GL_COLOR_BUFFER_BIT); 213 gl->Clear(GL_COLOR_BUFFER_BIT);
218 gl->Flush(); 214 gl->Flush();
215
216 unsigned int sync_point = gl->InsertSyncPointCHROMIUM();
danakj 2014/04/08 16:08:01 uint32? (trying to keep "unsigned int" inside cc/,
piman 2014/04/08 23:17:46 GLuint
217 webgl_.SetTextureMailbox(
218 cc::TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point),
219 cc::SingleReleaseCallback::Create(
220 base::Bind(ReturnMailbox, context_provider_, texture)),
221 bounds.size());
222 compositor->AddObserver(this);
219 } 223 }
220 224
221 virtual ~WebGLBench() { 225 virtual ~WebGLBench() {
222 context_provider_->ContextGL()->DeleteFramebuffers(1, &fbo_);
223 webgl_.SetShowPaintedContent(); 226 webgl_.SetShowPaintedContent();
224 texture_ = NULL; 227 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
228 gl->DeleteFramebuffers(1, &fbo_);
225 compositor_->RemoveObserver(this); 229 compositor_->RemoveObserver(this);
226 } 230 }
227 231
228 virtual void Draw() OVERRIDE { 232 virtual void Draw() OVERRIDE {
229 if (do_draw_) { 233 if (do_draw_) {
230 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); 234 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL();
231 gl->ClearColor((frames() % kFrames)*1.0/kFrames, 1.f, 0.f, 1.f); 235 gl->ClearColor((frames() % kFrames)*1.0/kFrames, 1.f, 0.f, 1.f);
232 gl->Clear(GL_COLOR_BUFFER_BIT); 236 gl->Clear(GL_COLOR_BUFFER_BIT);
233 gl->Flush(); 237 gl->Flush();
234 } 238 }
235 webgl_.SetExternalTexture(texture_.get());
236 webgl_.SchedulePaint(gfx::Rect(webgl_.bounds().size())); 239 webgl_.SchedulePaint(gfx::Rect(webgl_.bounds().size()));
237 compositor_->ScheduleDraw(); 240 compositor_->ScheduleDraw();
238 } 241 }
239 242
240 private: 243 private:
241 Layer* parent_; 244 Layer* parent_;
242 Layer webgl_; 245 Layer webgl_;
243 Compositor* compositor_; 246 Compositor* compositor_;
244 scoped_refptr<cc::ContextProvider> context_provider_; 247 scoped_refptr<cc::ContextProvider> context_provider_;
245 scoped_refptr<WebGLTexture> texture_;
246 248
247 // The FBO that is used to render to the texture. 249 // The FBO that is used to render to the texture.
248 unsigned int fbo_; 250 unsigned int fbo_;
249 251
250 // Whether or not to draw to the texture every frame. 252 // Whether or not to draw to the texture every frame.
251 bool do_draw_; 253 bool do_draw_;
252 254
253 DISALLOW_COPY_AND_ASSIGN(WebGLBench); 255 DISALLOW_COPY_AND_ASSIGN(WebGLBench);
254 }; 256 };
255 257
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 ui::PrintLayerHierarchy(host->window()->layer(), gfx::Point(100, 100)); 363 ui::PrintLayerHierarchy(host->window()->layer(), gfx::Point(100, 100));
362 #endif 364 #endif
363 365
364 host->Show(); 366 host->Show();
365 base::MessageLoopForUI::current()->Run(); 367 base::MessageLoopForUI::current()->Run();
366 focus_client.reset(); 368 focus_client.reset();
367 host.reset(); 369 host.reset();
368 370
369 return 0; 371 return 0;
370 } 372 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698