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

Side by Side Diff: services/ui/demo/bitmap_uploader.cc

Issue 2440453002: Splitting the Mus demo code out of a service. (Closed)
Patch Set: Rebased Created 4 years, 2 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "services/ui/demo/bitmap_uploader.h" 5 #include "services/ui/demo/bitmap_uploader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 17 matching lines...) Expand all
28 28
29 const char kBitmapUploaderForAcceleratedWidget[] = 29 const char kBitmapUploaderForAcceleratedWidget[] =
30 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; 30 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__";
31 31
32 BitmapUploader::BitmapUploader(Window* window) 32 BitmapUploader::BitmapUploader(Window* window)
33 : window_(window), 33 : window_(window),
34 color_(g_transparent_color), 34 color_(g_transparent_color),
35 width_(0), 35 width_(0),
36 height_(0), 36 height_(0),
37 format_(BGRA), 37 format_(BGRA),
38 next_resource_id_(1u) { 38 next_resource_id_(1u),
39 } 39 weak_factory_(this) {}
40 40
41 void BitmapUploader::Init(ui::GpuService* gpu_service) { 41 void BitmapUploader::Init(ui::GpuService* gpu_service) {
42 surface_ = window_->RequestSurface(mojom::SurfaceType::DEFAULT); 42 surface_ = window_->RequestSurface(mojom::SurfaceType::DEFAULT);
43 surface_->BindToThread(); 43 surface_->BindToThread();
44 surface_->set_client(this); 44 surface_->set_client(this);
45 45
46 gles2_context_ = GLES2Context::CreateOffscreenContext( 46 gpu_service->EstablishGpuChannel(base::Bind(
47 gpu_service->EstablishGpuChannelSync(), 47 &BitmapUploader::OnGpuChannelEstablished, weak_factory_.GetWeakPtr()));
48 base::ThreadTaskRunnerHandle::Get());
49 } 48 }
50 49
51 BitmapUploader::~BitmapUploader() {} 50 BitmapUploader::~BitmapUploader() {}
52 51
53 // Sets the color which is RGBA. 52 // Sets the color which is RGBA.
54 void BitmapUploader::SetColor(uint32_t color) { 53 void BitmapUploader::SetColor(uint32_t color) {
55 if (color_ == color) 54 if (color_ == color)
56 return; 55 return;
57 color_ = color; 56 color_ = color;
58 if (surface_) 57 if (surface_)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 quad->SetAll(sqs, bounds, opaque_rect, bounds, needs_blending, color_, 166 quad->SetAll(sqs, bounds, opaque_rect, bounds, needs_blending, color_,
168 force_antialiasing_off); 167 force_antialiasing_off);
169 } 168 }
170 169
171 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); 170 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass));
172 171
173 // TODO(rjkroege, fsamuel): We should throttle frames. 172 // TODO(rjkroege, fsamuel): We should throttle frames.
174 surface_->SubmitCompositorFrame(std::move(frame), base::Closure()); 173 surface_->SubmitCompositorFrame(std::move(frame), base::Closure());
175 } 174 }
176 175
176 void BitmapUploader::OnGpuChannelEstablished(
177 scoped_refptr<gpu::GpuChannelHost> gpu_channel) {
178 gles2_context_ = GLES2Context::CreateOffscreenContext(
179 gpu_channel, base::ThreadTaskRunnerHandle::Get());
180 }
181
177 uint32_t BitmapUploader::BindTextureForSize(const gfx::Size& size) { 182 uint32_t BitmapUploader::BindTextureForSize(const gfx::Size& size) {
178 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); 183 gpu::gles2::GLES2Interface* gl = gles2_context_->interface();
179 // TODO(jamesr): Recycle textures. 184 // TODO(jamesr): Recycle textures.
180 GLuint texture = 0u; 185 GLuint texture = 0u;
181 gl->GenTextures(1, &texture); 186 gl->GenTextures(1, &texture);
182 gl->BindTexture(GL_TEXTURE_2D, texture); 187 gl->BindTexture(GL_TEXTURE_2D, texture);
183 gl->TexImage2D(GL_TEXTURE_2D, 0, TextureFormat(), size.width(), size.height(), 188 gl->TexImage2D(GL_TEXTURE_2D, 0, TextureFormat(), size.width(), size.height(),
184 0, TextureFormat(), GL_UNSIGNED_BYTE, 0); 189 0, TextureFormat(), GL_UNSIGNED_BYTE, 0);
185 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 190 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
186 return texture; 191 return texture;
187 } 192 }
188 193
189 void BitmapUploader::OnResourcesReturned( 194 void BitmapUploader::OnResourcesReturned(
190 WindowSurface* surface, 195 WindowSurface* surface,
191 const cc::ReturnedResourceArray& resources) { 196 const cc::ReturnedResourceArray& resources) {
192 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); 197 gpu::gles2::GLES2Interface* gl = gles2_context_->interface();
193 // TODO(jamesr): Recycle. 198 // TODO(jamesr): Recycle.
194 for (size_t i = 0; i < resources.size(); ++i) { 199 for (size_t i = 0; i < resources.size(); ++i) {
195 cc::ReturnedResource resource = std::move(resources[i]); 200 cc::ReturnedResource resource = std::move(resources[i]);
196 DCHECK_EQ(1, resource.count); 201 DCHECK_EQ(1, resource.count);
197 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); 202 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData());
198 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; 203 uint32_t texture_id = resource_to_texture_id_map_[resource.id];
199 DCHECK_NE(0u, texture_id); 204 DCHECK_NE(0u, texture_id);
200 resource_to_texture_id_map_.erase(resource.id); 205 resource_to_texture_id_map_.erase(resource.id);
201 gl->DeleteTextures(1, &texture_id); 206 gl->DeleteTextures(1, &texture_id);
202 } 207 }
203 } 208 }
204 209
205 } // namespace ui 210 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698