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 "cc/ipc/compositor_frame.mojom.h" | 12 #include "cc/ipc/compositor_frame.mojom.h" |
13 #include "cc/quads/render_pass.h" | |
14 #include "cc/quads/solid_color_draw_quad.h" | |
15 #include "cc/quads/texture_draw_quad.h" | |
13 #include "components/mus/public/cpp/gles2_context.h" | 16 #include "components/mus/public/cpp/gles2_context.h" |
14 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" | 17 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" |
15 #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; |
23 | 25 |
24 } // namespace | 26 } // namespace |
25 | 27 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 Format format) { | 66 Format format) { |
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().size()); |
danakj
2016/06/22 20:51:35
is there a test for this behaviour change?
Fady Samuel
2016/06/22 21:41:19
Unfortunately bitmap_uploader lacks tests. I'll wr
| |
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(); |
85 cc::SharedQuadState* sqs = | 85 pass->SetAll(cc::RenderPassId(1, 1), bounds, bounds, gfx::Transform(), |
86 pass->shared_quad_states.AllocateAndConstruct<cc::SharedQuadState>(); | 86 true /* has_transparent_background */); |
87 mojo::ConfigureSharedQuadState(bounds.size(), sqs); | 87 |
88 // The SharedQuadState is owned by the SharedQuadStateList | |
89 // shared_quad_state_list. | |
90 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | |
91 sqs->SetAll(gfx::Transform(), bounds.size(), bounds, bounds, | |
92 false /* is_clipped */, 1.f /* opacity */, SkXfermode::kSrc_Mode, | |
93 0 /* sorting_context_id */); | |
88 | 94 |
89 if (bitmap_.get()) { | 95 if (bitmap_.get()) { |
90 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); | 96 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); |
91 gfx::Size bitmap_size(width_, height_); | 97 gfx::Size bitmap_size(width_, height_); |
92 GLuint texture_id = BindTextureForSize(bitmap_size); | 98 GLuint texture_id = BindTextureForSize(bitmap_size); |
93 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap_size.width(), | 99 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap_size.width(), |
94 bitmap_size.height(), TextureFormat(), GL_UNSIGNED_BYTE, | 100 bitmap_size.height(), TextureFormat(), GL_UNSIGNED_BYTE, |
95 &((*bitmap_)[0])); | 101 &((*bitmap_)[0])); |
96 | 102 |
97 gpu::Mailbox mailbox; | 103 gpu::Mailbox mailbox; |
(...skipping 10 matching lines...) Expand all Loading... | |
108 resource.id = next_resource_id_++; | 114 resource.id = next_resource_id_++; |
109 resource_to_texture_id_map_[resource.id] = texture_id; | 115 resource_to_texture_id_map_[resource.id] = texture_id; |
110 resource.format = cc::ResourceFormat::RGBA_8888; | 116 resource.format = cc::ResourceFormat::RGBA_8888; |
111 resource.filter = GL_LINEAR; | 117 resource.filter = GL_LINEAR; |
112 resource.size = bitmap_size; | 118 resource.size = bitmap_size; |
113 resource.mailbox_holder = | 119 resource.mailbox_holder = |
114 gpu::MailboxHolder(mailbox, sync_token, GL_TEXTURE_2D); | 120 gpu::MailboxHolder(mailbox, sync_token, GL_TEXTURE_2D); |
115 resource.read_lock_fences_enabled = false; | 121 resource.read_lock_fences_enabled = false; |
116 resource.is_software = false; | 122 resource.is_software = false; |
117 resource.is_overlay_candidate = false; | 123 resource.is_overlay_candidate = false; |
124 frame->resources.push_back(std::move(resource)); | |
118 | 125 |
119 cc::mojom::DrawQuadPtr quad = cc::mojom::DrawQuad::New(); | 126 cc::TextureDrawQuad* quad = |
120 quad->material = cc::mojom::Material::TEXTURE_CONTENT; | 127 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); |
121 | 128 |
122 gfx::Size rect_size; | 129 gfx::Size rect_size; |
123 if (width_ <= bounds.width() && height_ <= bounds.height()) { | 130 if (width_ <= bounds.width() && height_ <= bounds.height()) { |
124 rect_size.SetSize(width_, height_); | 131 rect_size.SetSize(width_, height_); |
125 } else { | 132 } else { |
126 // The source bitmap is larger than the viewport. Resize it while | 133 // The source bitmap is larger than the viewport. Resize it while |
127 // maintaining the aspect ratio. | 134 // maintaining the aspect ratio. |
128 float width_ratio = static_cast<float>(width_) / bounds.width(); | 135 float width_ratio = static_cast<float>(width_) / bounds.width(); |
129 float height_ratio = static_cast<float>(height_) / bounds.height(); | 136 float height_ratio = static_cast<float>(height_) / bounds.height(); |
130 if (width_ratio > height_ratio) { | 137 if (width_ratio > height_ratio) { |
131 rect_size.SetSize(bounds.width(), height_ / width_ratio); | 138 rect_size.SetSize(bounds.width(), height_ / width_ratio); |
132 } else { | 139 } else { |
133 rect_size.SetSize(width_ / height_ratio, bounds.height()); | 140 rect_size.SetSize(width_ / height_ratio, bounds.height()); |
134 } | 141 } |
135 } | 142 } |
136 gfx::Rect rect(rect_size); | 143 gfx::Rect rect(rect_size); |
137 quad->rect = rect; | 144 const bool needs_blending = true; |
138 quad->opaque_rect = rect; | 145 const bool premultiplied_alpha = true; |
139 quad->visible_rect = rect; | 146 const gfx::PointF uv_top_left(0.f, 0.f); |
140 quad->needs_blending = true; | 147 const gfx::PointF uv_bottom_right(1.f, 1.f); |
141 quad->shared_quad_state_index = 0u; | 148 float vertex_opacity[4] = {1.f, 1.f, 1.f, 1.f}; |
142 | 149 const bool y_flipped = false; |
143 cc::mojom::TextureQuadStatePtr texture_state = | 150 const bool nearest_neighbor = false; |
144 cc::mojom::TextureQuadState::New(); | 151 quad->SetAll(sqs, rect, rect, rect, needs_blending, resource.id, |
145 texture_state->resource_id = resource.id; | 152 gfx::Size(), premultiplied_alpha, uv_top_left, uv_bottom_right, |
146 texture_state->premultiplied_alpha = true; | 153 g_transparent_color, vertex_opacity, y_flipped, |
147 texture_state->uv_top_left.SetPoint(0.f, 0.f); | 154 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 } | 155 } |
158 | 156 |
159 if (color_ != g_transparent_color) { | 157 if (color_ != g_transparent_color) { |
160 cc::mojom::DrawQuadPtr quad = cc::mojom::DrawQuad::New(); | 158 cc::SolidColorDrawQuad* quad = |
161 quad->material = cc::mojom::Material::SOLID_COLOR; | 159 pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); |
162 quad->rect = bounds; | 160 const bool force_antialiasing_off = false; |
163 quad->visible_rect = bounds; | 161 const gfx::Rect opaque_rect(0, 0, 0, 0); |
164 quad->needs_blending = true; | 162 const bool needs_blending = true; |
165 quad->shared_quad_state_index = 0u; | 163 quad->SetAll(sqs, bounds, opaque_rect, bounds, needs_blending, color_, |
166 | 164 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 } | 165 } |
175 | 166 |
176 frame->passes.push_back(std::move(pass)); | 167 frame->passes.push_back(std::move(pass)); |
177 | 168 |
178 // TODO(rjkroege, fsamuel): We should throttle frames. | 169 // TODO(rjkroege, fsamuel): We should throttle frames. |
179 surface_->SubmitCompositorFrame(std::move(frame), base::Closure()); | 170 surface_->SubmitCompositorFrame(std::move(frame), base::Closure()); |
180 } | 171 } |
181 | 172 |
182 uint32_t BitmapUploader::BindTextureForSize(const gfx::Size& size) { | 173 uint32_t BitmapUploader::BindTextureForSize(const gfx::Size& size) { |
183 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); | 174 gpu::gles2::GLES2Interface* gl = gles2_context_->interface(); |
(...skipping 23 matching lines...) Expand all Loading... | |
207 DCHECK_EQ(1, resource.count); | 198 DCHECK_EQ(1, resource.count); |
208 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); | 199 gl->WaitSyncTokenCHROMIUM(resource.sync_token.GetConstData()); |
209 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; | 200 uint32_t texture_id = resource_to_texture_id_map_[resource.id]; |
210 DCHECK_NE(0u, texture_id); | 201 DCHECK_NE(0u, texture_id); |
211 resource_to_texture_id_map_.erase(resource.id); | 202 resource_to_texture_id_map_.erase(resource.id); |
212 gl->DeleteTextures(1, &texture_id); | 203 gl->DeleteTextures(1, &texture_id); |
213 } | 204 } |
214 } | 205 } |
215 | 206 |
216 } // namespace bitmap_uploader | 207 } // namespace bitmap_uploader |
OLD | NEW |