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/RefBase.h> 24 #include <utils/threads.h> 25 26 #include <ui/FrameStats.h> 27 #include <ui/PixelFormat.h> 28 #include <ui/Region.h> 29 30 #include <gui/ISurfaceComposerClient.h> 31 #include <math/vec3.h> 32 33 namespace android { 34 35 // --------------------------------------------------------------------------- 36 37 class IGraphicBufferProducer; 38 class Surface; 39 class SurfaceComposerClient; 40 class BLASTBufferQueue; 41 42 // --------------------------------------------------------------------------- 43 44 class SurfaceControl : public RefBase 45 { 46 public: 47 static status_t readFromParcel(const Parcel& parcel, sp<SurfaceControl>* outSurfaceControl); 48 status_t writeToParcel(Parcel& parcel); 49 50 static status_t readNullableFromParcel(const Parcel& parcel, 51 sp<SurfaceControl>* outSurfaceControl); 52 static status_t writeNullableToParcel(Parcel& parcel, const sp<SurfaceControl>& surfaceControl); 53 isValid(const sp<SurfaceControl> & surface)54 static bool isValid(const sp<SurfaceControl>& surface) { 55 return (surface != nullptr) && surface->isValid(); 56 } 57 isValid()58 bool isValid() { 59 return mHandle!=nullptr && mClient!=nullptr; 60 } 61 62 static bool isSameSurface( 63 const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs); 64 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(); 75 sp<Surface> createSurface(); 76 sp<IBinder> getHandle() const; 77 sp<IBinder> getLayerStateHandle() const; 78 int32_t getLayerId() const; 79 80 sp<IGraphicBufferProducer> getIGraphicBufferProducer(); 81 82 status_t clearLayerFrameStats() const; 83 status_t getLayerFrameStats(FrameStats* outStats) const; 84 85 sp<SurfaceComposerClient> getClient() const; 86 87 uint32_t getTransformHint() const; 88 89 void setTransformHint(uint32_t hint); 90 void updateDefaultBufferSize(uint32_t width, uint32_t height); 91 92 explicit SurfaceControl(const sp<SurfaceControl>& other); 93 94 SurfaceControl(const sp<SurfaceComposerClient>& client, const sp<IBinder>& handle, 95 const sp<IGraphicBufferProducer>& gbp, int32_t layerId, 96 uint32_t width = 0, uint32_t height = 0, PixelFormat format = 0, 97 uint32_t transformHint = 0, uint32_t flags = 0); 98 99 sp<SurfaceControl> getParentingLayer(); 100 101 private: 102 // can't be copied 103 SurfaceControl& operator = (SurfaceControl& rhs); 104 SurfaceControl(const SurfaceControl& rhs); 105 106 friend class SurfaceComposerClient; 107 friend class Surface; 108 109 ~SurfaceControl(); 110 111 sp<Surface> generateSurfaceLocked(); 112 status_t validate() const; 113 114 sp<SurfaceComposerClient> mClient; 115 sp<IBinder> mHandle; 116 sp<IGraphicBufferProducer> mGraphicBufferProducer; 117 mutable Mutex mLock; 118 mutable sp<Surface> mSurfaceData; 119 mutable sp<BLASTBufferQueue> mBbq; 120 mutable sp<SurfaceControl> mBbqChild; 121 int32_t mLayerId; 122 uint32_t mTransformHint; 123 uint32_t mWidth; 124 uint32_t mHeight; 125 PixelFormat mFormat; 126 uint32_t mCreateFlags; 127 }; 128 129 }; // namespace android 130 131 #endif // ANDROID_GUI_SURFACE_CONTROL_H 132