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

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

Issue 2088603002: Implement RenderPass StructTraits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary change 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
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/solid_color_draw_quad.h"
14 #include "cc/quads/texture_draw_quad.h"
13 #include "components/mus/public/cpp/gles2_context.h" 15 #include "components/mus/public/cpp/gles2_context.h"
14 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" 16 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h"
15 #include "components/mus/public/cpp/surfaces/surfaces_utils.h" 17 #include "components/mus/public/cpp/surfaces/surfaces_utils.h"
16 #include "components/mus/public/cpp/window.h" 18 #include "components/mus/public/cpp/window.h"
17 #include "components/mus/public/cpp/window_surface.h" 19 #include "components/mus/public/cpp/window_surface.h"
18 20
19 namespace bitmap_uploader { 21 namespace bitmap_uploader {
20 namespace { 22 namespace {
21 23
22 const uint32_t g_transparent_color = 0x00000000; 24 const uint32_t g_transparent_color = 0x00000000;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 width_ = width; 67 width_ = width;
66 height_ = height; 68 height_ = height;
67 bitmap_ = std::move(data); 69 bitmap_ = std::move(data);
68 format_ = format; 70 format_ = format;
69 if (surface_) 71 if (surface_)
70 Upload(); 72 Upload();
71 } 73 }
72 74
73 void BitmapUploader::Upload() { 75 void BitmapUploader::Upload() {
74 const gfx::Rect bounds(window_->bounds()); 76 const gfx::Rect bounds(window_->bounds());
75 cc::mojom::RenderPassPtr pass = mojo::CreateDefaultPass(1, bounds); 77
76 cc::mojom::CompositorFramePtr frame = cc::mojom::CompositorFrame::New(); 78 cc::mojom::CompositorFramePtr frame = cc::mojom::CompositorFrame::New();
77 79 // TODO(rjkroege): Support device scale factors other than 1.
78 // TODO(rjkroege): Support device scale factor in PDF viewer
79 frame->metadata.device_scale_factor = 1.0f; 80 frame->metadata.device_scale_factor = 1.0f;
80
81 frame->resources.resize(0u); 81 frame->resources.resize(0u);
82 82
83 pass->quads.resize(0u); 83 cc::RenderPassId render_pass_id(1, 1);
84 // The SharedQuadState is owned by the SharedQuadStateList shared_quad_states. 84 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
danakj 2016/06/22 00:06:20 include render_pass.h too then
Fady Samuel 2016/06/22 20:08:15 Done.
85 cc::SharedQuadState* sqs = 85 pass->output_rect = bounds;
danakj 2016/06/22 00:06:21 use SetNew/SetAll
Fady Samuel 2016/06/22 20:08:15 Done.
86 pass->shared_quad_states.AllocateAndConstruct<cc::SharedQuadState>(); 86 pass->damage_rect = bounds;
87 pass->has_transparent_background = true;
88
89 // The SharedQuadState is owned by the SharedQuadStateList
90 // shared_quad_state_list.
91 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
87 mojo::ConfigureSharedQuadState(bounds.size(), sqs); 92 mojo::ConfigureSharedQuadState(bounds.size(), sqs);
88 93
89 if (bitmap_.get()) { 94 if (bitmap_.get()) {
90 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); 95 gpu::gles2::GLES2Interface* gl = gles2_context_->interface();
91 gfx::Size bitmap_size(width_, height_); 96 gfx::Size bitmap_size(width_, height_);
92 GLuint texture_id = BindTextureForSize(bitmap_size); 97 GLuint texture_id = BindTextureForSize(bitmap_size);
93 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap_size.width(), 98 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap_size.width(),
94 bitmap_size.height(), TextureFormat(), GL_UNSIGNED_BYTE, 99 bitmap_size.height(), TextureFormat(), GL_UNSIGNED_BYTE,
95 &((*bitmap_)[0])); 100 &((*bitmap_)[0]));
96 101
(...skipping 11 matching lines...) Expand all
108 resource.id = next_resource_id_++; 113 resource.id = next_resource_id_++;
109 resource_to_texture_id_map_[resource.id] = texture_id; 114 resource_to_texture_id_map_[resource.id] = texture_id;
110 resource.format = cc::ResourceFormat::RGBA_8888; 115 resource.format = cc::ResourceFormat::RGBA_8888;
111 resource.filter = GL_LINEAR; 116 resource.filter = GL_LINEAR;
112 resource.size = bitmap_size; 117 resource.size = bitmap_size;
113 resource.mailbox_holder = 118 resource.mailbox_holder =
114 gpu::MailboxHolder(mailbox, sync_token, GL_TEXTURE_2D); 119 gpu::MailboxHolder(mailbox, sync_token, GL_TEXTURE_2D);
115 resource.read_lock_fences_enabled = false; 120 resource.read_lock_fences_enabled = false;
116 resource.is_software = false; 121 resource.is_software = false;
117 resource.is_overlay_candidate = false; 122 resource.is_overlay_candidate = false;
123 frame->resources.push_back(std::move(resource));
118 124
119 cc::mojom::DrawQuadPtr quad = cc::mojom::DrawQuad::New(); 125 cc::TextureDrawQuad* quad =
120 quad->material = cc::mojom::Material::TEXTURE_CONTENT; 126 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>();
121 127
122 gfx::Size rect_size; 128 gfx::Size rect_size;
123 if (width_ <= bounds.width() && height_ <= bounds.height()) { 129 if (width_ <= bounds.width() && height_ <= bounds.height()) {
124 rect_size.SetSize(width_, height_); 130 rect_size.SetSize(width_, height_);
125 } else { 131 } else {
126 // The source bitmap is larger than the viewport. Resize it while 132 // The source bitmap is larger than the viewport. Resize it while
127 // maintaining the aspect ratio. 133 // maintaining the aspect ratio.
128 float width_ratio = static_cast<float>(width_) / bounds.width(); 134 float width_ratio = static_cast<float>(width_) / bounds.width();
129 float height_ratio = static_cast<float>(height_) / bounds.height(); 135 float height_ratio = static_cast<float>(height_) / bounds.height();
130 if (width_ratio > height_ratio) { 136 if (width_ratio > height_ratio) {
131 rect_size.SetSize(bounds.width(), height_ / width_ratio); 137 rect_size.SetSize(bounds.width(), height_ / width_ratio);
132 } else { 138 } else {
133 rect_size.SetSize(width_ / height_ratio, bounds.height()); 139 rect_size.SetSize(width_ / height_ratio, bounds.height());
134 } 140 }
135 } 141 }
136 gfx::Rect rect(rect_size); 142 gfx::Rect rect(rect_size);
137 quad->rect = rect; 143 const bool needs_blending = true;
138 quad->opaque_rect = rect; 144 const bool premultiplied_alpha = true;
139 quad->visible_rect = rect; 145 const gfx::PointF uv_top_left(0.f, 0.f);
140 quad->needs_blending = true; 146 const gfx::PointF uv_bottom_right(1.f, 1.f);
141 quad->shared_quad_state_index = 0u; 147 float vertex_opacity[4] = {1.f, 1.f, 1.f, 1.f};
142 148 const bool y_flipped = false;
143 cc::mojom::TextureQuadStatePtr texture_state = 149 const bool nearest_neighbor = false;
144 cc::mojom::TextureQuadState::New(); 150 quad->SetAll(sqs, rect, rect, rect, needs_blending, resource.id,
145 texture_state->resource_id = resource.id; 151 gfx::Size(), premultiplied_alpha, uv_top_left, uv_bottom_right,
146 texture_state->premultiplied_alpha = true; 152 g_transparent_color, vertex_opacity, y_flipped,
147 texture_state->uv_top_left.SetPoint(0.f, 0.f); 153 nearest_neighbor, false);
148 texture_state->uv_bottom_right.SetPoint(1.f, 1.f);
149 texture_state->background_color = g_transparent_color;
150 for (int i = 0; i < 4; ++i)
151 texture_state->vertex_opacity.push_back(1.f);
152 texture_state->y_flipped = false;
153
154 frame->resources.push_back(std::move(resource));
155 quad->texture_quad_state = std::move(texture_state);
156 pass->quads.push_back(std::move(quad));
157 } 154 }
158 155
159 if (color_ != g_transparent_color) { 156 if (color_ != g_transparent_color) {
160 cc::mojom::DrawQuadPtr quad = cc::mojom::DrawQuad::New(); 157 cc::SolidColorDrawQuad* quad =
161 quad->material = cc::mojom::Material::SOLID_COLOR; 158 pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>();
162 quad->rect = bounds; 159 const bool force_antialiasing_off = false;
163 quad->visible_rect = bounds; 160 const gfx::Rect opaque_rect(0, 0, 0, 0);
164 quad->needs_blending = true; 161 const bool needs_blending = true;
165 quad->shared_quad_state_index = 0u; 162 quad->SetAll(sqs, bounds, opaque_rect, bounds, needs_blending, color_,
166 163 force_antialiasing_off);
167 cc::mojom::SolidColorQuadStatePtr color_state =
168 cc::mojom::SolidColorQuadState::New();
169 color_state->color = color_;
170 color_state->force_anti_aliasing_off = false;
171
172 quad->solid_color_quad_state = std::move(color_state);
173 pass->quads.push_back(std::move(quad));
174 } 164 }
175 165
176 frame->passes.push_back(std::move(pass)); 166 frame->passes.push_back(std::move(pass));
177 167
178 // TODO(rjkroege, fsamuel): We should throttle frames. 168 // TODO(rjkroege, fsamuel): We should throttle frames.
179 surface_->SubmitCompositorFrame(std::move(frame), base::Closure()); 169 surface_->SubmitCompositorFrame(std::move(frame), base::Closure());
180 } 170 }
181 171
182 uint32_t BitmapUploader::BindTextureForSize(const gfx::Size& size) { 172 uint32_t BitmapUploader::BindTextureForSize(const gfx::Size& size) {
183 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); 173 gpu::gles2::GLES2Interface* gl = gles2_context_->interface();
(...skipping 23 matching lines...) Expand all
207 DCHECK_EQ(1, resource.count); 197 DCHECK_EQ(1, resource.count);
208 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); 198 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData());
209 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; 199 uint32_t texture_id = resource_to_texture_id_map_[resource.id];
210 DCHECK_NE(0u, texture_id); 200 DCHECK_NE(0u, texture_id);
211 resource_to_texture_id_map_.erase(resource.id); 201 resource_to_texture_id_map_.erase(resource.id);
212 gl->DeleteTextures(1, &texture_id); 202 gl->DeleteTextures(1, &texture_id);
213 } 203 }
214 } 204 }
215 205
216 } // namespace bitmap_uploader 206 } // namespace bitmap_uploader
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698