OLD | NEW |
---|---|
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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
6 | 6 |
7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
18 #include "cc/resources/display_item_list.h" | 18 #include "cc/resources/display_item_list.h" |
19 #include "cc/resources/drawing_display_item.h" | 19 #include "cc/resources/drawing_display_item.h" |
20 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
21 #include "third_party/skia/include/core/SkRect.h" | 20 #include "third_party/skia/include/core/SkRect.h" |
22 #include "ui/accessibility/ax_enums.h" | 21 #include "ui/accessibility/ax_enums.h" |
23 #include "ui/base/cursor/cursor.h" | 22 #include "ui/base/cursor/cursor.h" |
24 #include "ui/base/dragdrop/drag_drop_types.h" | 23 #include "ui/base/dragdrop/drag_drop_types.h" |
25 #include "ui/compositor/compositor.h" | 24 #include "ui/compositor/compositor.h" |
26 #include "ui/compositor/dip_util.h" | 25 #include "ui/compositor/dip_util.h" |
27 #include "ui/compositor/layer.h" | 26 #include "ui/compositor/layer.h" |
28 #include "ui/compositor/layer_animator.h" | 27 #include "ui/compositor/layer_animator.h" |
28 #include "ui/compositor/paint_recorder.h" | |
29 #include "ui/events/event_target_iterator.h" | 29 #include "ui/events/event_target_iterator.h" |
30 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
31 #include "ui/gfx/geometry/point3_f.h" | 31 #include "ui/gfx/geometry/point3_f.h" |
32 #include "ui/gfx/geometry/point_conversions.h" | 32 #include "ui/gfx/geometry/point_conversions.h" |
33 #include "ui/gfx/interpolated_transform.h" | 33 #include "ui/gfx/interpolated_transform.h" |
34 #include "ui/gfx/path.h" | 34 #include "ui/gfx/path.h" |
35 #include "ui/gfx/scoped_canvas.h" | 35 #include "ui/gfx/scoped_canvas.h" |
36 #include "ui/gfx/screen.h" | 36 #include "ui/gfx/screen.h" |
37 #include "ui/gfx/skia_util.h" | 37 #include "ui/gfx/skia_util.h" |
38 #include "ui/gfx/transform.h" | 38 #include "ui/gfx/transform.h" |
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1457 SetLayerBounds(GetLocalBounds() + offset); | 1457 SetLayerBounds(GetLocalBounds() + offset); |
1458 } else { | 1458 } else { |
1459 for (int i = 0, count = child_count(); i < count; ++i) { | 1459 for (int i = 0, count = child_count(); i < count; ++i) { |
1460 View* child = child_at(i); | 1460 View* child = child_at(i); |
1461 child->UpdateChildLayerBounds( | 1461 child->UpdateChildLayerBounds( |
1462 offset + gfx::Vector2d(child->GetMirroredX(), child->y())); | 1462 offset + gfx::Vector2d(child->GetMirroredX(), child->y())); |
1463 } | 1463 } |
1464 } | 1464 } |
1465 } | 1465 } |
1466 | 1466 |
1467 void View::OnPaintLayerToDisplayList(cc::DisplayItemList* list, | 1467 void View::OnPaintLayerToDisplayList(cc::DisplayItemList* list, |
sky
2015/03/20 14:52:45
I was commenting on this function. This hasn't lan
danakj
2015/03/20 15:26:35
Ya this patch depends on the first one to add the
| |
1468 float device_scale_factor) { | 1468 float device_scale_factor) { |
1469 TRACE_EVENT1("views", "View::OnPaintToDisplayList", "class", GetClassName()); | 1469 TRACE_EVENT1("views", "View::OnPaintToDisplayList", "class", GetClassName()); |
1470 | 1470 |
1471 // TODO(danakj): Instead of always recording, cache a picture in each view and | |
1472 // reuse it when not invalidated. ie. just AppendItem() and return here. | |
1473 | |
1471 // TODO(danakj): Does this include the bounds of all children? | 1474 // TODO(danakj): Does this include the bounds of all children? |
1472 // TODO(danakj): Should this be the layer's bounds? | 1475 // TODO(danakj): Should this be the layer's bounds? |
1476 // TODO(danakj): The paint code does transforms on the canvas to position | |
1477 // children, but each DisplayItem's recording bounds and origin should be | |
1478 // relative to the layer, I think. | |
1473 gfx::Rect view_bounds = GetLocalBounds(); | 1479 gfx::Rect view_bounds = GetLocalBounds(); |
1474 | 1480 |
1475 // TODO(danakj): Instead of always recording, cache a picture in each view and | 1481 ui::PaintRecorder recorder(view_bounds, device_scale_factor); |
1476 // reuse it when not invalidated. | 1482 OnPaintLayer(recorder.canvas()); |
1477 SkPictureRecorder recorder; | |
1478 SkRTreeFactory* no_factory = nullptr; | |
1479 skia::RefPtr<SkCanvas> skcanvas = skia::SharePtr(recorder.beginRecording( | |
1480 view_bounds.width(), view_bounds.height(), no_factory, | |
1481 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); | |
1482 skcanvas->clipRect(gfx::RectToSkRect(view_bounds)); | |
1483 | 1483 |
1484 { | 1484 // TODO(danakj): Cache this picture in the View and reuse it. |
1485 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( | 1485 scoped_ptr<cc::DrawingDisplayItem> item = recorder.TakeDisplayItem(); |
1486 skcanvas.get(), device_scale_factor)); | 1486 list->AppendItem(item->Clone()); |
1487 if (!layer() || !layer()->fills_bounds_opaquely()) | |
1488 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); | |
1489 PaintCommon(canvas.get(), CullSet()); | |
1490 } | |
1491 | |
1492 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | |
1493 scoped_ptr<cc::DrawingDisplayItem> item = | |
1494 cc::DrawingDisplayItem::Create(picture); | |
1495 list->AppendItem(item.Pass()); | |
1496 } | 1487 } |
1497 | 1488 |
1498 void View::OnPaintLayer(gfx::Canvas* canvas) { | 1489 void View::OnPaintLayer(gfx::Canvas* canvas) { |
1499 if (!layer() || !layer()->fills_bounds_opaquely()) | 1490 if (!layer() || !layer()->fills_bounds_opaquely()) |
1500 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); | 1491 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); |
1501 PaintCommon(canvas, CullSet()); | 1492 PaintCommon(canvas, CullSet()); |
1502 } | 1493 } |
1503 | 1494 |
1504 void View::OnDelegatedFrameDamage( | 1495 void View::OnDelegatedFrameDamage( |
1505 const gfx::Rect& damage_rect_in_dip) { | 1496 const gfx::Rect& damage_rect_in_dip) { |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2507 // Message the RootView to do the drag and drop. That way if we're removed | 2498 // Message the RootView to do the drag and drop. That way if we're removed |
2508 // the RootView can detect it and avoid calling us back. | 2499 // the RootView can detect it and avoid calling us back. |
2509 gfx::Point widget_location(event.location()); | 2500 gfx::Point widget_location(event.location()); |
2510 ConvertPointToWidget(this, &widget_location); | 2501 ConvertPointToWidget(this, &widget_location); |
2511 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2502 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2512 // WARNING: we may have been deleted. | 2503 // WARNING: we may have been deleted. |
2513 return true; | 2504 return true; |
2514 } | 2505 } |
2515 | 2506 |
2516 } // namespace views | 2507 } // namespace views |
OLD | NEW |