Home | History | Annotate | Download | only in gui
      1 /*
      2  * Copyright (C) 2007 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 #ifndef ANDROID_GUI_SURFACE_CONTROL_H
     18 #define ANDROID_GUI_SURFACE_CONTROL_H
     19 
     20 #include <stdint.h>
     21 #include <sys/types.h>
     22 
     23 #include <utils/KeyedVector.h>
     24 #include <utils/RefBase.h>
     25 #include <utils/threads.h>
     26 
     27 #include <ui/FrameStats.h>
     28 #include <ui/PixelFormat.h>
     29 #include <ui/Region.h>
     30 
     31 #include <gui/ISurfaceComposerClient.h>
     32 #include <math/vec3.h>
     33 
     34 namespace android {
     35 
     36 // ---------------------------------------------------------------------------
     37 
     38 class IGraphicBufferProducer;
     39 class Surface;
     40 class SurfaceComposerClient;
     41 
     42 // ---------------------------------------------------------------------------
     43 
     44 class SurfaceControl : public RefBase
     45 {
     46 public:
     47     static sp<SurfaceControl> readFromParcel(Parcel* parcel);
     48     void writeToParcel(Parcel* parcel);
     49 
     50     static bool isValid(const sp<SurfaceControl>& surface) {
     51         return (surface != nullptr) && surface->isValid();
     52     }
     53 
     54     bool isValid() {
     55         return mHandle!=nullptr && mClient!=nullptr;
     56     }
     57 
     58     static bool isSameSurface(
     59             const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);
     60 
     61     // Release the handles assosciated with the SurfaceControl, without reparenting
     62     // them off-screen. At the moment if this isn't executed before ~SurfaceControl
     63     // is called then the destructor will reparent the layer off-screen for you.
     64     void        release();
     65     // Reparent off-screen and release. This is invoked by the destructor.
     66     void destroy();
     67 
     68     // disconnect any api that's connected
     69     void        disconnect();
     70 
     71     static status_t writeSurfaceToParcel(
     72             const sp<SurfaceControl>& control, Parcel* parcel);
     73 
     74     sp<Surface> getSurface() const;
     75     sp<Surface> createSurface() const;
     76     sp<IBinder> getHandle() const;
     77 
     78     sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
     79 
     80     status_t clearLayerFrameStats() const;
     81     status_t getLayerFrameStats(FrameStats* outStats) const;
     82 
     83     sp<SurfaceComposerClient> getClient() const;
     84 
     85     explicit SurfaceControl(const sp<SurfaceControl>& other);
     86 
     87     SurfaceControl(const sp<SurfaceComposerClient>& client, const sp<IBinder>& handle,
     88                    const sp<IGraphicBufferProducer>& gbp, bool owned);
     89 
     90 private:
     91     // can't be copied
     92     SurfaceControl& operator = (SurfaceControl& rhs);
     93     SurfaceControl(const SurfaceControl& rhs);
     94 
     95     friend class SurfaceComposerClient;
     96     friend class Surface;
     97 
     98     ~SurfaceControl();
     99 
    100     sp<Surface> generateSurfaceLocked() const;
    101     status_t validate() const;
    102 
    103     sp<SurfaceComposerClient>   mClient;
    104     sp<IBinder>                 mHandle;
    105     sp<IGraphicBufferProducer>  mGraphicBufferProducer;
    106     mutable Mutex               mLock;
    107     mutable sp<Surface>         mSurfaceData;
    108     bool                        mOwned;
    109 };
    110 
    111 }; // namespace android
    112 
    113 #endif // ANDROID_GUI_SURFACE_CONTROL_H
    114