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

Side by Side Diff: ui/compositor/layer.cc

Issue 10411086: Makes the browser send pixels to the GPU process where it should (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/compositor/layer.h ('k') | ui/compositor/layer_unittest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/layer.h" 5 #include "ui/compositor/layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 Layer::Layer() 47 Layer::Layer()
48 : type_(LAYER_TEXTURED), 48 : type_(LAYER_TEXTURED),
49 compositor_(NULL), 49 compositor_(NULL),
50 parent_(NULL), 50 parent_(NULL),
51 visible_(true), 51 visible_(true),
52 fills_bounds_opaquely_(true), 52 fills_bounds_opaquely_(true),
53 layer_updated_externally_(false), 53 layer_updated_externally_(false),
54 opacity_(1.0f), 54 opacity_(1.0f),
55 delegate_(NULL), 55 delegate_(NULL),
56 scale_canvas_(true), 56 scale_content_(true),
57 device_scale_factor_(1.0f) { 57 device_scale_factor_(1.0f) {
58 CreateWebLayer(); 58 CreateWebLayer();
59 } 59 }
60 60
61 Layer::Layer(LayerType type) 61 Layer::Layer(LayerType type)
62 : type_(type), 62 : type_(type),
63 compositor_(NULL), 63 compositor_(NULL),
64 parent_(NULL), 64 parent_(NULL),
65 visible_(true), 65 visible_(true),
66 fills_bounds_opaquely_(true), 66 fills_bounds_opaquely_(true),
67 layer_updated_externally_(false), 67 layer_updated_externally_(false),
68 opacity_(1.0f), 68 opacity_(1.0f),
69 delegate_(NULL), 69 delegate_(NULL),
70 scale_canvas_(true), 70 scale_content_(true),
71 device_scale_factor_(1.0f) { 71 device_scale_factor_(1.0f) {
72 CreateWebLayer(); 72 CreateWebLayer();
73 } 73 }
74 74
75 Layer::~Layer() { 75 Layer::~Layer() {
76 // Destroying the animator may cause observers to use the layer (and 76 // Destroying the animator may cause observers to use the layer (and
77 // indirectly the WebLayer). Destroy the animator first so that the WebLayer 77 // indirectly the WebLayer). Destroy the animator first so that the WebLayer
78 // is still around. 78 // is still around.
79 animator_.reset(); 79 animator_.reset();
80 if (compositor_) 80 if (compositor_)
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 if (delegate_ && !damaged_region_.isEmpty()) { 333 if (delegate_ && !damaged_region_.isEmpty()) {
334 for (SkRegion::Iterator iter(damaged_region_); 334 for (SkRegion::Iterator iter(damaged_region_);
335 !iter.done(); iter.next()) { 335 !iter.done(); iter.next()) {
336 const SkIRect& sk_damaged = iter.rect(); 336 const SkIRect& sk_damaged = iter.rect();
337 gfx::Rect damaged( 337 gfx::Rect damaged(
338 sk_damaged.x(), 338 sk_damaged.x(),
339 sk_damaged.y(), 339 sk_damaged.y(),
340 sk_damaged.width(), 340 sk_damaged.width(),
341 sk_damaged.height()); 341 sk_damaged.height());
342 342
343 // TODO(pkotwicz): Remove this once we are no longer linearly upscaling 343 if (scale_content_ && web_layer_is_accelerated_) {
344 // web contents when DIP is enabled (crbug.com/127455).
345 if (web_layer_is_accelerated_) {
346 damaged.Inset(-1, -1); 344 damaged.Inset(-1, -1);
347 damaged = damaged.Intersect(bounds_); 345 damaged = damaged.Intersect(bounds_);
348 } 346 }
349 347
350 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged); 348 gfx::Rect damaged_in_pixel = ConvertRectToPixel(this, damaged);
351 WebKit::WebFloatRect web_rect( 349 WebKit::WebFloatRect web_rect(
352 damaged_in_pixel.x(), 350 damaged_in_pixel.x(),
353 damaged_in_pixel.y(), 351 damaged_in_pixel.y(),
354 damaged_in_pixel.width(), 352 damaged_in_pixel.width(),
355 damaged_in_pixel.height()); 353 damaged_in_pixel.height());
(...skipping 27 matching lines...) Expand all
383 if (delegate_) 381 if (delegate_)
384 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); 382 delegate_->OnDeviceScaleFactorChanged(device_scale_factor);
385 for (size_t i = 0; i < children_.size(); ++i) 383 for (size_t i = 0; i < children_.size(); ++i)
386 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); 384 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor);
387 } 385 }
388 386
389 void Layer::paintContents(WebKit::WebCanvas* web_canvas, 387 void Layer::paintContents(WebKit::WebCanvas* web_canvas,
390 const WebKit::WebRect& clip) { 388 const WebKit::WebRect& clip) {
391 TRACE_EVENT0("ui", "Layer::paintContents"); 389 TRACE_EVENT0("ui", "Layer::paintContents");
392 gfx::Canvas canvas(web_canvas); 390 gfx::Canvas canvas(web_canvas);
393 bool scale_canvas = scale_canvas_; 391 bool scale_content = scale_content_;
394 if (scale_canvas) { 392 if (scale_content) {
395 canvas.sk_canvas()->scale(SkFloatToScalar(device_scale_factor_), 393 canvas.sk_canvas()->scale(SkFloatToScalar(device_scale_factor_),
396 SkFloatToScalar(device_scale_factor_)); 394 SkFloatToScalar(device_scale_factor_));
397 } 395 }
398 if (delegate_) 396 if (delegate_)
399 delegate_->OnPaintLayer(&canvas); 397 delegate_->OnPaintLayer(&canvas);
400 if (scale_canvas) 398 if (scale_content)
401 canvas.Restore(); 399 canvas.Restore();
402 } 400 }
403 401
404 float Layer::GetCombinedOpacity() const { 402 float Layer::GetCombinedOpacity() const {
405 float opacity = opacity_; 403 float opacity = opacity_;
406 Layer* current = this->parent_; 404 Layer* current = this->parent_;
407 while (current) { 405 while (current) {
408 opacity *= current->opacity_; 406 opacity *= current->opacity_;
409 current = current->parent_; 407 current = current->parent_;
410 } 408 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 if (!web_layer_is_accelerated_) { 582 if (!web_layer_is_accelerated_) {
585 if (type_ != LAYER_SOLID_COLOR) 583 if (type_ != LAYER_SOLID_COLOR)
586 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); 584 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw);
587 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size())); 585 web_layer_.setBounds(ConvertSizeToPixel(this, bounds_.size()));
588 } else { 586 } else {
589 DCHECK(texture_); 587 DCHECK(texture_);
590 unsigned int texture_id = texture_->texture_id(); 588 unsigned int texture_id = texture_->texture_id();
591 WebKit::WebExternalTextureLayer texture_layer = 589 WebKit::WebExternalTextureLayer texture_layer =
592 web_layer_.to<WebKit::WebExternalTextureLayer>(); 590 web_layer_.to<WebKit::WebExternalTextureLayer>();
593 texture_layer.setTextureId(should_draw ? texture_id : 0); 591 texture_layer.setTextureId(should_draw ? texture_id : 0);
594 gfx::Size texture_size = texture_->size();
595 592
596 // As WebKit does not support DIP, WebKit is told of coordinates in DIP 593 gfx::Size texture_size;
597 // as if they were pixel coordinates. The texture is scaled here via 594 if (scale_content_)
598 // the setBounds call. 595 texture_size = texture_->size();
599 // TODO(pkotwicz): Fix this code to take in account textures with pixel 596 else
600 // sizes once WebKit understands DIP. http://crbug.com/127455 597 texture_size = ConvertSizeToDIP(this, texture_->size());
598
601 gfx::Size size(std::min(bounds().width(), texture_size.width()), 599 gfx::Size size(std::min(bounds().width(), texture_size.width()),
602 std::min(bounds().height(), texture_size.height())); 600 std::min(bounds().height(), texture_size.height()));
603 WebKit::WebFloatRect rect( 601 WebKit::WebFloatRect rect(
604 0, 602 0,
605 0, 603 0,
606 static_cast<float>(size.width())/texture_size.width(), 604 static_cast<float>(size.width())/texture_size.width(),
607 static_cast<float>(size.height())/texture_size.height()); 605 static_cast<float>(size.height())/texture_size.height());
608 texture_layer.setUVRect(rect); 606 texture_layer.setUVRect(rect);
609 607
610 gfx::Size size_in_pixel = ConvertSizeToPixel(this, size); 608 gfx::Size size_in_pixel = ConvertSizeToPixel(this, size);
611 web_layer_.setBounds(size_in_pixel); 609 web_layer_.setBounds(size_in_pixel);
612 } 610 }
613 } 611 }
614 612
615 void Layer::RecomputeDebugBorderColor() { 613 void Layer::RecomputeDebugBorderColor() {
616 if (!show_debug_borders_) 614 if (!show_debug_borders_)
617 return; 615 return;
618 unsigned int color = 0xFF000000; 616 unsigned int color = 0xFF000000;
619 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; 617 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000;
620 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); 618 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f);
621 if (!opaque) 619 if (!opaque)
622 color |= 0xFF; 620 color |= 0xFF;
623 web_layer_.setDebugBorderColor(color); 621 web_layer_.setDebugBorderColor(color);
624 } 622 }
625 623
626 } // namespace ui 624 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer.h ('k') | ui/compositor/layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698