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

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

Issue 1101783002: ui: Cache the output of View::OnPaint when the View isn't invalid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cache: . Created 5 years, 8 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/paint_recorder.h" 5 #include "ui/compositor/paint_recorder.h"
6 6
7 #include "cc/resources/display_item_list.h" 7 #include "cc/resources/display_item_list.h"
8 #include "cc/resources/drawing_display_item.h" 8 #include "cc/resources/drawing_display_item.h"
9 #include "third_party/skia/include/core/SkPictureRecorder.h" 9 #include "third_party/skia/include/core/SkPictureRecorder.h"
10 #include "ui/compositor/paint_cache.h"
10 #include "ui/compositor/paint_context.h" 11 #include "ui/compositor/paint_context.h"
11 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/skia_util.h" 13 #include "ui/gfx/skia_util.h"
13 14
14 namespace ui { 15 namespace ui {
15 16
16 PaintRecorder::PaintRecorder(const PaintContext& context) 17 PaintRecorder::PaintRecorder(const PaintContext& context, PaintCache* cache)
17 : context_(context), canvas_(context.canvas_) { 18 : context_(context), canvas_(context.canvas_), cache_(cache) {
18 #if DCHECK_IS_ON() 19 #if DCHECK_IS_ON()
19 DCHECK(!context.inside_paint_recorder_); 20 DCHECK(!context.inside_paint_recorder_);
20 context.inside_paint_recorder_ = true; 21 context.inside_paint_recorder_ = true;
21 #endif 22 #endif
22 23
23 if (context.list_) { 24 if (context.list_) {
24 SkRTreeFactory* no_factory = nullptr; 25 SkRTreeFactory* no_factory = nullptr;
25 // This SkCancas is shared with the recorder_ so no need to store a RefPtr 26 // This SkCancas is shared with the recorder_ so no need to store a RefPtr
26 // to it on this class. 27 // to it on this class.
27 skia::RefPtr<SkCanvas> skcanvas = 28 skia::RefPtr<SkCanvas> skcanvas =
28 skia::SharePtr(context.recorder_->beginRecording( 29 skia::SharePtr(context.recorder_->beginRecording(
29 gfx::RectToSkRect(context.bounds_), no_factory, 30 gfx::RectToSkRect(context.bounds_), no_factory,
30 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); 31 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag));
31 owned_canvas_ = make_scoped_ptr(gfx::Canvas::CreateCanvasWithoutScaling( 32 owned_canvas_ = make_scoped_ptr(gfx::Canvas::CreateCanvasWithoutScaling(
32 skcanvas.get(), context.device_scale_factor_)); 33 skcanvas.get(), context.device_scale_factor_));
33 canvas_ = owned_canvas_.get(); 34 canvas_ = owned_canvas_.get();
34 } 35 }
35 } 36 }
36 37
38 PaintRecorder::PaintRecorder(const PaintContext& context)
39 : PaintRecorder(context, nullptr) {
40 }
41
37 PaintRecorder::~PaintRecorder() { 42 PaintRecorder::~PaintRecorder() {
38 #if DCHECK_IS_ON() 43 #if DCHECK_IS_ON()
39 context_.inside_paint_recorder_ = false; 44 context_.inside_paint_recorder_ = false;
40 #endif 45 #endif
41 46
42 if (context_.list_) { 47 if (!context_.list_)
43 context_.list_->AppendItem(cc::DrawingDisplayItem::Create( 48 return;
44 skia::AdoptRef(context_.recorder_->endRecordingAsPicture()))); 49
45 } 50 scoped_ptr<cc::DrawingDisplayItem> item = cc::DrawingDisplayItem::Create(
51 skia::AdoptRef(context_.recorder_->endRecordingAsPicture()));
52 if (cache_)
53 cache_->SetCache(item->Clone());
54 context_.list_->AppendItem(item.Pass());
46 } 55 }
47 56
48 } // namespace ui 57 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698