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

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

Issue 9297041: Merge Compositor and CompositorCC (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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
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/gfx/compositor/layer.h" 5 #include "ui/gfx/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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebContentLa yer.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebContentLa yer.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebExternalT extureLayer.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebExternalT extureLayer.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoin t.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoin t.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect .h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect .h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
18 #include "ui/base/animation/animation.h" 18 #include "ui/base/animation/animation.h"
19 #include "ui/gfx/canvas_skia.h" 19 #include "ui/gfx/canvas_skia.h"
20 #include "ui/gfx/compositor/compositor_switches.h" 20 #include "ui/gfx/compositor/compositor_switches.h"
21 #include "ui/gfx/compositor/layer_animator.h" 21 #include "ui/gfx/compositor/layer_animator.h"
22 #include "ui/gfx/interpolated_transform.h" 22 #include "ui/gfx/interpolated_transform.h"
23 #include "ui/gfx/point3.h" 23 #include "ui/gfx/point3.h"
24 24
25 #include "ui/gfx/compositor/compositor_cc.h"
26
27 namespace { 25 namespace {
28 26
29 const float EPSILON = 1e-3f; 27 const float EPSILON = 1e-3f;
30 28
31 bool IsApproximateMultilpleOf(float value, float base) { 29 bool IsApproximateMultilpleOf(float value, float base) {
32 float remainder = fmod(fabs(value), base); 30 float remainder = fmod(fabs(value), base);
33 return remainder < EPSILON || base - remainder < EPSILON; 31 return remainder < EPSILON || base - remainder < EPSILON;
34 } 32 }
35 33
36 const ui::Layer* GetRoot(const ui::Layer* layer) { 34 const ui::Layer* GetRoot(const ui::Layer* layer) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { 213 void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) {
216 if (fills_bounds_opaquely_ == fills_bounds_opaquely) 214 if (fills_bounds_opaquely_ == fills_bounds_opaquely)
217 return; 215 return;
218 216
219 fills_bounds_opaquely_ = fills_bounds_opaquely; 217 fills_bounds_opaquely_ = fills_bounds_opaquely;
220 218
221 web_layer_.setOpaque(fills_bounds_opaquely); 219 web_layer_.setOpaque(fills_bounds_opaquely);
222 RecomputeDebugBorderColor(); 220 RecomputeDebugBorderColor();
223 } 221 }
224 222
225 void Layer::SetExternalTexture(ui::Texture* texture) { 223 void Layer::SetExternalTexture(Texture* texture) {
226 layer_updated_externally_ = !!texture; 224 layer_updated_externally_ = !!texture;
227 texture_ = texture; 225 texture_ = texture;
228 if (web_layer_is_accelerated_ != layer_updated_externally_) { 226 if (web_layer_is_accelerated_ != layer_updated_externally_) {
229 // Switch to a different type of layer. 227 // Switch to a different type of layer.
230 web_layer_.removeAllChildren(); 228 web_layer_.removeAllChildren();
231 WebKit::WebLayer new_layer; 229 WebKit::WebLayer new_layer;
232 if (layer_updated_externally_) 230 if (layer_updated_externally_) {
233 new_layer = WebKit::WebExternalTextureLayer::create(); 231 WebKit::WebExternalTextureLayer texture_layer =
234 else 232 WebKit::WebExternalTextureLayer::create();
233 texture_layer.setFlipped(texture_->flipped());
234 new_layer = texture_layer;
235 } else {
235 new_layer = WebKit::WebContentLayer::create(this); 236 new_layer = WebKit::WebContentLayer::create(this);
237 }
236 if (parent_) { 238 if (parent_) {
237 DCHECK(!parent_->web_layer_.isNull()); 239 DCHECK(!parent_->web_layer_.isNull());
238 parent_->web_layer_.replaceChild(web_layer_, new_layer); 240 parent_->web_layer_.replaceChild(web_layer_, new_layer);
239 } 241 }
240 web_layer_ = new_layer; 242 web_layer_ = new_layer;
241 web_layer_is_accelerated_ = layer_updated_externally_; 243 web_layer_is_accelerated_ = layer_updated_externally_;
242 for (size_t i = 0; i < children_.size(); ++i) { 244 for (size_t i = 0; i < children_.size(); ++i) {
243 DCHECK(!children_[i]->web_layer_.isNull()); 245 DCHECK(!children_[i]->web_layer_.isNull());
244 web_layer_.addChild(children_[i]->web_layer_); 246 web_layer_.addChild(children_[i]->web_layer_);
245 } 247 }
246 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); 248 web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f));
247 web_layer_.setOpaque(fills_bounds_opaquely_); 249 web_layer_.setOpaque(fills_bounds_opaquely_);
248 web_layer_.setOpacity(visible_ ? opacity_ : 0.f); 250 web_layer_.setOpacity(visible_ ? opacity_ : 0.f);
249 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0); 251 web_layer_.setDebugBorderWidth(show_debug_borders_ ? 2 : 0);
250 RecomputeTransform(); 252 RecomputeTransform();
251 RecomputeDebugBorderColor(); 253 RecomputeDebugBorderColor();
252 } 254 }
253 if (texture) {
254 TextureCC* texture_cc = static_cast<TextureCC*>(texture);
255 texture_cc->Update();
256 WebKit::WebExternalTextureLayer texture_layer =
257 web_layer_.to<WebKit::WebExternalTextureLayer>();
258 texture_layer.setFlipped(texture_cc->flipped());
259 }
260 RecomputeDrawsContentAndUVRect(); 255 RecomputeDrawsContentAndUVRect();
261 } 256 }
262 257
263 void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) {
264 NOTREACHED();
265 }
266
267 void Layer::SchedulePaint(const gfx::Rect& invalid_rect) { 258 void Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
268 WebKit::WebFloatRect web_rect( 259 WebKit::WebFloatRect web_rect(
269 invalid_rect.x(), 260 invalid_rect.x(),
270 invalid_rect.y(), 261 invalid_rect.y(),
271 invalid_rect.width(), 262 invalid_rect.width(),
272 invalid_rect.height()); 263 invalid_rect.height());
273 if (!web_layer_is_accelerated_) 264 if (!web_layer_is_accelerated_)
274 web_layer_.to<WebKit::WebContentLayer>().invalidateRect(web_rect); 265 web_layer_.to<WebKit::WebContentLayer>().invalidateRect(web_rect);
275 else 266 else
276 web_layer_.to<WebKit::WebExternalTextureLayer>().invalidateRect(web_rect); 267 web_layer_.to<WebKit::WebExternalTextureLayer>().invalidateRect(web_rect);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 } 451 }
461 452
462 void Layer::RecomputeDrawsContentAndUVRect() { 453 void Layer::RecomputeDrawsContentAndUVRect() {
463 DCHECK(!web_layer_.isNull()); 454 DCHECK(!web_layer_.isNull());
464 bool should_draw = type_ == LAYER_HAS_TEXTURE; 455 bool should_draw = type_ == LAYER_HAS_TEXTURE;
465 if (!web_layer_is_accelerated_) { 456 if (!web_layer_is_accelerated_) {
466 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); 457 web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw);
467 web_layer_.setBounds(bounds_.size()); 458 web_layer_.setBounds(bounds_.size());
468 } else { 459 } else {
469 DCHECK(texture_); 460 DCHECK(texture_);
470 TextureCC* texture_cc = static_cast<TextureCC*>(texture_.get()); 461 unsigned int texture_id = texture_->texture_id();
471 unsigned int texture_id = texture_cc->texture_id();
472 WebKit::WebExternalTextureLayer texture_layer = 462 WebKit::WebExternalTextureLayer texture_layer =
473 web_layer_.to<WebKit::WebExternalTextureLayer>(); 463 web_layer_.to<WebKit::WebExternalTextureLayer>();
474 texture_layer.setTextureId(should_draw ? texture_id : 0); 464 texture_layer.setTextureId(should_draw ? texture_id : 0);
475 gfx::Size size(std::min(bounds_.width(), texture_cc->size().width()), 465 gfx::Size texture_size = texture_->size();
476 std::min(bounds_.height(), texture_cc->size().height())); 466 gfx::Size size(std::min(bounds_.width(), texture_size.width()),
467 std::min(bounds_.height(), texture_size.height()));
477 WebKit::WebFloatRect rect( 468 WebKit::WebFloatRect rect(
478 0, 469 0,
479 0, 470 0,
480 static_cast<float>(size.width())/texture_cc->size().width(), 471 static_cast<float>(size.width())/texture_size.width(),
481 static_cast<float>(size.height())/texture_cc->size().height()); 472 static_cast<float>(size.height())/texture_size.height());
482 texture_layer.setUVRect(rect); 473 texture_layer.setUVRect(rect);
483 web_layer_.setBounds(size); 474 web_layer_.setBounds(size);
484 } 475 }
485 } 476 }
486 477
487 void Layer::RecomputeDebugBorderColor() { 478 void Layer::RecomputeDebugBorderColor() {
488 if (!show_debug_borders_) 479 if (!show_debug_borders_)
489 return; 480 return;
490 unsigned int color = 0xFF000000; 481 unsigned int color = 0xFF000000;
491 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000; 482 color |= web_layer_is_accelerated_ ? 0x0000FF00 : 0x00FF0000;
492 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f); 483 bool opaque = fills_bounds_opaquely_ && (GetCombinedOpacity() == 1.f);
493 if (!opaque) 484 if (!opaque)
494 color |= 0xFF; 485 color |= 0xFF;
495 web_layer_.setDebugBorderColor(color); 486 web_layer_.setDebugBorderColor(color);
496 } 487 }
497 488
498 } // namespace ui 489 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698