1 /* 2 * Copyright (C) 2019 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 FRAME_CAPTURE_PROCESSOR_H_ 18 #define FRAME_CAPTURE_PROCESSOR_H_ 19 20 #include <media/stagefright/foundation/ABase.h> 21 #include <media/stagefright/foundation/AHandler.h> 22 23 namespace android { 24 25 struct AMessage; 26 class GraphicBuffer; 27 class Rect; 28 29 namespace renderengine { 30 class RenderEngine; 31 struct LayerSettings; 32 } 33 34 /* 35 * Process a decoded graphic buffer through RenderEngine to 36 * convert it to sRGB. 37 * 38 * This class is a singleton that holds one instance of RenderEngine 39 * and its event queue (on which the GL context runs). The RenderEngine 40 * is created upon the first getInstance(). 41 */ 42 class FrameCaptureProcessor : public AHandler { 43 44 public: 45 46 struct Layer : public RefBase { 47 virtual void getLayerSettings( 48 const Rect &sourceCrop, uint32_t textureName, 49 renderengine::LayerSettings *layerSettings) = 0; 50 }; 51 52 static sp<FrameCaptureProcessor> getInstance(); 53 54 status_t capture( 55 const sp<Layer> &layer, 56 const Rect &sourceCrop, const sp<GraphicBuffer> &outBuffer); 57 58 protected: 59 virtual ~FrameCaptureProcessor(); 60 void onMessageReceived(const sp<AMessage> &msg); 61 62 private: 63 FrameCaptureProcessor(); 64 65 enum { 66 kWhatCreate, 67 kWhatCapture, 68 }; 69 70 static Mutex sLock; 71 static sp<FrameCaptureProcessor> sInstance GUARDED_BY(sLock); 72 73 constexpr static float sDefaultMaxLumiance = 500.0f; 74 75 status_t mInitStatus; 76 sp<ALooper> mLooper; 77 std::unique_ptr<renderengine::RenderEngine> mRE; 78 uint32_t mTextureName; 79 80 static status_t PostAndAwaitResponse( 81 const sp<AMessage> &msg, sp<AMessage> *response); 82 static void PostReplyWithError( 83 const sp<AReplyToken> &replyID, status_t err); 84 initCheck()85 status_t initCheck() { return mInitStatus; } 86 void createRenderEngine(); 87 88 // message handlers 89 status_t onCreate(); 90 status_t onCapture(const sp<Layer> &layer, 91 const Rect &sourceCrop, const sp<GraphicBuffer> &outBuffer); 92 93 DISALLOW_EVIL_CONSTRUCTORS(FrameCaptureProcessor); 94 }; 95 96 } // namespace android 97 98 #endif // FRAME_CAPTURE_PROCESSOR_H_ 99