| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 const char kBitmapUploaderForAcceleratedWidget[] = | 30 const char kBitmapUploaderForAcceleratedWidget[] = |
| 31 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; | 31 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; |
| 32 | 32 |
| 33 BitmapUploader::BitmapUploader(Window* window) | 33 BitmapUploader::BitmapUploader(Window* window) |
| 34 : window_(window), | 34 : window_(window), |
| 35 color_(g_transparent_color), | 35 color_(g_transparent_color), |
| 36 width_(0), | 36 width_(0), |
| 37 height_(0), | 37 height_(0), |
| 38 format_(BGRA), | 38 format_(BGRA), |
| 39 next_resource_id_(1u) { | 39 next_resource_id_(1u), |
| 40 } | 40 weak_factory_(this) {} |
| 41 | 41 |
| 42 void BitmapUploader::Init(ui::GpuService* gpu_service) { | 42 void BitmapUploader::Init(ui::GpuService* gpu_service) { |
| 43 compositor_frame_sink_ = window_->RequestCompositorFrameSink( | 43 gpu_service->EstablishGpuChannel(base::Bind( |
| 44 mojom::SurfaceType::DEFAULT, | 44 &BitmapUploader::OnGpuChannelEstablished, weak_factory_.GetWeakPtr())); |
| 45 new ContextProvider(gpu_service->EstablishGpuChannelSync())); | |
| 46 compositor_frame_sink_->BindToClient(this); | |
| 47 } | 45 } |
| 48 | 46 |
| 49 BitmapUploader::~BitmapUploader() { | 47 BitmapUploader::~BitmapUploader() { |
| 50 compositor_frame_sink_->DetachFromClient(); | 48 compositor_frame_sink_->DetachFromClient(); |
| 51 } | 49 } |
| 52 | 50 |
| 53 // Sets the color which is RGBA. | 51 // Sets the color which is RGBA. |
| 54 void BitmapUploader::SetColor(uint32_t color) { | 52 void BitmapUploader::SetColor(uint32_t color) { |
| 55 if (color_ == color) | 53 if (color_ == color) |
| 56 return; | 54 return; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 quad->SetAll(sqs, bounds, opaque_rect, bounds, needs_blending, color_, | 166 quad->SetAll(sqs, bounds, opaque_rect, bounds, needs_blending, color_, |
| 169 force_antialiasing_off); | 167 force_antialiasing_off); |
| 170 } | 168 } |
| 171 | 169 |
| 172 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)); |
| 173 | 171 |
| 174 // TODO(rjkroege, fsamuel): We should throttle frames. | 172 // TODO(rjkroege, fsamuel): We should throttle frames. |
| 175 compositor_frame_sink_->SubmitCompositorFrame(std::move(frame)); | 173 compositor_frame_sink_->SubmitCompositorFrame(std::move(frame)); |
| 176 } | 174 } |
| 177 | 175 |
| 176 void BitmapUploader::OnGpuChannelEstablished( |
| 177 scoped_refptr<gpu::GpuChannelHost> gpu_channel) { |
| 178 compositor_frame_sink_ = window_->RequestCompositorFrameSink( |
| 179 mojom::SurfaceType::DEFAULT, |
| 180 new ContextProvider(gpu_channel)); |
| 181 compositor_frame_sink_->BindToClient(this); |
| 182 } |
| 183 |
| 178 uint32_t BitmapUploader::BindTextureForSize(const gfx::Size& size) { | 184 uint32_t BitmapUploader::BindTextureForSize(const gfx::Size& size) { |
| 179 gpu::gles2::GLES2Interface* gl = | 185 gpu::gles2::GLES2Interface* gl = |
| 180 compositor_frame_sink_->context_provider()->ContextGL(); | 186 compositor_frame_sink_->context_provider()->ContextGL(); |
| 181 // TODO(jamesr): Recycle textures. | 187 // TODO(jamesr): Recycle textures. |
| 182 GLuint texture = 0u; | 188 GLuint texture = 0u; |
| 183 gl->GenTextures(1, &texture); | 189 gl->GenTextures(1, &texture); |
| 184 gl->BindTexture(GL_TEXTURE_2D, texture); | 190 gl->BindTexture(GL_TEXTURE_2D, texture); |
| 185 gl->TexImage2D(GL_TEXTURE_2D, 0, TextureFormat(), size.width(), size.height(), | 191 gl->TexImage2D(GL_TEXTURE_2D, 0, TextureFormat(), size.width(), size.height(), |
| 186 0, TextureFormat(), GL_UNSIGNED_BYTE, 0); | 192 0, TextureFormat(), GL_UNSIGNED_BYTE, 0); |
| 187 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 193 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // TODO(fsamuel): Implement this. | 234 // TODO(fsamuel): Implement this. |
| 229 } | 235 } |
| 230 | 236 |
| 231 void BitmapUploader::SetExternalTilePriorityConstraints( | 237 void BitmapUploader::SetExternalTilePriorityConstraints( |
| 232 const gfx::Rect& viewport_rect, | 238 const gfx::Rect& viewport_rect, |
| 233 const gfx::Transform& transform) { | 239 const gfx::Transform& transform) { |
| 234 // TODO(fsamuel): Implement this. | 240 // TODO(fsamuel): Implement this. |
| 235 } | 241 } |
| 236 | 242 |
| 237 } // namespace ui | 243 } // namespace ui |
| OLD | NEW |