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

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

Issue 2765393004: ash: Map/unmap GMB for each laser pointer update. (Closed)
Patch Set: 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 | « no previous file | no next file » | 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> 7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h> 8 #include <GLES2/gl2ext.h>
9 #include <GLES2/gl2extchromium.h> 9 #include <GLES2/gl2extchromium.h>
10 10
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 widget_->Show(); 236 widget_->Show();
237 widget_->SetContentsView(this); 237 widget_->SetContentsView(this);
238 widget_->SetBounds(root_window->GetBoundsInScreen()); 238 widget_->SetBounds(root_window->GetBoundsInScreen());
239 set_owned_by_client(); 239 set_owned_by_client();
240 240
241 scale_factor_ = display::Screen::GetScreen() 241 scale_factor_ = display::Screen::GetScreen()
242 ->GetDisplayNearestWindow(widget_->GetNativeView()) 242 ->GetDisplayNearestWindow(widget_->GetNativeView())
243 .device_scale_factor(); 243 .device_scale_factor();
244 } 244 }
245 245
246 LaserPointerView::~LaserPointerView() { 246 LaserPointerView::~LaserPointerView() {}
247 // Make sure GPU memory buffer is unmapped before being destroyed.
248 if (gpu_memory_buffer_)
249 gpu_memory_buffer_->Unmap();
250 }
251 247
252 void LaserPointerView::Stop() { 248 void LaserPointerView::Stop() {
253 buffer_damage_rect_.Union(GetBoundingBox()); 249 buffer_damage_rect_.Union(GetBoundingBox());
254 laser_points_.Clear(); 250 laser_points_.Clear();
255 predicted_laser_points_.Clear(); 251 predicted_laser_points_.Clear();
256 OnPointsUpdated(); 252 OnPointsUpdated();
257 } 253 }
258 254
259 void LaserPointerView::AddNewPoint(const gfx::PointF& new_point, 255 void LaserPointerView::AddNewPoint(const gfx::PointF& new_point,
260 const base::TimeTicks& new_time) { 256 const base::TimeTicks& new_time) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 gfx::ScaleToCeiledSize(screen_bounds.size(), scale_factor_), 459 gfx::ScaleToCeiledSize(screen_bounds.size(), scale_factor_),
464 SK_B32_SHIFT ? gfx::BufferFormat::RGBA_8888 460 SK_B32_SHIFT ? gfx::BufferFormat::RGBA_8888
465 : gfx::BufferFormat::BGRA_8888, 461 : gfx::BufferFormat::BGRA_8888,
466 gfx::BufferUsage::SCANOUT_CPU_READ_WRITE, 462 gfx::BufferUsage::SCANOUT_CPU_READ_WRITE,
467 gpu::kNullSurfaceHandle); 463 gpu::kNullSurfaceHandle);
468 if (!gpu_memory_buffer_) { 464 if (!gpu_memory_buffer_) {
469 LOG(ERROR) << "Failed to allocate GPU memory buffer"; 465 LOG(ERROR) << "Failed to allocate GPU memory buffer";
470 return; 466 return;
471 } 467 }
472 468
473 // Map buffer and keep it mapped until destroyed.
474 bool rv = gpu_memory_buffer_->Map();
475 if (!rv) {
476 LOG(ERROR) << "Failed to map GPU memory buffer";
477 return;
478 }
479
480 // Make sure the first update rectangle covers the whole buffer. 469 // Make sure the first update rectangle covers the whole buffer.
481 update_rect = gfx::Rect(screen_bounds.size()); 470 update_rect = gfx::Rect(screen_bounds.size());
482 } 471 }
483 472
484 // Constrain update rectangle to buffer size and early out if empty. 473 // Constrain update rectangle to buffer size and early out if empty.
485 update_rect.Intersect(gfx::Rect(screen_bounds.size())); 474 update_rect.Intersect(gfx::Rect(screen_bounds.size()));
486 if (update_rect.IsEmpty()) 475 if (update_rect.IsEmpty())
487 return; 476 return;
488 477
478 // Map buffer for writing.
479 if (!gpu_memory_buffer_->Map()) {
480 LOG(ERROR) << "Failed to map GPU memory buffer";
481 return;
482 }
483
489 // Create a temporary canvas for update rectangle. 484 // Create a temporary canvas for update rectangle.
490 gfx::Canvas canvas(update_rect.size(), scale_factor_, false); 485 gfx::Canvas canvas(update_rect.size(), scale_factor_, false);
491 486
492 cc::PaintFlags flags; 487 cc::PaintFlags flags;
493 flags.setStyle(cc::PaintFlags::kFill_Style); 488 flags.setStyle(cc::PaintFlags::kFill_Style);
494 flags.setAntiAlias(true); 489 flags.setAntiAlias(true);
495 490
496 // Compute the offset of the current widget. 491 // Compute the offset of the current widget.
497 gfx::Vector2d widget_offset( 492 gfx::Vector2d widget_offset(
498 widget_->GetNativeView()->GetBoundsInRootWindow().origin().x(), 493 widget_->GetNativeView()->GetBoundsInRootWindow().origin().x(),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 // Convert update rectangle to pixel coordinates. 560 // Convert update rectangle to pixel coordinates.
566 gfx::Rect pixel_rect = 561 gfx::Rect pixel_rect =
567 gfx::ScaleToEnclosingRect(update_rect, scale_factor_); 562 gfx::ScaleToEnclosingRect(update_rect, scale_factor_);
568 uint8_t* data = static_cast<uint8_t*>(gpu_memory_buffer_->memory(0)); 563 uint8_t* data = static_cast<uint8_t*>(gpu_memory_buffer_->memory(0));
569 int stride = gpu_memory_buffer_->stride(0); 564 int stride = gpu_memory_buffer_->stride(0);
570 canvas.sk_canvas()->readPixels( 565 canvas.sk_canvas()->readPixels(
571 SkImageInfo::MakeN32Premul(pixel_rect.width(), pixel_rect.height()), 566 SkImageInfo::MakeN32Premul(pixel_rect.width(), pixel_rect.height()),
572 data + pixel_rect.y() * stride + pixel_rect.x() * 4, stride, 0, 0); 567 data + pixel_rect.y() * stride + pixel_rect.x() * 4, stride, 0, 0);
573 } 568 }
574 569
570 // Unmap to flush writes to buffer.
571 gpu_memory_buffer_->Unmap();
572
575 // Update surface damage rectangle. 573 // Update surface damage rectangle.
576 surface_damage_rect_.Union(update_rect); 574 surface_damage_rect_.Union(update_rect);
577 575
578 needs_update_surface_ = true; 576 needs_update_surface_ = true;
579 577
580 // Early out if waiting for last surface update to be drawn. 578 // Early out if waiting for last surface update to be drawn.
581 if (pending_draw_surface_) 579 if (pending_draw_surface_)
582 return; 580 return;
583 581
584 UpdateSurface(); 582 UpdateSurface();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 pending_draw_surface_ = true; 710 pending_draw_surface_ = true;
713 } 711 }
714 712
715 void LaserPointerView::OnDidDrawSurface() { 713 void LaserPointerView::OnDidDrawSurface() {
716 pending_draw_surface_ = false; 714 pending_draw_surface_ = false;
717 if (needs_update_surface_) 715 if (needs_update_surface_)
718 UpdateSurface(); 716 UpdateSurface();
719 } 717 }
720 718
721 } // namespace ash 719 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698