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

Side by Side Diff: ash/laser/laser_pointer_view.cc

Issue 2714393002: ash: Low-latency laser pointer. (Closed)
Patch Set: remove :surfaces Created 3 years, 9 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 | « ash/laser/laser_pointer_view.h ('k') | mash/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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ash/laser/laser_pointer_view.h" 5 #include "ash/laser/laser_pointer_view.h"
6 6
7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h>
9 #include <GLES2/gl2extchromium.h>
10
7 #include <memory> 11 #include <memory>
8 12
9 #include "ash/laser/laser_pointer_points.h" 13 #include "ash/laser/laser_pointer_points.h"
10 #include "ash/laser/laser_segment_utils.h" 14 #include "ash/laser/laser_segment_utils.h"
11 #include "ash/public/cpp/shell_window_ids.h" 15 #include "ash/public/cpp/shell_window_ids.h"
12 #include "ash/shell.h" 16 #include "ash/shell.h"
17 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/timer/timer.h" 18 #include "base/timer/timer.h"
19 #include "base/trace_event/trace_event.h"
20 #include "cc/output/context_provider.h"
21 #include "cc/quads/texture_draw_quad.h"
22 #include "cc/resources/transferable_resource.h"
23 #include "cc/surfaces/surface.h"
24 #include "cc/surfaces/surface_manager.h"
25 #include "gpu/command_buffer/client/context_support.h"
26 #include "gpu/command_buffer/client/gles2_interface.h"
27 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
14 #include "third_party/skia/include/core/SkColor.h" 28 #include "third_party/skia/include/core/SkColor.h"
29 #include "third_party/skia/include/core/SkTypes.h"
30 #include "ui/aura/env.h"
15 #include "ui/aura/window.h" 31 #include "ui/aura/window.h"
32 #include "ui/display/display.h"
33 #include "ui/display/screen.h"
16 #include "ui/events/event.h" 34 #include "ui/events/event.h"
17 #include "ui/gfx/canvas.h" 35 #include "ui/gfx/canvas.h"
36 #include "ui/gfx/gpu_memory_buffer.h"
18 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
19 38
20 namespace ash { 39 namespace ash {
21 namespace { 40 namespace {
22 41
23 // Variables for rendering the laser. Radius in DIP. 42 // Variables for rendering the laser. Radius in DIP.
24 const float kPointInitialRadius = 5.0f; 43 const float kPointInitialRadius = 5.0f;
25 const float kPointFinalRadius = 0.25f; 44 const float kPointFinalRadius = 0.25f;
26 const int kPointInitialOpacity = 200; 45 const int kPointInitialOpacity = 200;
27 const int kPointFinalOpacity = 10; 46 const int kPointFinalOpacity = 10;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 SkPath path() const { return path_; } 169 SkPath path() const { return path_; }
151 std::vector<gfx::PointF> path_points() const { return path_points_; } 170 std::vector<gfx::PointF> path_points() const { return path_points_; }
152 171
153 private: 172 private:
154 SkPath path_; 173 SkPath path_;
155 std::vector<gfx::PointF> path_points_; 174 std::vector<gfx::PointF> path_points_;
156 175
157 DISALLOW_COPY_AND_ASSIGN(LaserSegment); 176 DISALLOW_COPY_AND_ASSIGN(LaserSegment);
158 }; 177 };
159 178
179 // This struct contains the resources associated with a laser pointer frame.
180 struct LaserResource {
181 LaserResource() {}
182 ~LaserResource() {
183 if (context_provider) {
184 gpu::gles2::GLES2Interface* gles2 = context_provider->ContextGL();
185 if (texture)
186 gles2->DeleteTextures(1, &texture);
187 if (image)
188 gles2->DestroyImageCHROMIUM(image);
189 }
190 }
191 scoped_refptr<cc::ContextProvider> context_provider;
192 uint32_t texture = 0;
193 uint32_t image = 0;
194 gpu::Mailbox mailbox;
195 };
196
160 // LaserPointerView 197 // LaserPointerView
161 LaserPointerView::LaserPointerView(base::TimeDelta life_duration, 198 LaserPointerView::LaserPointerView(base::TimeDelta life_duration,
162 aura::Window* root_window) 199 aura::Window* root_window)
163 : laser_points_(life_duration) { 200 : laser_points_(life_duration),
201 frame_sink_id_(aura::Env::GetInstance()
202 ->context_factory_private()
203 ->AllocateFrameSinkId()),
204 frame_sink_support_(this,
205 aura::Env::GetInstance()
206 ->context_factory_private()
207 ->GetSurfaceManager(),
208 frame_sink_id_,
209 false /* is_root */,
210 true /* handles_frame_sink_id_invalidation */,
211 true /* needs_sync_points */),
212 weak_ptr_factory_(this) {
164 widget_.reset(new views::Widget); 213 widget_.reset(new views::Widget);
165 views::Widget::InitParams params; 214 views::Widget::InitParams params;
166 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; 215 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
167 params.name = "LaserOverlay"; 216 params.name = "LaserOverlay";
168 params.accept_events = false; 217 params.accept_events = false;
169 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; 218 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
170 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 219 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
171 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 220 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
172 params.parent = 221 params.parent =
173 Shell::GetContainer(root_window, kShellWindowId_OverlayContainer); 222 Shell::GetContainer(root_window, kShellWindowId_OverlayContainer);
223 params.layer_type = ui::LAYER_SOLID_COLOR;
174 224
175 widget_->Init(params); 225 widget_->Init(params);
176 widget_->Show(); 226 widget_->Show();
177 widget_->SetContentsView(this); 227 widget_->SetContentsView(this);
228 widget_->SetBounds(root_window->GetBoundsInScreen());
178 set_owned_by_client(); 229 set_owned_by_client();
230
231 scale_factor_ = display::Screen::GetScreen()
232 ->GetDisplayNearestWindow(widget_->GetNativeView())
233 .device_scale_factor();
179 } 234 }
180 235
181 LaserPointerView::~LaserPointerView() {} 236 LaserPointerView::~LaserPointerView() {
237 // Make sure GPU memory buffer is unmapped before being destroyed.
238 if (gpu_memory_buffer_)
239 gpu_memory_buffer_->Unmap();
240 }
182 241
183 void LaserPointerView::Stop() { 242 void LaserPointerView::Stop() {
243 buffer_damage_rect_.Union(GetBoundingBox());
184 laser_points_.Clear(); 244 laser_points_.Clear();
185 SchedulePaint(); 245 OnPointsUpdated();
186 } 246 }
187 247
188 void LaserPointerView::AddNewPoint(const gfx::Point& new_point) { 248 void LaserPointerView::AddNewPoint(const gfx::Point& new_point) {
249 buffer_damage_rect_.Union(GetBoundingBox());
189 laser_points_.AddPoint(new_point); 250 laser_points_.AddPoint(new_point);
251 buffer_damage_rect_.Union(GetBoundingBox());
190 OnPointsUpdated(); 252 OnPointsUpdated();
191 } 253 }
192 254
193 void LaserPointerView::UpdateTime() { 255 void LaserPointerView::UpdateTime() {
256 buffer_damage_rect_.Union(GetBoundingBox());
194 // Do not add the point but advance the time if the view is in process of 257 // Do not add the point but advance the time if the view is in process of
195 // fading away. 258 // fading away.
196 laser_points_.MoveForwardToTime(base::Time::Now()); 259 laser_points_.MoveForwardToTime(base::Time::Now());
260 buffer_damage_rect_.Union(GetBoundingBox());
197 OnPointsUpdated(); 261 OnPointsUpdated();
198 } 262 }
199 263
200 void LaserPointerView::OnPointsUpdated() { 264 void LaserPointerView::SetNeedsBeginFrame(bool needs_begin_frame) {
201 // The bounding box should be relative to the screen. 265 frame_sink_support_.SetNeedsBeginFrame(needs_begin_frame);
202 gfx::Point screen_offset =
203 widget_->GetNativeView()->GetRootWindow()->GetBoundsInScreen().origin();
204
205 // Expand the bounding box so that it includes the radius of the points on the
206 // edges.
207 gfx::Rect bounding_box;
208 bounding_box = laser_points_.GetBoundingBox();
209 bounding_box.Offset(-kPointInitialRadius, -kPointInitialRadius);
210 bounding_box.Offset(screen_offset.x(), screen_offset.y());
211 bounding_box.set_width(bounding_box.width() + (kPointInitialRadius * 2));
212 bounding_box.set_height(bounding_box.height() + (kPointInitialRadius * 2));
213 widget_->SetBounds(bounding_box);
214 SchedulePaint();
215 } 266 }
216 267
217 void LaserPointerView::OnPaint(gfx::Canvas* canvas) { 268 void LaserPointerView::SubmitCompositorFrame(
218 if (laser_points_.IsEmpty()) 269 const cc::LocalSurfaceId& local_surface_id,
270 cc::CompositorFrame frame) {
271 frame_sink_support_.SubmitCompositorFrame(local_surface_id, std::move(frame));
272 }
273
274 void LaserPointerView::EvictFrame() {
275 frame_sink_support_.EvictFrame();
276 }
277
278 void LaserPointerView::DidReceiveCompositorFrameAck() {
279 base::ThreadTaskRunnerHandle::Get()->PostTask(
280 FROM_HERE, base::Bind(&LaserPointerView::OnDidDrawSurface,
281 weak_ptr_factory_.GetWeakPtr()));
282 }
283
284 void LaserPointerView::ReclaimResources(
285 const cc::ReturnedResourceArray& resources) {
286 DCHECK_EQ(resources.size(), 1u);
287
288 auto it = resources_.find(resources.front().id);
289 DCHECK(it != resources_.end());
290 std::unique_ptr<LaserResource> resource = std::move(it->second);
291 resources_.erase(it);
292
293 gpu::gles2::GLES2Interface* gles2 = resource->context_provider->ContextGL();
294 if (resources.front().sync_token.HasData())
295 gles2->WaitSyncTokenCHROMIUM(resources.front().sync_token.GetConstData());
296
297 if (!resources.front().lost)
298 returned_resources_.push_back(std::move(resource));
299 }
300
301 gfx::Rect LaserPointerView::GetBoundingBox() {
302 // Expand the bounding box so that it includes the radius of the points on the
303 // edges and antialiasing.
304 gfx::Rect bounding_box = laser_points_.GetBoundingBox();
305 const int kOutsetForAntialiasing = 1;
306 int outset = kPointInitialRadius + kOutsetForAntialiasing;
307 bounding_box.Inset(-outset, -outset);
308 return bounding_box;
309 }
310
311 void LaserPointerView::OnPointsUpdated() {
312 if (pending_update_buffer_)
219 return; 313 return;
220 314
315 pending_update_buffer_ = true;
316 base::ThreadTaskRunnerHandle::Get()->PostTask(
317 FROM_HERE, base::Bind(&LaserPointerView::UpdateBuffer,
318 weak_ptr_factory_.GetWeakPtr()));
319 }
320
321 void LaserPointerView::UpdateBuffer() {
322 TRACE_EVENT2("ui", "LaserPointerView::UpdatedBuffer", "damage",
323 buffer_damage_rect_.ToString(), "points",
324 laser_points_.GetNumberOfPoints());
325
326 DCHECK(pending_update_buffer_);
327 pending_update_buffer_ = false;
328
329 gfx::Rect screen_bounds = widget_->GetNativeView()->GetBoundsInScreen();
330 gfx::Rect update_rect = buffer_damage_rect_;
331 buffer_damage_rect_ = gfx::Rect();
332
333 // Create and map a single GPU memory buffer. The laser pointer will be
334 // written into this buffer without any buffering. The result is that we
335 // might be modifying the buffer while it's being displayed. This provides
336 // minimal latency but potential tearing. Note that we have to draw into
337 // a temporary surface and copy it into GPU memory buffer to avoid flicker.
338 if (!gpu_memory_buffer_) {
339 gpu_memory_buffer_ =
340 aura::Env::GetInstance()
341 ->context_factory()
342 ->GetGpuMemoryBufferManager()
343 ->CreateGpuMemoryBuffer(
344 gfx::ScaleToCeiledSize(screen_bounds.size(), scale_factor_),
345 SK_B32_SHIFT ? gfx::BufferFormat::RGBA_8888
346 : gfx::BufferFormat::BGRA_8888,
347 gfx::BufferUsage::SCANOUT_CPU_READ_WRITE,
348 gpu::kNullSurfaceHandle);
349 if (!gpu_memory_buffer_) {
350 LOG(ERROR) << "Failed to allocate GPU memory buffer";
351 return;
352 }
353
354 // Map buffer and keep it mapped until destroyed.
355 bool rv = gpu_memory_buffer_->Map();
356 if (!rv) {
357 LOG(ERROR) << "Failed to map GPU memory buffer";
358 return;
359 }
360
361 // Make sure the first update rectangle covers the whole buffer.
362 update_rect = gfx::Rect(screen_bounds.size());
363 }
364
365 // Constrain update rectangle to buffer size and early out if empty.
366 update_rect.Intersect(gfx::Rect(screen_bounds.size()));
367 if (update_rect.IsEmpty())
368 return;
369
370 // Create a temporary canvas for update rectangle.
371 gfx::Canvas canvas(update_rect.size(), scale_factor_, false);
372
221 cc::PaintFlags flags; 373 cc::PaintFlags flags;
222 flags.setStyle(cc::PaintFlags::kFill_Style); 374 flags.setStyle(cc::PaintFlags::kFill_Style);
223 flags.setAntiAlias(true); 375 flags.setAntiAlias(true);
224 376
225 // Compute the offset of the current widget. 377 // Compute the offset of the current widget.
226 gfx::Vector2d widget_offset( 378 gfx::Vector2d widget_offset(
227 widget_->GetNativeView()->GetBoundsInRootWindow().origin().x(), 379 widget_->GetNativeView()->GetBoundsInRootWindow().origin().x(),
228 widget_->GetNativeView()->GetBoundsInRootWindow().origin().y()); 380 widget_->GetNativeView()->GetBoundsInRootWindow().origin().y());
229 381
230 int num_points = laser_points_.GetNumberOfPoints(); 382 int num_points = laser_points_.GetNumberOfPoints();
231 DCHECK(num_points > 0); 383 if (num_points) {
232 LaserPointerPoints::LaserPoint previous_point = laser_points_.GetOldest(); 384 LaserPointerPoints::LaserPoint previous_point = laser_points_.GetOldest();
233 previous_point.location -= widget_offset; 385 previous_point.location -= widget_offset + update_rect.OffsetFromOrigin();
234 LaserPointerPoints::LaserPoint current_point; 386 LaserPointerPoints::LaserPoint current_point;
235 std::vector<gfx::PointF> previous_segment_points; 387 std::vector<gfx::PointF> previous_segment_points;
236 float previous_radius; 388 float previous_radius;
237 int current_opacity; 389 int current_opacity;
238 390
239 for (int i = 0; i < num_points; ++i) { 391 for (int i = 0; i < num_points; ++i) {
240 current_point = laser_points_.laser_points()[i]; 392 current_point = laser_points_.laser_points()[i];
241 current_point.location -= widget_offset; 393 current_point.location -= widget_offset + update_rect.OffsetFromOrigin();
242 394
243 // Set the radius and opacity based on the distance. 395 // Set the radius and opacity based on the distance.
244 float current_radius = LinearInterpolate( 396 float current_radius = LinearInterpolate(
245 kPointInitialRadius, kPointFinalRadius, current_point.age); 397 kPointInitialRadius, kPointFinalRadius, current_point.age);
246 current_opacity = int{LinearInterpolate( 398 current_opacity = int{LinearInterpolate(
247 kPointInitialOpacity, kPointFinalOpacity, current_point.age)}; 399 kPointInitialOpacity, kPointFinalOpacity, current_point.age)};
248 400
249 // If we draw laser_points_ that are within a stroke width of each other, 401 // If we draw laser_points_ that are within a stroke width of each other,
250 // the result will be very jagged, unless we are on the last point, then we 402 // the result will be very jagged, unless we are on the last point, then
251 // draw regardless. 403 // we draw regardless.
252 float distance_threshold = current_radius * 2.0f; 404 float distance_threshold = current_radius * 2.0f;
253 if (DistanceBetweenPoints(previous_point.location, 405 if (DistanceBetweenPoints(previous_point.location,
254 current_point.location) <= distance_threshold && 406 current_point.location) <= distance_threshold &&
255 i != num_points - 1) { 407 i != num_points - 1) {
256 continue; 408 continue;
409 }
410
411 LaserSegment current_segment(
412 previous_segment_points, gfx::PointF(previous_point.location),
413 gfx::PointF(current_point.location), previous_radius, current_radius,
414 i == num_points - 1);
415
416 SkPath path = current_segment.path();
417 flags.setColor(SkColorSetA(kPointColor, current_opacity));
418 canvas.DrawPath(path, flags);
419
420 previous_segment_points = current_segment.path_points();
421 previous_radius = current_radius;
422 previous_point = current_point;
257 } 423 }
258 424
259 LaserSegment current_segment( 425 // Draw the last point as a circle.
260 previous_segment_points, gfx::PointF(previous_point.location),
261 gfx::PointF(current_point.location), previous_radius, current_radius,
262 i == num_points - 1);
263
264 SkPath path = current_segment.path();
265 flags.setColor(SkColorSetA(kPointColor, current_opacity)); 426 flags.setColor(SkColorSetA(kPointColor, current_opacity));
266 canvas->DrawPath(path, flags); 427 flags.setStyle(cc::PaintFlags::kFill_Style);
267 428 canvas.DrawCircle(current_point.location, kPointInitialRadius, flags);
268 previous_segment_points = current_segment.path_points(); 429 }
269 previous_radius = current_radius; 430
270 previous_point = current_point; 431 // Copy result to GPU memory buffer. This is effectiely a memcpy and unlike
271 } 432 // drawing to the buffer directly this ensures that the buffer is never in a
272 // Draw the last point as a circle. 433 // state that would result in flicker.
273 flags.setColor(SkColorSetA(kPointColor, current_opacity)); 434 {
274 flags.setStyle(cc::PaintFlags::kFill_Style); 435 TRACE_EVENT0("ui", "LaserPointerView::OnPointsUpdated::Copy");
275 canvas->DrawCircle(current_point.location, kPointInitialRadius, flags); 436
437 // Convert update rectangle to pixel coordinates.
438 gfx::Rect pixel_rect =
439 gfx::ScaleToEnclosingRect(update_rect, scale_factor_);
440 uint8_t* data = static_cast<uint8_t*>(gpu_memory_buffer_->memory(0));
441 int stride = gpu_memory_buffer_->stride(0);
442 canvas.sk_canvas()->readPixels(
443 SkImageInfo::MakeN32Premul(pixel_rect.width(), pixel_rect.height()),
444 data + pixel_rect.y() * stride + pixel_rect.x() * 4, stride, 0, 0);
445 }
446
447 // Update surface damage rectangle.
448 surface_damage_rect_.Union(update_rect);
449
450 needs_update_surface_ = true;
451
452 // Early out if waiting for last surface update to be drawn.
453 if (pending_draw_surface_)
454 return;
455
456 UpdateSurface();
276 } 457 }
458
459 void LaserPointerView::UpdateSurface() {
460 TRACE_EVENT1("ui", "LaserPointerView::UpdatedSurface", "damage",
461 surface_damage_rect_.ToString());
462
463 DCHECK(needs_update_surface_);
464 needs_update_surface_ = false;
465
466 std::unique_ptr<LaserResource> resource;
467 // Reuse returned resource if available.
468 if (!returned_resources_.empty()) {
469 resource = std::move(returned_resources_.front());
470 returned_resources_.pop_front();
471 }
472
473 // Create new resource if needed.
474 if (!resource)
475 resource = base::MakeUnique<LaserResource>();
476
477 // Acquire context provider for resource if needed.
478 // Note: We make no attempts to recover if the context provider is later
479 // lost. It is expected that this class is short-lived and requiring a
480 // new instance to be created in lost context situations is acceptable and
481 // keeps the code simple.
482 if (!resource->context_provider) {
483 resource->context_provider = aura::Env::GetInstance()
484 ->context_factory()
485 ->SharedMainThreadContextProvider();
486 if (!resource->context_provider) {
487 LOG(ERROR) << "Failed to acquire a context provider";
488 return;
489 }
490 }
491
492 gpu::gles2::GLES2Interface* gles2 = resource->context_provider->ContextGL();
493
494 if (resource->texture) {
495 gles2->ActiveTexture(GL_TEXTURE0);
496 gles2->BindTexture(GL_TEXTURE_2D, resource->texture);
497 } else {
498 gles2->GenTextures(1, &resource->texture);
499 gles2->ActiveTexture(GL_TEXTURE0);
500 gles2->BindTexture(GL_TEXTURE_2D, resource->texture);
501 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
502 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
503 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
504 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
505 gles2->GenMailboxCHROMIUM(resource->mailbox.name);
506 gles2->ProduceTextureCHROMIUM(GL_TEXTURE_2D, resource->mailbox.name);
507 }
508
509 gfx::Size buffer_size = gpu_memory_buffer_->GetSize();
510
511 if (resource->image) {
512 gles2->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, resource->image);
513 } else {
514 resource->image = gles2->CreateImageCHROMIUM(
515 gpu_memory_buffer_->AsClientBuffer(), buffer_size.width(),
516 buffer_size.height(), SK_B32_SHIFT ? GL_RGBA : GL_BGRA_EXT);
517 if (!resource->image) {
518 LOG(ERROR) << "Failed to create image";
519 return;
520 }
521 }
522 gles2->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, resource->image);
523
524 gpu::SyncToken sync_token;
525 uint64_t fence_sync = gles2->InsertFenceSyncCHROMIUM();
526 gles2->OrderingBarrierCHROMIUM();
527 gles2->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData());
528
529 cc::TransferableResource transferable_resource;
530 transferable_resource.id = next_resource_id_++;
531 transferable_resource.format = cc::RGBA_8888;
532 transferable_resource.filter = GL_LINEAR;
533 transferable_resource.size = buffer_size;
534 transferable_resource.mailbox_holder =
535 gpu::MailboxHolder(resource->mailbox, sync_token, GL_TEXTURE_2D);
536 transferable_resource.is_overlay_candidate = true;
537
538 gfx::Rect quad_rect(widget_->GetNativeView()->GetBoundsInScreen().size());
539
540 const int kRenderPassId = 1;
541 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create();
542 render_pass->SetNew(kRenderPassId, quad_rect, surface_damage_rect_,
543 gfx::Transform());
544 surface_damage_rect_ = gfx::Rect();
545
546 cc::SharedQuadState* quad_state =
547 render_pass->CreateAndAppendSharedQuadState();
548 quad_state->quad_layer_bounds = quad_rect.size();
549 quad_state->visible_quad_layer_rect = quad_rect;
550 quad_state->opacity = 1.0f;
551
552 cc::CompositorFrame frame;
553 cc::TextureDrawQuad* texture_quad =
554 render_pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>();
555 float vertex_opacity[4] = {1.0, 1.0, 1.0, 1.0};
556 gfx::PointF uv_top_left(0.f, 0.f);
557 gfx::PointF uv_bottom_right(1.f, 1.f);
558 texture_quad->SetNew(quad_state, quad_rect, gfx::Rect(), quad_rect,
559 transferable_resource.id, true, uv_top_left,
560 uv_bottom_right, SK_ColorTRANSPARENT, vertex_opacity,
561 false, false, false);
562 texture_quad->set_resource_size_in_pixels(transferable_resource.size);
563 frame.resource_list.push_back(transferable_resource);
564 frame.render_pass_list.push_back(std::move(render_pass));
565
566 // Set layer surface if this is the initial frame.
567 if (!local_surface_id_.is_valid()) {
568 local_surface_id_ = id_allocator_.GenerateId();
569 widget_->GetNativeView()->layer()->SetShowPrimarySurface(
570 cc::SurfaceInfo(cc::SurfaceId(frame_sink_id_, local_surface_id_), 1.0f,
571 quad_rect.size()),
572 aura::Env::GetInstance()
573 ->context_factory_private()
574 ->GetSurfaceManager()
575 ->reference_factory());
576 widget_->GetNativeView()->layer()->SetFillsBoundsOpaquely(false);
577 }
578
579 SubmitCompositorFrame(local_surface_id_, std::move(frame));
580
581 resources_[transferable_resource.id] = std::move(resource);
582
583 DCHECK(!pending_draw_surface_);
584 pending_draw_surface_ = true;
585 }
586
587 void LaserPointerView::OnDidDrawSurface() {
588 pending_draw_surface_ = false;
589 if (needs_update_surface_)
590 UpdateSurface();
591 }
592
277 } // namespace ash 593 } // namespace ash
OLDNEW
« no previous file with comments | « ash/laser/laser_pointer_view.h ('k') | mash/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698