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

Side by Side Diff: ui/views/view.cc

Issue 1021823002: Introduce ui::PaintRecorder and use it for CursorWindowDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: slimmingui-paintrecorder: rebase Created 5 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 | « ui/compositor/paint_recorder.cc ('k') | 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 (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 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
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 OnPaintLayer(canvas.get());
1488 }
1489
1490 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
1491 scoped_ptr<cc::DrawingDisplayItem> item =
1492 cc::DrawingDisplayItem::Create(picture);
1493 list->AppendItem(item.Pass());
1494 } 1487 }
1495 1488
1496 void View::OnPaintLayer(gfx::Canvas* canvas) { 1489 void View::OnPaintLayer(gfx::Canvas* canvas) {
1497 if (!layer() || !layer()->fills_bounds_opaquely()) 1490 if (!layer() || !layer()->fills_bounds_opaquely())
1498 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); 1491 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
1499 PaintCommon(canvas, CullSet()); 1492 PaintCommon(canvas, CullSet());
1500 } 1493 }
1501 1494
1502 void View::OnDelegatedFrameDamage( 1495 void View::OnDelegatedFrameDamage(
1503 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
2505 // 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
2506 // the RootView can detect it and avoid calling us back. 2499 // the RootView can detect it and avoid calling us back.
2507 gfx::Point widget_location(event.location()); 2500 gfx::Point widget_location(event.location());
2508 ConvertPointToWidget(this, &widget_location); 2501 ConvertPointToWidget(this, &widget_location);
2509 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2502 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2510 // WARNING: we may have been deleted. 2503 // WARNING: we may have been deleted.
2511 return true; 2504 return true;
2512 } 2505 }
2513 2506
2514 } // namespace views 2507 } // namespace views
OLDNEW
« no previous file with comments | « ui/compositor/paint_recorder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698