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

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

Issue 2092843002: Implement CompositorFrame Struct Traits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed dcheng's comments Created 4 years, 5 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/BUILD.gn ('k') | components/mus/gpu/display_compositor/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 "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 "components/mus/public/cpp/gles2_context.h" 16 #include "components/mus/public/cpp/gles2_context.h"
17 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h"
18 #include "components/mus/public/cpp/window.h" 17 #include "components/mus/public/cpp/window.h"
19 #include "components/mus/public/cpp/window_surface.h" 18 #include "components/mus/public/cpp/window_surface.h"
20 19
21 namespace bitmap_uploader { 20 namespace bitmap_uploader {
22 namespace { 21 namespace {
23 22
24 const uint32_t g_transparent_color = 0x00000000; 23 const uint32_t g_transparent_color = 0x00000000;
25 24
26 } // namespace 25 } // namespace
27 26
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 height_ = height; 67 height_ = height;
69 bitmap_ = std::move(data); 68 bitmap_ = std::move(data);
70 format_ = format; 69 format_ = format;
71 if (surface_) 70 if (surface_)
72 Upload(); 71 Upload();
73 } 72 }
74 73
75 void BitmapUploader::Upload() { 74 void BitmapUploader::Upload() {
76 const gfx::Rect bounds(window_->bounds().size()); 75 const gfx::Rect bounds(window_->bounds().size());
77 76
78 cc::mojom::CompositorFramePtr frame = cc::mojom::CompositorFrame::New(); 77 cc::CompositorFrame frame;
79 // TODO(rjkroege): Support device scale factors other than 1. 78 // TODO(rjkroege): Support device scale factors other than 1.
80 frame->metadata.device_scale_factor = 1.0f; 79 frame.metadata.device_scale_factor = 1.0f;
81 frame->resources.resize(0u); 80 frame.delegated_frame_data.reset(new cc::DelegatedFrameData());
81 frame.delegated_frame_data->resource_list.resize(0u);
82 82
83 const cc::RenderPassId render_pass_id(1, 1); 83 const cc::RenderPassId render_pass_id(1, 1);
84 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); 84 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
85 pass->SetAll(render_pass_id, bounds, bounds, gfx::Transform(), 85 pass->SetAll(render_pass_id, bounds, bounds, gfx::Transform(),
86 true /* has_transparent_background */); 86 true /* has_transparent_background */);
87 87
88 // The SharedQuadState is owned by the SharedQuadStateList 88 // The SharedQuadState is owned by the SharedQuadStateList
89 // shared_quad_state_list. 89 // shared_quad_state_list.
90 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); 90 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
91 sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds, 91 sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds,
(...skipping 22 matching lines...) Expand all
114 resource.id = next_resource_id_++; 114 resource.id = next_resource_id_++;
115 resource_to_texture_id_map_[resource.id] = texture_id; 115 resource_to_texture_id_map_[resource.id] = texture_id;
116 resource.format = cc::ResourceFormat::RGBA_8888; 116 resource.format = cc::ResourceFormat::RGBA_8888;
117 resource.filter = GL_LINEAR; 117 resource.filter = GL_LINEAR;
118 resource.size = bitmap_size; 118 resource.size = bitmap_size;
119 resource.mailbox_holder = 119 resource.mailbox_holder =
120 gpu::MailboxHolder(mailbox, sync_token, GL_TEXTURE_2D); 120 gpu::MailboxHolder(mailbox, sync_token, GL_TEXTURE_2D);
121 resource.read_lock_fences_enabled = false; 121 resource.read_lock_fences_enabled = false;
122 resource.is_software = false; 122 resource.is_software = false;
123 resource.is_overlay_candidate = false; 123 resource.is_overlay_candidate = false;
124 frame->resources.push_back(std::move(resource)); 124 frame.delegated_frame_data->resource_list.push_back(std::move(resource));
125 125
126 cc::TextureDrawQuad* quad = 126 cc::TextureDrawQuad* quad =
127 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); 127 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>();
128 128
129 gfx::Size rect_size; 129 gfx::Size rect_size;
130 if (width_ <= bounds.width() && height_ <= bounds.height()) { 130 if (width_ <= bounds.width() && height_ <= bounds.height()) {
131 rect_size.SetSize(width_, height_); 131 rect_size.SetSize(width_, height_);
132 } else { 132 } else {
133 // The source bitmap is larger than the viewport. Resize it while 133 // The source bitmap is larger than the viewport. Resize it while
134 // maintaining the aspect ratio. 134 // maintaining the aspect ratio.
(...skipping 22 matching lines...) Expand all
157 if (color_ != g_transparent_color) { 157 if (color_ != g_transparent_color) {
158 cc::SolidColorDrawQuad* quad = 158 cc::SolidColorDrawQuad* quad =
159 pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); 159 pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>();
160 const bool force_antialiasing_off = false; 160 const bool force_antialiasing_off = false;
161 const gfx::Rect opaque_rect(0, 0, 0, 0); 161 const gfx::Rect opaque_rect(0, 0, 0, 0);
162 const bool needs_blending = true; 162 const bool needs_blending = true;
163 quad->SetAll(sqs, bounds, opaque_rect, bounds, needs_blending, color_, 163 quad->SetAll(sqs, bounds, opaque_rect, bounds, needs_blending, color_,
164 force_antialiasing_off); 164 force_antialiasing_off);
165 } 165 }
166 166
167 frame->passes.push_back(std::move(pass)); 167 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass));
168 168
169 // TODO(rjkroege, fsamuel): We should throttle frames. 169 // TODO(rjkroege, fsamuel): We should throttle frames.
170 surface_->SubmitCompositorFrame(std::move(frame), base::Closure()); 170 surface_->SubmitCompositorFrame(std::move(frame), base::Closure());
171 } 171 }
172 172
173 uint32_t BitmapUploader::BindTextureForSize(const gfx::Size& size) { 173 uint32_t BitmapUploader::BindTextureForSize(const gfx::Size& size) {
174 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); 174 gpu::gles2::GLES2Interface* gl = gles2_context_->interface();
175 // TODO(jamesr): Recycle textures. 175 // TODO(jamesr): Recycle textures.
176 GLuint texture = 0u; 176 GLuint texture = 0u;
177 gl->GenTextures(1, &texture); 177 gl->GenTextures(1, &texture);
(...skipping 20 matching lines...) Expand all
198 DCHECK_EQ(1, resource.count); 198 DCHECK_EQ(1, resource.count);
199 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); 199 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData());
200 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; 200 uint32_t texture_id = resource_to_texture_id_map_[resource.id];
201 DCHECK_NE(0u, texture_id); 201 DCHECK_NE(0u, texture_id);
202 resource_to_texture_id_map_.erase(resource.id); 202 resource_to_texture_id_map_.erase(resource.id);
203 gl->DeleteTextures(1, &texture_id); 203 gl->DeleteTextures(1, &texture_id);
204 } 204 }
205 } 205 }
206 206
207 } // namespace bitmap_uploader 207 } // namespace bitmap_uploader
OLDNEW
« no previous file with comments | « components/bitmap_uploader/BUILD.gn ('k') | components/mus/gpu/display_compositor/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698