199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall/*
299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * Copyright 2013 The Android Open Source Project
399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall *
499c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * Licensed under the Apache License, Version 2.0 (the "License");
599c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * you may not use this file except in compliance with the License.
699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * You may obtain a copy of the License at
799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall *
899c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall *      http://www.apache.org/licenses/LICENSE-2.0
999c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall *
1099c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * Unless required by applicable law or agreed to in writing, software
1199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * distributed under the License is distributed on an "AS IS" BASIS,
1299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * See the License for the specific language governing permissions and
1499c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * limitations under the License.
1599c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall */
1699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
1799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall#ifndef ANDROID_SF_DISPLAY_SURFACE_H
1899c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall#define ANDROID_SF_DISPLAY_SURFACE_H
1999c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
2099c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall#include <utils/Errors.h>
2199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall#include <utils/RefBase.h>
2299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall#include <utils/StrongPointer.h>
2399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
2499c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall// ---------------------------------------------------------------------------
2599c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hallnamespace android {
2699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall// ---------------------------------------------------------------------------
2799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
2899c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hallclass IGraphicBufferProducer;
2999c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hallclass String8;
3099c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
3199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hallclass DisplaySurface : public virtual RefBase {
3299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hallpublic:
33028dc8f2d72bc7cd4fbe7808781443125a742f78Jesse Hall    // beginFrame is called at the beginning of the composition loop, before
34028dc8f2d72bc7cd4fbe7808781443125a742f78Jesse Hall    // the configuration is known. The DisplaySurface should do anything it
35028dc8f2d72bc7cd4fbe7808781443125a742f78Jesse Hall    // needs to do to enable HWComposer to decide how to compose the frame.
367143316af216fa92c31a60d4407b707637382da1Dan Stoza    // We pass in mustRecompose so we can keep VirtualDisplaySurface's state
377143316af216fa92c31a60d4407b707637382da1Dan Stoza    // machine happy without actually queueing a buffer if nothing has changed.
387143316af216fa92c31a60d4407b707637382da1Dan Stoza    virtual status_t beginFrame(bool mustRecompose) = 0;
39028dc8f2d72bc7cd4fbe7808781443125a742f78Jesse Hall
4038efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall    // prepareFrame is called after the composition configuration is known but
4138efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall    // before composition takes place. The DisplaySurface can use the
4238efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall    // composition type to decide how to manage the flow of buffers between
4338efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall    // GLES and HWC for this frame.
4438efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall    enum CompositionType {
4538efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall        COMPOSITION_UNKNOWN = 0,
4638efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall        COMPOSITION_GLES    = 1,
4738efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall        COMPOSITION_HWC     = 2,
4838efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall        COMPOSITION_MIXED   = COMPOSITION_GLES | COMPOSITION_HWC
4938efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall    };
5038efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall    virtual status_t prepareFrame(CompositionType compositionType) = 0;
5138efe86d9459cf5c96a24a34cc5cbf31fdba7e19Jesse Hall
5299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    // Should be called when composition rendering is complete for a frame (but
5399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    // eglSwapBuffers hasn't necessarily been called). Required by certain
5499c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    // older drivers for synchronization.
5599c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    // TODO: Remove this when we drop support for HWC 1.0.
5699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    virtual status_t compositionComplete() = 0;
5799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
5899c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    // Inform the surface that GLES composition is complete for this frame, and
5999c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    // the surface should make sure that HWComposer has the correct buffer for
6099c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    // this frame. Some implementations may only push a new buffer to
6199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    // HWComposer if GLES composition took place, others need to push a new
6299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    // buffer on every frame.
637414965606f82ac2bcace5d3e2c8a4810517bf1eJesse Hall    //
647414965606f82ac2bcace5d3e2c8a4810517bf1eJesse Hall    // advanceFrame must be followed by a call to  onFrameCommitted before
657414965606f82ac2bcace5d3e2c8a4810517bf1eJesse Hall    // advanceFrame may be called again.
6699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    virtual status_t advanceFrame() = 0;
6799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
687414965606f82ac2bcace5d3e2c8a4810517bf1eJesse Hall    // onFrameCommitted is called after the frame has been committed to the
69851cfe834295224cd64bdd499872b95b19c4de8cJesse Hall    // hardware composer. The surface collects the release fence for this
70851cfe834295224cd64bdd499872b95b19c4de8cJesse Hall    // frame's buffer.
71851cfe834295224cd64bdd499872b95b19c4de8cJesse Hall    virtual void onFrameCommitted() = 0;
7299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
7399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    virtual void dump(String8& result) const = 0;
7499c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
7547e45405d1533aa73307014f7bf371e118695cf3Michael Lentine    virtual void resizeBuffers(const uint32_t w, const uint32_t h) = 0;
7647e45405d1533aa73307014f7bf371e118695cf3Michael Lentine
7799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hallprotected:
7899c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    DisplaySurface() {}
7999c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall    virtual ~DisplaySurface() {}
8099c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall};
8199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
8299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall// ---------------------------------------------------------------------------
8399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall} // namespace android
8499c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall// ---------------------------------------------------------------------------
8599c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
8699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall#endif // ANDROID_SF_DISPLAY_SURFACE_H
8799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall
88