Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #ifndef SERVICES_GFX_COMPOSITOR_RENDER_PAINTING_H_ | |
| 6 #define SERVICES_GFX_COMPOSITOR_RENDER_PAINTING_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "mojo/skia/ganesh_context.h" | |
| 13 #include "skia/ext/refptr.h" | |
| 14 | |
| 15 class SkImage; | |
| 16 class SkPicture; | |
| 17 | |
| 18 namespace compositor { | |
| 19 | |
| 20 class PaintingCache; | |
| 21 class RenderImage; | |
| 22 class RenderLayer; | |
| 23 | |
| 24 // Provides a context for painting the contents of render tree. | |
| 25 // | |
| 26 // This scope should only be instantiated on the stack since it sets up | |
| 27 // thread-local state for the duration of painting operations. | |
| 28 class PaintingScope { | |
| 29 public: | |
| 30 PaintingScope(const mojo::skia::GaneshContext::Scope& ganesh_scope, | |
| 31 PaintingCache* painting_cache); | |
| 32 ~PaintingScope(); | |
| 33 | |
| 34 // 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
| |
| 35 const mojo::skia::GaneshContext::Scope& ganesh_scope() const { | |
| 36 return ganesh_scope_; | |
| 37 } | |
| 38 | |
| 39 // Gets the painting cache. | |
|
abarth
2016/01/10 22:55:36
Kind of a useless comment.
jeffbrown
2016/01/16 03:28:32
Done.
| |
| 40 PaintingCache* painting_cache() const { return painting_cache_; } | |
| 41 | |
| 42 private: | |
| 43 const mojo::skia::GaneshContext::Scope& ganesh_scope_; | |
| 44 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
| |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(PaintingScope); | |
| 47 }; | |
| 48 | |
| 49 // Caches assets between painting invocations to improve efficiency. | |
| 50 class PaintingCache { | |
| 51 public: | |
| 52 PaintingCache(); | |
| 53 | |
| 54 // The destructor must only be called after the cache has been cleared. | |
| 55 ~PaintingCache(); | |
| 56 | |
| 57 // Clears the painting cache. | |
| 58 // Since clearing the cache may cause textures to be deallocated, we require | |
| 59 // that this work happen within a painting scope before the cache is | |
| 60 // destroyed. | |
| 61 void Clear(const PaintingScope& painting_scope); | |
| 62 | |
| 63 // Obtains an SkImage for the specified render image. | |
| 64 // Reuses a previously cached image if possible. | |
| 65 // Returns null if the image could not be allocated. | |
| 66 skia::RefPtr<SkImage> GetSkImage(const PaintingScope& painting_scope, | |
| 67 const std::shared_ptr<RenderImage>& image); | |
| 68 | |
| 69 // Obtains an SkPicture for the specified render layer. | |
| 70 // Reuses a previously cached pcture if possible. | |
| 71 // Result is never null. | |
| 72 skia::RefPtr<SkPicture> GetSkPicture( | |
| 73 const PaintingScope& painting_scope, | |
| 74 const std::shared_ptr<RenderLayer>& layer); | |
| 75 | |
| 76 private: | |
| 77 friend class PaintingScope; | |
| 78 | |
| 79 // Informs the cache that painting is about to begin. | |
| 80 void BeginPainting(const PaintingScope& painting_scope); | |
| 81 | |
| 82 // Informs the cache that painting has finished. | |
| 83 // This provides a signal to the cache that it may discard unused | |
| 84 // cached resources that it no longer needs. | |
| 85 void FinishPainting(const PaintingScope& painting_scope); | |
| 86 | |
| 87 bool painting_ = false; | |
| 88 | |
| 89 std::map<std::weak_ptr<RenderImage>, | |
| 90 skia::RefPtr<SkImage>, | |
| 91 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::
| |
| 92 std::map<std::weak_ptr<RenderImage>, | |
| 93 skia::RefPtr<SkImage>, | |
| 94 std::owner_less<std::weak_ptr<RenderImage>>> cached_images_; | |
| 95 | |
| 96 std::map<std::weak_ptr<RenderLayer>, | |
| 97 skia::RefPtr<SkPicture>, | |
| 98 std::owner_less<std::weak_ptr<RenderLayer>>> used_pictures_; | |
| 99 std::map<std::weak_ptr<RenderLayer>, | |
| 100 skia::RefPtr<SkPicture>, | |
| 101 std::owner_less<std::weak_ptr<RenderLayer>>> cached_pictures_; | |
| 102 }; | |
| 103 | |
| 104 } // namespace compositor | |
| 105 | |
| 106 #endif // SERVICES_GFX_COMPOSITOR_RENDER_PAINTING_H_ | |
| OLD | NEW |