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

Side by Side Diff: services/gfx/compositor/render/painting.cc

Issue 1552963002: Initial checkin of the new Mozart compositor. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-11
Patch Set: Created 4 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "services/gfx/compositor/render/painting.h"
6
7 #include "base/logging.h"
8 #include "services/gfx/compositor/render/render_image.h"
9 #include "services/gfx/compositor/render/render_layer.h"
10 #include "third_party/skia/include/core/SkImage.h"
11 #include "third_party/skia/include/core/SkPicture.h"
12
13 namespace compositor {
14
15 PaintingScope::PaintingScope(
16 const mojo::skia::GaneshContext::Scope& ganesh_scope,
17 PaintingCache* painting_cache)
18 : ganesh_scope_(ganesh_scope), painting_cache_(painting_cache) {
19 DCHECK(painting_cache_);
20 painting_cache_->BeginPainting(*this);
21 }
22
23 PaintingScope::~PaintingScope() {
24 painting_cache_->FinishPainting(*this);
25 }
26
27 PaintingCache::PaintingCache() {}
28
29 PaintingCache::~PaintingCache() {
30 DCHECK(!painting_);
31 DCHECK(used_images_.empty());
32 DCHECK(cached_images_.empty());
33 DCHECK(used_pictures_.empty());
34 DCHECK(cached_pictures_.empty());
35 }
36
37 void PaintingCache::BeginPainting(const PaintingScope& painting_scope) {
38 DCHECK(!painting_);
39 DCHECK(used_images_.empty());
40 DCHECK(used_pictures_.empty());
41
42 painting_ = true;
43 }
44
45 void PaintingCache::FinishPainting(const PaintingScope& painting_scope) {
46 DCHECK(painting_);
47
48 painting_ = false;
49 cached_images_.clear();
50 cached_images_.swap(used_images_);
51 cached_pictures_.clear();
52 cached_pictures_.swap(used_pictures_);
53 }
54
55 void PaintingCache::Clear(const PaintingScope& painting_scope) {
56 used_images_.clear();
57 cached_images_.clear();
58 used_pictures_.clear();
59 cached_pictures_.clear();
60 }
61
62 skia::RefPtr<SkImage> PaintingCache::GetSkImage(
63 const PaintingScope& painting_scope,
64 const std::shared_ptr<RenderImage>& image) {
65 // Look in our recently used images.
66 auto used_it = used_images_.find(image);
67 if (used_it != used_images_.end())
68 return used_it->second;
69
70 // Look in our previously cached images.
71 auto cached_it = cached_images_.find(image);
72 if (cached_it != cached_images_.end()) {
73 used_images_.emplace(*cached_it);
74 return cached_it->second;
75 }
76
77 // Create the image.
78 skia::RefPtr<SkImage> result = image->CreateSkImage(painting_scope);
79 used_images_.emplace(std::make_pair(image, result));
80 return result;
81 }
82
83 skia::RefPtr<SkPicture> PaintingCache::GetSkPicture(
84 const PaintingScope& painting_scope,
85 const std::shared_ptr<RenderLayer>& layer) {
86 // Look in our recently used pictures.
87 auto used_it = used_pictures_.find(layer);
88 if (used_it != used_pictures_.end())
89 return used_it->second;
90
91 // Look in our previously cached pictures.
92 auto cached_it = cached_pictures_.find(layer);
93 if (cached_it != cached_pictures_.end()) {
94 used_pictures_.emplace(*cached_it);
95 return cached_it->second;
96 }
97
98 // Create the picture.
99 skia::RefPtr<SkPicture> result = layer->CreateSkPicture(painting_scope);
100 used_pictures_.emplace(std::make_pair(layer, result));
101 return result;
102 }
103
104 } // namespace compositor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698