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 "components/bitmap_uploader/bitmap_uploader.h" | 5 #include "components/bitmap_uploader/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 "components/mus/public/cpp/gles2_context.h" | 12 #include "components/mus/public/cpp/gles2_context.h" |
| 13 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" | 13 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" |
| 14 #include "components/mus/public/cpp/surfaces/surfaces_utils.h" | 14 #include "components/mus/public/cpp/surfaces/surfaces_utils.h" |
| 15 #include "components/mus/public/cpp/window.h" | 15 #include "components/mus/public/cpp/window.h" |
| 16 #include "components/mus/public/cpp/window_surface.h" | 16 #include "components/mus/public/cpp/window_surface.h" |
| 17 #include "services/shell/public/cpp/connector.h" | |
| 18 | 17 |
| 19 namespace bitmap_uploader { | 18 namespace bitmap_uploader { |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 const uint32_t g_transparent_color = 0x00000000; | 21 const uint32_t g_transparent_color = 0x00000000; |
| 23 | 22 |
| 24 } // namespace | 23 } // namespace |
| 25 | 24 |
| 26 const char kBitmapUploaderForAcceleratedWidget[] = | 25 const char kBitmapUploaderForAcceleratedWidget[] = |
| 27 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; | 26 "__BITMAP_UPLOADER_ACCELERATED_WIDGET__"; |
| 28 | 27 |
| 29 BitmapUploader::BitmapUploader(mus::Window* window) | 28 BitmapUploader::BitmapUploader(mus::Window* window) |
| 30 : window_(window), | 29 : window_(window), |
| 31 color_(g_transparent_color), | 30 color_(g_transparent_color), |
| 32 width_(0), | 31 width_(0), |
| 33 height_(0), | 32 height_(0), |
| 34 format_(BGRA), | 33 format_(BGRA), |
| 35 next_resource_id_(1u), | 34 next_resource_id_(1u), |
| 36 id_namespace_(0u) {} | 35 id_namespace_(0u) {} |
| 37 | 36 |
| 38 BitmapUploader::~BitmapUploader() { | 37 BitmapUploader::~BitmapUploader() { |
| 39 } | 38 } |
| 40 | 39 |
| 41 void BitmapUploader::Init(shell::Connector* connector) { | 40 void BitmapUploader::Init(shell::Connector* connector) { |
|
sky
2016/06/01 15:45:29
Isn't this in services, which you also removed the
Peng
2016/06/01 16:23:21
Yes. But this file just passes it as incomplete po
| |
| 42 surface_ = window_->RequestSurface(mus::mojom::SurfaceType::DEFAULT); | 41 surface_ = window_->RequestSurface(mus::mojom::SurfaceType::DEFAULT); |
| 43 surface_->BindToThread(); | 42 surface_->BindToThread(); |
| 44 surface_->set_client(this); | 43 surface_->set_client(this); |
| 45 | 44 |
| 46 connector->ConnectToInterface("mojo:mus", &gpu_service_); | 45 gles2_context_ = mus::GLES2Context::CreateOffscreenContext( |
| 47 mus::mojom::CommandBufferPtr command_buffer_ptr; | 46 std::vector<int32_t>(), connector); |
| 48 gpu_service_->CreateOffscreenGLES2Context(GetProxy(&command_buffer_ptr)); | 47 DCHECK(gles2_context_); |
| 49 gles2_context_.reset(new mus::GLES2Context(std::vector<int32_t>(), | |
| 50 std::move(command_buffer_ptr))); | |
| 51 DCHECK(gles2_context_->Initialize()); | |
| 52 } | 48 } |
| 53 | 49 |
| 54 // Sets the color which is RGBA. | 50 // Sets the color which is RGBA. |
| 55 void BitmapUploader::SetColor(uint32_t color) { | 51 void BitmapUploader::SetColor(uint32_t color) { |
| 56 if (color_ == color) | 52 if (color_ == color) |
| 57 return; | 53 return; |
| 58 color_ = color; | 54 color_ = color; |
| 59 if (surface_) | 55 if (surface_) |
| 60 Upload(); | 56 Upload(); |
| 61 } | 57 } |
| 62 | 58 |
| 63 // Sets a bitmap. | 59 // Sets a bitmap. |
| 64 void BitmapUploader::SetBitmap(int width, | 60 void BitmapUploader::SetBitmap(int width, |
| 65 int height, | 61 int height, |
| 66 std::unique_ptr<std::vector<unsigned char>> data, | 62 std::unique_ptr<std::vector<unsigned char>> data, |
| 67 Format format) { | 63 Format format) { |
| 68 width_ = width; | 64 width_ = width; |
| 69 height_ = height; | 65 height_ = height; |
| 70 bitmap_ = std::move(data); | 66 bitmap_ = std::move(data); |
| 71 format_ = format; | 67 format_ = format; |
| 72 if (surface_) | 68 if (surface_) |
| 73 Upload(); | 69 Upload(); |
| 74 } | 70 } |
| 75 | 71 |
| 76 void BitmapUploader::Upload() { | 72 void BitmapUploader::Upload() { |
| 77 // If the |gpu_service_| has errored than we won't get far. Do nothing, | |
| 78 // assuming we are in shutdown. | |
| 79 if (gpu_service_.encountered_error()) | |
| 80 return; | |
| 81 | |
| 82 const gfx::Rect bounds(window_->bounds()); | 73 const gfx::Rect bounds(window_->bounds()); |
| 83 mus::mojom::PassPtr pass = mojo::CreateDefaultPass(1, bounds); | 74 mus::mojom::PassPtr pass = mojo::CreateDefaultPass(1, bounds); |
| 84 mus::mojom::CompositorFramePtr frame = mus::mojom::CompositorFrame::New(); | 75 mus::mojom::CompositorFramePtr frame = mus::mojom::CompositorFrame::New(); |
| 85 | 76 |
| 86 // TODO(rjkroege): Support device scale factor in PDF viewer | 77 // TODO(rjkroege): Support device scale factor in PDF viewer |
| 87 mus::mojom::CompositorFrameMetadataPtr meta = | 78 mus::mojom::CompositorFrameMetadataPtr meta = |
| 88 mus::mojom::CompositorFrameMetadata::New(); | 79 mus::mojom::CompositorFrameMetadata::New(); |
| 89 meta->device_scale_factor = 1.0f; | 80 meta->device_scale_factor = 1.0f; |
| 90 frame->metadata = std::move(meta); | 81 frame->metadata = std::move(meta); |
| 91 | 82 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 DCHECK_EQ(1, resource.count); | 209 DCHECK_EQ(1, resource.count); |
| 219 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); | 210 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); |
| 220 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; | 211 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; |
| 221 DCHECK_NE(0u, texture_id); | 212 DCHECK_NE(0u, texture_id); |
| 222 resource_to_texture_id_map_.erase(resource.id); | 213 resource_to_texture_id_map_.erase(resource.id); |
| 223 gl->DeleteTextures(1, &texture_id); | 214 gl->DeleteTextures(1, &texture_id); |
| 224 } | 215 } |
| 225 } | 216 } |
| 226 | 217 |
| 227 } // namespace bitmap_uploader | 218 } // namespace bitmap_uploader |
| OLD | NEW |