Chromium Code Reviews| 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" |
| 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/gpu_service.h" | |
| 17 #include "services/ui/public/cpp/window.h" | 18 #include "services/ui/public/cpp/window.h" |
| 18 #include "services/ui/public/cpp/window_surface.h" | 19 #include "services/ui/public/cpp/window_surface.h" |
| 19 | 20 |
| 20 namespace ui { | 21 namespace ui { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 const uint32_t g_transparent_color = 0x00000000; | 24 const uint32_t g_transparent_color = 0x00000000; |
| 24 | 25 |
| 25 } // namespace | 26 } // namespace |
| 26 | 27 |
| 27 const char kBitmapUploaderForAcceleratedWidget[] = | 28 const char kBitmapUploaderForAcceleratedWidget[] = |
| 28 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; | 29 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; |
| 29 | 30 |
| 30 BitmapUploader::BitmapUploader(Window* window, GpuService* gpu_service) | 31 BitmapUploader::BitmapUploader(Window* window, GpuService* gpu_service) |
| 31 : window_(window), | 32 : window_(window), |
| 32 gpu_service_(gpu_service), | |
| 33 color_(g_transparent_color), | 33 color_(g_transparent_color), |
| 34 width_(0), | 34 width_(0), |
| 35 height_(0), | 35 height_(0), |
| 36 format_(BGRA), | 36 format_(BGRA), |
| 37 next_resource_id_(1u) {} | 37 next_resource_id_(1u) { |
| 38 | |
| 39 BitmapUploader::~BitmapUploader() { | |
| 40 } | |
| 41 | |
| 42 void BitmapUploader::Init() { | |
| 43 surface_ = window_->RequestSurface(mojom::SurfaceType::DEFAULT); | 38 surface_ = window_->RequestSurface(mojom::SurfaceType::DEFAULT); |
| 44 surface_->BindToThread(); | 39 surface_->BindToThread(); |
| 45 surface_->set_client(this); | 40 surface_->set_client(this); |
| 46 | 41 |
| 47 gles2_context_ = GLES2Context::CreateOffscreenContext(gpu_service_); | 42 gles2_context_ = GLES2Context::CreateOffscreenContext( |
| 43 gpu_service->EstablishGpuChannelSync()); | |
|
sky
2016/08/18 13:15:45
Aren't these all rather expensive calls? Seems lik
sadrul
2016/08/18 14:59:48
Done.
| |
| 48 // CreateOffscreenContext() may return null. | 44 // CreateOffscreenContext() may return null. |
|
sky
2016/08/18 13:15:45
Update or remove comment?
sadrul
2016/08/18 14:59:48
Done (removed)
| |
| 49 } | 45 } |
| 50 | 46 |
| 47 BitmapUploader::~BitmapUploader() {} | |
| 48 | |
| 51 // Sets the color which is RGBA. | 49 // Sets the color which is RGBA. |
| 52 void BitmapUploader::SetColor(uint32_t color) { | 50 void BitmapUploader::SetColor(uint32_t color) { |
| 53 if (color_ == color) | 51 if (color_ == color) |
| 54 return; | 52 return; |
| 55 color_ = color; | 53 color_ = color; |
| 56 if (surface_) | 54 if (surface_) |
| 57 Upload(); | 55 Upload(); |
| 58 } | 56 } |
| 59 | 57 |
| 60 // Sets a bitmap. | 58 // Sets a bitmap. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 DCHECK_EQ(1, resource.count); | 192 DCHECK_EQ(1, resource.count); |
| 195 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); | 193 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); |
| 196 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; | 194 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; |
| 197 DCHECK_NE(0u, texture_id); | 195 DCHECK_NE(0u, texture_id); |
| 198 resource_to_texture_id_map_.erase(resource.id); | 196 resource_to_texture_id_map_.erase(resource.id); |
| 199 gl->DeleteTextures(1, &texture_id); | 197 gl->DeleteTextures(1, &texture_id); |
| 200 } | 198 } |
| 201 } | 199 } |
| 202 | 200 |
| 203 } // namespace ui | 201 } // namespace ui |
| OLD | NEW |