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 #include <optional> 23 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 class BLASTBufferQueue; 42 43 // --------------------------------------------------------------------------- 44 45 class SurfaceControl : public RefBase 46 { 47 public: 48 static status_t readFromParcel(const Parcel& parcel, sp<SurfaceControl>* outSurfaceControl); 49 status_t writeToParcel(Parcel& parcel); 50 51 static status_t readNullableFromParcel(const Parcel& parcel, 52 sp<SurfaceControl>* outSurfaceControl); 53 static status_t writeNullableToParcel(Parcel& parcel, const sp<SurfaceControl>& surfaceControl); 54 isValid(const sp<SurfaceControl> & surface)55 static bool isValid(const sp<SurfaceControl>& surface) { 56 return (surface != nullptr) && surface->isValid(); 57 } 58 isValid()59 bool isValid() { 60 return mHandle!=nullptr && mClient!=nullptr; 61 } 62 63 static bool isSameSurface( 64 const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs); 65 66 // Reparent off-screen and release. This is invoked by the destructor. 67 void destroy(); 68 69 // disconnect any api that's connected 70 void disconnect(); 71 72 static status_t writeSurfaceToParcel( 73 const sp<SurfaceControl>& control, Parcel* parcel); 74 75 sp<Surface> getSurface(); 76 sp<Surface> createSurface(); 77 sp<IBinder> getHandle() const; 78 sp<IBinder> getLayerStateHandle() const; 79 int32_t getLayerId() const; 80 81 sp<IGraphicBufferProducer> getIGraphicBufferProducer(); 82 83 status_t clearLayerFrameStats() const; 84 status_t getLayerFrameStats(FrameStats* outStats) const; 85 86 sp<SurfaceComposerClient> getClient() const; 87 88 uint32_t getTransformHint() const; 89 90 void setTransformHint(uint32_t hint); 91 void updateDefaultBufferSize(uint32_t width, uint32_t height); 92 93 explicit SurfaceControl(const sp<SurfaceControl>& other); 94 95 SurfaceControl(const sp<SurfaceComposerClient>& client, const sp<IBinder>& handle, 96 const sp<IGraphicBufferProducer>& gbp, int32_t layerId, 97 uint32_t width = 0, uint32_t height = 0, PixelFormat format = 0, 98 uint32_t transformHint = 0, uint32_t flags = 0); 99 100 sp<SurfaceControl> getParentingLayer(); 101 102 uint64_t resolveFrameNumber(const std::optional<uint64_t>& frameNumber); 103 104 private: 105 // can't be copied 106 SurfaceControl& operator = (SurfaceControl& rhs); 107 SurfaceControl(const SurfaceControl& rhs); 108 109 friend class SurfaceComposerClient; 110 friend class Surface; 111 112 ~SurfaceControl(); 113 114 sp<Surface> generateSurfaceLocked(); 115 status_t validate() const; 116 117 sp<SurfaceComposerClient> mClient; 118 sp<IBinder> mHandle; 119 sp<IGraphicBufferProducer> mGraphicBufferProducer; 120 mutable Mutex mLock; 121 mutable sp<Surface> mSurfaceData; 122 mutable sp<BLASTBufferQueue> mBbq; 123 mutable sp<SurfaceControl> mBbqChild; 124 int32_t mLayerId = 0; 125 uint32_t mTransformHint = 0; 126 uint32_t mWidth = 0; 127 uint32_t mHeight = 0; 128 PixelFormat mFormat = PIXEL_FORMAT_NONE; 129 uint32_t mCreateFlags = 0; 130 uint64_t mFallbackFrameNumber = 100; 131 }; 132 133 }; // namespace android 134 135 #endif // ANDROID_GUI_SURFACE_CONTROL_H 136