| 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 "components/bitmap_uploader/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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "cc/ipc/compositor_frame.mojom.h" | 12 #include "cc/ipc/compositor_frame.mojom.h" |
| 13 #include "cc/quads/render_pass.h" | 13 #include "cc/quads/render_pass.h" |
| 14 #include "cc/quads/solid_color_draw_quad.h" | 14 #include "cc/quads/solid_color_draw_quad.h" |
| 15 #include "cc/quads/texture_draw_quad.h" | 15 #include "cc/quads/texture_draw_quad.h" |
| 16 #include "services/ui/public/cpp/gles2_context.h" | 16 #include "services/ui/public/cpp/gles2_context.h" |
| 17 #include "services/ui/public/cpp/window.h" | 17 #include "services/ui/public/cpp/window.h" |
| 18 #include "services/ui/public/cpp/window_surface.h" | 18 #include "services/ui/public/cpp/window_surface.h" |
| 19 | 19 |
| 20 namespace bitmap_uploader { | 20 namespace ui { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const uint32_t g_transparent_color = 0x00000000; | 23 const uint32_t g_transparent_color = 0x00000000; |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 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(ui::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) {} | 37 id_namespace_(0u) {} |
| 38 | 38 |
| 39 BitmapUploader::~BitmapUploader() { | 39 BitmapUploader::~BitmapUploader() { |
| 40 } | 40 } |
| 41 | 41 |
| 42 void BitmapUploader::Init(shell::Connector* connector) { | 42 void BitmapUploader::Init(shell::Connector* connector) { |
| 43 surface_ = window_->RequestSurface(ui::mojom::SurfaceType::DEFAULT); | 43 surface_ = window_->RequestSurface(mojom::SurfaceType::DEFAULT); |
| 44 surface_->BindToThread(); | 44 surface_->BindToThread(); |
| 45 surface_->set_client(this); | 45 surface_->set_client(this); |
| 46 | 46 |
| 47 gles2_context_ = ui::GLES2Context::CreateOffscreenContext( | 47 gles2_context_ = GLES2Context::CreateOffscreenContext( |
| 48 std::vector<int32_t>(), connector); | 48 std::vector<int32_t>(), connector); |
| 49 // CreateOffscreenContext() may return null. | 49 // CreateOffscreenContext() may return null. |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Sets the color which is RGBA. | 52 // Sets the color which is RGBA. |
| 53 void BitmapUploader::SetColor(uint32_t color) { | 53 void BitmapUploader::SetColor(uint32_t color) { |
| 54 if (color_ == color) | 54 if (color_ == color) |
| 55 return; | 55 return; |
| 56 color_ = color; | 56 color_ = color; |
| 57 if (surface_) | 57 if (surface_) |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 return texture; | 185 return texture; |
| 186 } | 186 } |
| 187 | 187 |
| 188 void BitmapUploader::SetIdNamespace(uint32_t id_namespace) { | 188 void BitmapUploader::SetIdNamespace(uint32_t id_namespace) { |
| 189 id_namespace_ = id_namespace; | 189 id_namespace_ = id_namespace; |
| 190 if (color_ != g_transparent_color || bitmap_.get()) | 190 if (color_ != g_transparent_color || bitmap_.get()) |
| 191 Upload(); | 191 Upload(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void BitmapUploader::OnResourcesReturned( | 194 void BitmapUploader::OnResourcesReturned( |
| 195 ui::WindowSurface* surface, | 195 WindowSurface* surface, |
| 196 mojo::Array<cc::ReturnedResource> resources) { | 196 mojo::Array<cc::ReturnedResource> resources) { |
| 197 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); | 197 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); |
| 198 // TODO(jamesr): Recycle. | 198 // TODO(jamesr): Recycle. |
| 199 for (size_t i = 0; i < resources.size(); ++i) { | 199 for (size_t i = 0; i < resources.size(); ++i) { |
| 200 cc::ReturnedResource resource = std::move(resources[i]); | 200 cc::ReturnedResource resource = std::move(resources[i]); |
| 201 DCHECK_EQ(1, resource.count); | 201 DCHECK_EQ(1, resource.count); |
| 202 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); | 202 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); |
| 203 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; | 203 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; |
| 204 DCHECK_NE(0u, texture_id); | 204 DCHECK_NE(0u, texture_id); |
| 205 resource_to_texture_id_map_.erase(resource.id); | 205 resource_to_texture_id_map_.erase(resource.id); |
| 206 gl->DeleteTextures(1, &texture_id); | 206 gl->DeleteTextures(1, &texture_id); |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 | 209 |
| 210 } // namespace bitmap_uploader | 210 } // namespace ui |
| OLD | NEW |