Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: components/bitmap_uploader/bitmap_uploader.cc

Issue 1976703003: Impl mus::mojom::GpuService to enable using Chrome IPC version gpu CmdBuf in mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/bitmap_uploader/bitmap_uploader.h ('k') | components/mus/common/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) {
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 bool initialized = gles2_context_->Initialize();
52 DCHECK(initialized);
53 } 48 }
54 49
55 // Sets the color which is RGBA. 50 // Sets the color which is RGBA.
56 void BitmapUploader::SetColor(uint32_t color) { 51 void BitmapUploader::SetColor(uint32_t color) {
57 if (color_ == color) 52 if (color_ == color)
58 return; 53 return;
59 color_ = color; 54 color_ = color;
60 if (surface_) 55 if (surface_)
61 Upload(); 56 Upload();
62 } 57 }
63 58
64 // Sets a bitmap. 59 // Sets a bitmap.
65 void BitmapUploader::SetBitmap(int width, 60 void BitmapUploader::SetBitmap(int width,
66 int height, 61 int height,
67 std::unique_ptr<std::vector<unsigned char>> data, 62 std::unique_ptr<std::vector<unsigned char>> data,
68 Format format) { 63 Format format) {
69 width_ = width; 64 width_ = width;
70 height_ = height; 65 height_ = height;
71 bitmap_ = std::move(data); 66 bitmap_ = std::move(data);
72 format_ = format; 67 format_ = format;
73 if (surface_) 68 if (surface_)
74 Upload(); 69 Upload();
75 } 70 }
76 71
77 void BitmapUploader::Upload() { 72 void BitmapUploader::Upload() {
78 // If the |gpu_service_| has errored than we won't get far. Do nothing,
79 // assuming we are in shutdown.
80 if (gpu_service_.encountered_error())
81 return;
82
83 const gfx::Rect bounds(window_->bounds()); 73 const gfx::Rect bounds(window_->bounds());
84 mus::mojom::PassPtr pass = mojo::CreateDefaultPass(1, bounds); 74 mus::mojom::PassPtr pass = mojo::CreateDefaultPass(1, bounds);
85 mus::mojom::CompositorFramePtr frame = mus::mojom::CompositorFrame::New(); 75 mus::mojom::CompositorFramePtr frame = mus::mojom::CompositorFrame::New();
86 76
87 // TODO(rjkroege): Support device scale factor in PDF viewer 77 // TODO(rjkroege): Support device scale factor in PDF viewer
88 mus::mojom::CompositorFrameMetadataPtr meta = 78 mus::mojom::CompositorFrameMetadataPtr meta =
89 mus::mojom::CompositorFrameMetadata::New(); 79 mus::mojom::CompositorFrameMetadata::New();
90 meta->device_scale_factor = 1.0f; 80 meta->device_scale_factor = 1.0f;
91 frame->metadata = std::move(meta); 81 frame->metadata = std::move(meta);
92 82
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 DCHECK_EQ(1, resource.count); 208 DCHECK_EQ(1, resource.count);
219 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); 209 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData());
220 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; 210 uint32_t texture_id = resource_to_texture_id_map_[resource.id];
221 DCHECK_NE(0u, texture_id); 211 DCHECK_NE(0u, texture_id);
222 resource_to_texture_id_map_.erase(resource.id); 212 resource_to_texture_id_map_.erase(resource.id);
223 gl->DeleteTextures(1, &texture_id); 213 gl->DeleteTextures(1, &texture_id);
224 } 214 }
225 } 215 }
226 216
227 } // namespace bitmap_uploader 217 } // namespace bitmap_uploader
OLDNEW
« no previous file with comments | « components/bitmap_uploader/bitmap_uploader.h ('k') | components/mus/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698