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_RENDER_LAYER_H_ | |
6 #define SERVICES_GFX_COMPOSITOR_RENDER_RENDER_LAYER_H_ | |
7 | |
8 #include <memory> | |
9 #include <vector> | |
10 | |
11 #include "base/macros.h" | |
12 #include "services/gfx/compositor/render/render_image.h" | |
13 #include "skia/ext/refptr.h" | |
14 #include "third_party/skia/include/core/SkMatrix.h" | |
15 #include "third_party/skia/include/core/SkPaint.h" | |
16 #include "third_party/skia/include/core/SkPath.h" | |
17 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
18 #include "third_party/skia/include/core/SkRRect.h" | |
19 #include "third_party/skia/include/core/SkRect.h" | |
20 | |
21 class SkCanvas; | |
22 class SkPicture; | |
23 | |
24 namespace compositor { | |
25 | |
26 class RenderCommand; | |
27 | |
28 // Describes a sequence of drawing commands to be evaluated as a single pass. | |
29 // Layers are introduced into the render frame at points where blending must | |
30 // occur or where portions of a scene graph may be drawn once into a temporary | |
31 // buffer and used many times. | |
32 // | |
33 // Render objects are thread-safe, immutable, and reference counted via | |
34 // std::shared_ptr. They have no direct references to the scene graph. | |
35 class RenderLayer { | |
36 public: | |
37 ~RenderLayer(); | |
38 explicit RenderLayer(const skia::RefPtr<SkPicture>& picture); | |
39 | |
40 // Gets the underlying picture to rasterize. | |
41 const skia::RefPtr<SkPicture>& picture() const { return picture_; } | |
42 | |
43 private: | |
44 friend class RenderLayerBuilder; | |
45 | |
46 // TODO: store auxiliary information required for hit testing | |
47 skia::RefPtr<SkPicture> picture_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(RenderLayer); | |
50 }; | |
51 | |
52 // Builder for render layers. | |
53 class RenderLayerBuilder { | |
54 public: | |
55 // Creates a layer builder with an optional |cull_rect| to cull recorded | |
56 // geometry information. | |
57 RenderLayerBuilder(); | |
58 explicit RenderLayerBuilder(const SkRect* cull_rect); | |
59 ~RenderLayerBuilder(); | |
60 | |
61 // Pushes information about a scene onto the stack. | |
62 void PushScene(uint32_t scene_token, uint32_t version); | |
63 | |
64 // Pops a scene off the stack. | |
65 void PopScene(); | |
66 | |
67 // Pushes information about a node onto the stack. | |
68 void PushNode(uint32_t node_id, uint32_t hit_id); | |
69 | |
70 // Pops a node off the stack. | |
71 void PopNode(); | |
72 | |
73 // Applies a transformation matrix to the node. | |
74 void ApplyTransform(const SkMatrix& content_transform); | |
75 | |
76 // Applies a clip to the node. | |
77 void ApplyClip(const SkRect& content_clip); | |
78 | |
79 // Inserts a command to draw a rectangle. | |
80 void DrawRect(const SkRect& content_rect, const SkPaint& paint); | |
81 | |
82 // Inserts a command to draw an image. | |
83 void DrawImage(const std::shared_ptr<RenderImage>& image, | |
84 const SkRect& content_rect, | |
85 const SkRect& image_rect, | |
86 const SkPaint& paint); | |
87 | |
88 // Inserts a command to draw an in-place layer. | |
89 void DrawLayer(const std::shared_ptr<RenderLayer>& layer); | |
90 | |
91 // Inserts a command to draw a saved layer. | |
92 void DrawSavedLayer(const std::shared_ptr<RenderLayer>& layer, | |
93 const SkRect& content_rect, | |
94 const SkPaint& paint); | |
95 | |
96 // Returns the layer which was built. | |
97 std::shared_ptr<RenderLayer> Build(); | |
98 | |
99 private: | |
100 SkPictureRecorder recorder_; | |
101 SkCanvas* canvas_; | |
102 | |
103 DISALLOW_COPY_AND_ASSIGN(RenderLayerBuilder); | |
104 }; | |
105 | |
106 } // namespace compositor | |
107 | |
108 #endif // SERVICES_GFX_COMPOSITOR_RENDER_RENDER_LAYER_H_ | |
OLD | NEW |