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 34namespace android { 35 36// --------------------------------------------------------------------------- 37 38class IGraphicBufferProducer; 39class Surface; 40class SurfaceComposerClient; 41 42// --------------------------------------------------------------------------- 43 44class SurfaceControl : public RefBase 45{ 46public: 47 static sp<SurfaceControl> readFromParcel(Parcel* parcel); 48 void writeToParcel(Parcel* parcel); 49 50 static bool isValid(const sp<SurfaceControl>& surface) { 51 return (surface != 0) && surface->isValid(); 52 } 53 54 bool isValid() { 55 return mHandle!=0 && mClient!=0; 56 } 57 58 static bool isSameSurface( 59 const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs); 60 61 // release surface data from java 62 void clear(); 63 64 // disconnect any api that's connected 65 void disconnect(); 66 67 static status_t writeSurfaceToParcel( 68 const sp<SurfaceControl>& control, Parcel* parcel); 69 70 sp<Surface> getSurface() const; 71 sp<Surface> createSurface() const; 72 sp<IBinder> getHandle() const; 73 74 status_t clearLayerFrameStats() const; 75 status_t getLayerFrameStats(FrameStats* outStats) const; 76 77 sp<SurfaceComposerClient> getClient() const; 78 79private: 80 // can't be copied 81 SurfaceControl& operator = (SurfaceControl& rhs); 82 SurfaceControl(const SurfaceControl& rhs); 83 84 friend class SurfaceComposerClient; 85 friend class Surface; 86 87 SurfaceControl( 88 const sp<SurfaceComposerClient>& client, 89 const sp<IBinder>& handle, 90 const sp<IGraphicBufferProducer>& gbp, 91 bool owned); 92 93 ~SurfaceControl(); 94 95 sp<Surface> generateSurfaceLocked() const; 96 status_t validate() const; 97 void destroy(); 98 99 sp<SurfaceComposerClient> mClient; 100 sp<IBinder> mHandle; 101 sp<IGraphicBufferProducer> mGraphicBufferProducer; 102 mutable Mutex mLock; 103 mutable sp<Surface> mSurfaceData; 104 bool mOwned; 105}; 106 107}; // namespace android 108 109#endif // ANDROID_GUI_SURFACE_CONTROL_H 110