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

Unified 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, 12 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 side-by-side diff with in-line comments
Download patch
Index: services/gfx/compositor/render/painting.cc
diff --git a/services/gfx/compositor/render/painting.cc b/services/gfx/compositor/render/painting.cc
new file mode 100644
index 0000000000000000000000000000000000000000..de2aefe2a81a616ef421400f9ea1ce52ff0109ae
--- /dev/null
+++ b/services/gfx/compositor/render/painting.cc
@@ -0,0 +1,104 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/gfx/compositor/render/painting.h"
+
+#include "base/logging.h"
+#include "services/gfx/compositor/render/render_image.h"
+#include "services/gfx/compositor/render/render_layer.h"
+#include "third_party/skia/include/core/SkImage.h"
+#include "third_party/skia/include/core/SkPicture.h"
+
+namespace compositor {
+
+PaintingScope::PaintingScope(
+ const mojo::skia::GaneshContext::Scope& ganesh_scope,
+ PaintingCache* painting_cache)
+ : ganesh_scope_(ganesh_scope), painting_cache_(painting_cache) {
+ DCHECK(painting_cache_);
+ painting_cache_->BeginPainting(*this);
+}
+
+PaintingScope::~PaintingScope() {
+ painting_cache_->FinishPainting(*this);
+}
+
+PaintingCache::PaintingCache() {}
+
+PaintingCache::~PaintingCache() {
+ DCHECK(!painting_);
+ DCHECK(used_images_.empty());
+ DCHECK(cached_images_.empty());
+ DCHECK(used_pictures_.empty());
+ DCHECK(cached_pictures_.empty());
+}
+
+void PaintingCache::BeginPainting(const PaintingScope& painting_scope) {
+ DCHECK(!painting_);
+ DCHECK(used_images_.empty());
+ DCHECK(used_pictures_.empty());
+
+ painting_ = true;
+}
+
+void PaintingCache::FinishPainting(const PaintingScope& painting_scope) {
+ DCHECK(painting_);
+
+ painting_ = false;
+ cached_images_.clear();
+ cached_images_.swap(used_images_);
+ cached_pictures_.clear();
+ cached_pictures_.swap(used_pictures_);
+}
+
+void PaintingCache::Clear(const PaintingScope& painting_scope) {
+ used_images_.clear();
+ cached_images_.clear();
+ used_pictures_.clear();
+ cached_pictures_.clear();
+}
+
+skia::RefPtr<SkImage> PaintingCache::GetSkImage(
+ const PaintingScope& painting_scope,
+ const std::shared_ptr<RenderImage>& image) {
+ // Look in our recently used images.
+ auto used_it = used_images_.find(image);
+ if (used_it != used_images_.end())
+ return used_it->second;
+
+ // Look in our previously cached images.
+ auto cached_it = cached_images_.find(image);
+ if (cached_it != cached_images_.end()) {
+ used_images_.emplace(*cached_it);
+ return cached_it->second;
+ }
+
+ // Create the image.
+ skia::RefPtr<SkImage> result = image->CreateSkImage(painting_scope);
+ used_images_.emplace(std::make_pair(image, result));
+ return result;
+}
+
+skia::RefPtr<SkPicture> PaintingCache::GetSkPicture(
+ const PaintingScope& painting_scope,
+ const std::shared_ptr<RenderLayer>& layer) {
+ // Look in our recently used pictures.
+ auto used_it = used_pictures_.find(layer);
+ if (used_it != used_pictures_.end())
+ return used_it->second;
+
+ // Look in our previously cached pictures.
+ auto cached_it = cached_pictures_.find(layer);
+ if (cached_it != cached_pictures_.end()) {
+ used_pictures_.emplace(*cached_it);
+ return cached_it->second;
+ }
+
+ // Create the picture.
+ skia::RefPtr<SkPicture> result = layer->CreateSkPicture(painting_scope);
+ used_pictures_.emplace(std::make_pair(layer, result));
+ return result;
+}
+
+} // namespace compositor

Powered by Google App Engine
This is Rietveld 408576698