/* * Copyright 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include #include #include #include namespace android { namespace renderengine { class RenderEngine; } // namespace renderengine namespace compositionengine::impl::planner { // This is the top level class for layer caching. It is responsible for // heuristically determining the composition strategy of the current layer stack, // and flattens inactive layers into an override buffer so it can be used // as a more efficient representation of parts of the layer stack. class Planner { public: Planner(renderengine::RenderEngine& renderengine); void setDisplaySize(ui::Size); // Updates the Planner with the current set of layers before a composition strategy is // determined. // The Planner will call to the Flattener to determine to: // 1. Replace any cached sets with a newly available flattened cached set // 2. Create a new cached set if possible void plan( compositionengine::Output::OutputLayersEnumerator&& layers); // Updates the Planner with the current set of layers after a composition strategy is // determined. void reportFinalPlan( compositionengine::Output::OutputLayersEnumerator&& layers); // The planner will call to the Flattener to render any pending cached set. // Rendering a pending cached set is optional: if the renderDeadline is not far enough in the // future then the planner may opt to skip rendering the cached set. void renderCachedSets(const OutputCompositionState& outputState, std::optional renderDeadline); void dump(const Vector& args, std::string&); private: void dumpUsage(std::string&) const; std::unordered_map mPreviousLayers; std::vector mCurrentLayers; Predictor mPredictor; Flattener mFlattener; std::optional mPredictedPlan; NonBufferHash mFlattenedHash = 0; bool mPredictorEnabled = false; }; } // namespace compositionengine::impl::planner } // namespace android