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

Unified Diff: services/gfx/compositor/render/painting.h

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.h
diff --git a/services/gfx/compositor/render/painting.h b/services/gfx/compositor/render/painting.h
new file mode 100644
index 0000000000000000000000000000000000000000..50b470cc1f4d0ef31cb58dfcdb2900e220bd8351
--- /dev/null
+++ b/services/gfx/compositor/render/painting.h
@@ -0,0 +1,106 @@
+// 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.
+
+#ifndef SERVICES_GFX_COMPOSITOR_RENDER_PAINTING_H_
+#define SERVICES_GFX_COMPOSITOR_RENDER_PAINTING_H_
+
+#include <map>
+#include <memory>
+
+#include "base/macros.h"
+#include "mojo/skia/ganesh_context.h"
+#include "skia/ext/refptr.h"
+
+class SkImage;
+class SkPicture;
+
+namespace compositor {
+
+class PaintingCache;
+class RenderImage;
+class RenderLayer;
+
+// Provides a context for painting the contents of render tree.
+//
+// This scope should only be instantiated on the stack since it sets up
+// thread-local state for the duration of painting operations.
+class PaintingScope {
+ public:
+ PaintingScope(const mojo::skia::GaneshContext::Scope& ganesh_scope,
+ PaintingCache* painting_cache);
+ ~PaintingScope();
+
+ // Gets the Ganesh scope.
abarth 2016/01/10 22:55:36 Kind of a useless comment.
jeffbrown 2016/01/16 03:28:32 Yeah, habits from documenting public APIs. I'll r
+ const mojo::skia::GaneshContext::Scope& ganesh_scope() const {
+ return ganesh_scope_;
+ }
+
+ // Gets the painting cache.
abarth 2016/01/10 22:55:36 Kind of a useless comment.
jeffbrown 2016/01/16 03:28:32 Done.
+ PaintingCache* painting_cache() const { return painting_cache_; }
+
+ private:
+ const mojo::skia::GaneshContext::Scope& ganesh_scope_;
+ PaintingCache* const painting_cache_;
abarth 2016/01/10 22:55:36 If this isn't nullable, consider "const PaintingCa
jeffbrown 2016/01/16 03:28:32 It can't be const though and non-const references
+
+ DISALLOW_COPY_AND_ASSIGN(PaintingScope);
+};
+
+// Caches assets between painting invocations to improve efficiency.
+class PaintingCache {
+ public:
+ PaintingCache();
+
+ // The destructor must only be called after the cache has been cleared.
+ ~PaintingCache();
+
+ // Clears the painting cache.
+ // Since clearing the cache may cause textures to be deallocated, we require
+ // that this work happen within a painting scope before the cache is
+ // destroyed.
+ void Clear(const PaintingScope& painting_scope);
+
+ // Obtains an SkImage for the specified render image.
+ // Reuses a previously cached image if possible.
+ // Returns null if the image could not be allocated.
+ skia::RefPtr<SkImage> GetSkImage(const PaintingScope& painting_scope,
+ const std::shared_ptr<RenderImage>& image);
+
+ // Obtains an SkPicture for the specified render layer.
+ // Reuses a previously cached pcture if possible.
+ // Result is never null.
+ skia::RefPtr<SkPicture> GetSkPicture(
+ const PaintingScope& painting_scope,
+ const std::shared_ptr<RenderLayer>& layer);
+
+ private:
+ friend class PaintingScope;
+
+ // Informs the cache that painting is about to begin.
+ void BeginPainting(const PaintingScope& painting_scope);
+
+ // Informs the cache that painting has finished.
+ // This provides a signal to the cache that it may discard unused
+ // cached resources that it no longer needs.
+ void FinishPainting(const PaintingScope& painting_scope);
+
+ bool painting_ = false;
+
+ std::map<std::weak_ptr<RenderImage>,
+ skia::RefPtr<SkImage>,
+ std::owner_less<std::weak_ptr<RenderImage>>> used_images_;
abarth 2016/01/10 22:55:36 No idea what this does. map instead of unordered_
jeffbrown 2016/01/16 03:28:32 http://en.cppreference.com/w/cpp/memory/owner_less
jeffbrown 2016/01/16 03:43:40 Ahh sadly there's no std::hash<> defined for std::
+ std::map<std::weak_ptr<RenderImage>,
+ skia::RefPtr<SkImage>,
+ std::owner_less<std::weak_ptr<RenderImage>>> cached_images_;
+
+ std::map<std::weak_ptr<RenderLayer>,
+ skia::RefPtr<SkPicture>,
+ std::owner_less<std::weak_ptr<RenderLayer>>> used_pictures_;
+ std::map<std::weak_ptr<RenderLayer>,
+ skia::RefPtr<SkPicture>,
+ std::owner_less<std::weak_ptr<RenderLayer>>> cached_pictures_;
+};
+
+} // namespace compositor
+
+#endif // SERVICES_GFX_COMPOSITOR_RENDER_PAINTING_H_

Powered by Google App Engine
This is Rietveld 408576698