| 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/public/cpp/bitmap_uploader.h" | 5 #include "services/ui/public/cpp/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 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 const char kBitmapUploaderForAcceleratedWidget[] = | 27 const char kBitmapUploaderForAcceleratedWidget[] = |
| 28 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; | 28 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; |
| 29 | 29 |
| 30 BitmapUploader::BitmapUploader(Window* window) | 30 BitmapUploader::BitmapUploader(Window* window) |
| 31 : window_(window), | 31 : window_(window), |
| 32 color_(g_transparent_color), | 32 color_(g_transparent_color), |
| 33 width_(0), | 33 width_(0), |
| 34 height_(0), | 34 height_(0), |
| 35 format_(BGRA), | 35 format_(BGRA), |
| 36 next_resource_id_(1u), | 36 next_resource_id_(1u) {} |
| 37 id_namespace_(0u) {} | |
| 38 | 37 |
| 39 BitmapUploader::~BitmapUploader() { | 38 BitmapUploader::~BitmapUploader() { |
| 40 } | 39 } |
| 41 | 40 |
| 42 void BitmapUploader::Init(shell::Connector* connector) { | 41 void BitmapUploader::Init(shell::Connector* connector) { |
| 43 surface_ = window_->RequestSurface(mojom::SurfaceType::DEFAULT); | 42 surface_ = window_->RequestSurface(mojom::SurfaceType::DEFAULT); |
| 44 surface_->BindToThread(); | 43 surface_->BindToThread(); |
| 45 surface_->set_client(this); | 44 surface_->set_client(this); |
| 46 | 45 |
| 47 gles2_context_ = GLES2Context::CreateOffscreenContext( | 46 gles2_context_ = GLES2Context::CreateOffscreenContext( |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // TODO(jamesr): Recycle textures. | 177 // TODO(jamesr): Recycle textures. |
| 179 GLuint texture = 0u; | 178 GLuint texture = 0u; |
| 180 gl->GenTextures(1, &texture); | 179 gl->GenTextures(1, &texture); |
| 181 gl->BindTexture(GL_TEXTURE_2D, texture); | 180 gl->BindTexture(GL_TEXTURE_2D, texture); |
| 182 gl->TexImage2D(GL_TEXTURE_2D, 0, TextureFormat(), size.width(), size.height(), | 181 gl->TexImage2D(GL_TEXTURE_2D, 0, TextureFormat(), size.width(), size.height(), |
| 183 0, TextureFormat(), GL_UNSIGNED_BYTE, 0); | 182 0, TextureFormat(), GL_UNSIGNED_BYTE, 0); |
| 184 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 183 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 185 return texture; | 184 return texture; |
| 186 } | 185 } |
| 187 | 186 |
| 188 void BitmapUploader::SetIdNamespace(uint32_t id_namespace) { | |
| 189 id_namespace_ = id_namespace; | |
| 190 if (color_ != g_transparent_color || bitmap_.get()) | |
| 191 Upload(); | |
| 192 } | |
| 193 | |
| 194 void BitmapUploader::OnResourcesReturned( | 187 void BitmapUploader::OnResourcesReturned( |
| 195 WindowSurface* surface, | 188 WindowSurface* surface, |
| 196 mojo::Array<cc::ReturnedResource> resources) { | 189 mojo::Array<cc::ReturnedResource> resources) { |
| 197 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); | 190 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); |
| 198 // TODO(jamesr): Recycle. | 191 // TODO(jamesr): Recycle. |
| 199 for (size_t i = 0; i < resources.size(); ++i) { | 192 for (size_t i = 0; i < resources.size(); ++i) { |
| 200 cc::ReturnedResource resource = std::move(resources[i]); | 193 cc::ReturnedResource resource = std::move(resources[i]); |
| 201 DCHECK_EQ(1, resource.count); | 194 DCHECK_EQ(1, resource.count); |
| 202 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); | 195 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); |
| 203 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; | 196 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; |
| 204 DCHECK_NE(0u, texture_id); | 197 DCHECK_NE(0u, texture_id); |
| 205 resource_to_texture_id_map_.erase(resource.id); | 198 resource_to_texture_id_map_.erase(resource.id); |
| 206 gl->DeleteTextures(1, &texture_id); | 199 gl->DeleteTextures(1, &texture_id); |
| 207 } | 200 } |
| 208 } | 201 } |
| 209 | 202 |
| 210 } // namespace ui | 203 } // namespace ui |
| OLD | NEW |