• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <compositionengine/Output.h>
20 #include <compositionengine/impl/planner/Flattener.h>
21 #include <compositionengine/impl/planner/LayerState.h>
22 #include <compositionengine/impl/planner/Predictor.h>
23 #include <utils/String16.h>
24 #include <utils/Vector.h>
25 
26 #include <optional>
27 #include <string>
28 #include <unordered_map>
29 
30 namespace android {
31 
32 namespace renderengine {
33 class RenderEngine;
34 } // namespace renderengine
35 
36 namespace compositionengine::impl::planner {
37 
38 // This is the top level class for layer caching. It is responsible for
39 // heuristically determining the composition strategy of the current layer stack,
40 // and flattens inactive layers into an override buffer so it can be used
41 // as a more efficient representation of parts of the layer stack.
42 class Planner {
43 public:
44     Planner(renderengine::RenderEngine& renderengine);
45 
46     void setDisplaySize(ui::Size);
47 
48     // Updates the Planner with the current set of layers before a composition strategy is
49     // determined.
50     // The Planner will call to the Flattener to determine to:
51     // 1. Replace any cached sets with a newly available flattened cached set
52     // 2. Create a new cached set if possible
53     void plan(
54             compositionengine::Output::OutputLayersEnumerator<compositionengine::Output>&& layers);
55 
56     // Updates the Planner with the current set of layers after a composition strategy is
57     // determined.
58     void reportFinalPlan(
59             compositionengine::Output::OutputLayersEnumerator<compositionengine::Output>&& layers);
60 
61     // The planner will call to the Flattener to render any pending cached set.
62     // Rendering a pending cached set is optional: if the renderDeadline is not far enough in the
63     // future then the planner may opt to skip rendering the cached set.
64     void renderCachedSets(const OutputCompositionState& outputState,
65                           std::optional<std::chrono::steady_clock::time_point> renderDeadline);
66 
67     void dump(const Vector<String16>& args, std::string&);
68 
69 private:
70     void dumpUsage(std::string&) const;
71 
72     std::unordered_map<LayerId, LayerState> mPreviousLayers;
73 
74     std::vector<const LayerState*> mCurrentLayers;
75 
76     Predictor mPredictor;
77     Flattener mFlattener;
78 
79     std::optional<Predictor::PredictedPlan> mPredictedPlan;
80     NonBufferHash mFlattenedHash = 0;
81 
82     bool mPredictorEnabled = false;
83 };
84 
85 } // namespace compositionengine::impl::planner
86 } // namespace android
87