1 /* 2 * Copyright 2022 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 #pragma once 18 19 #include <memory> 20 21 #include <compositionengine/RenderSurface.h> 22 #include <renderengine/impl/ExternalTexture.h> 23 #include <ui/Fence.h> 24 #include <ui/Size.h> 25 26 namespace android { 27 28 // ScreenCaptureRenderSurface is a RenderSurface that returns a preallocated buffer used by 29 // ScreenCaptureOutput. 30 class ScreenCaptureRenderSurface : public compositionengine::RenderSurface { 31 public: ScreenCaptureRenderSurface(std::shared_ptr<renderengine::ExternalTexture> buffer)32 ScreenCaptureRenderSurface(std::shared_ptr<renderengine::ExternalTexture> buffer) 33 : mBuffer(std::move(buffer)){}; 34 dequeueBuffer(base::unique_fd *)35 std::shared_ptr<renderengine::ExternalTexture> dequeueBuffer( 36 base::unique_fd* /* bufferFence */) override { 37 return mBuffer; 38 } 39 queueBuffer(base::unique_fd readyFence,float)40 void queueBuffer(base::unique_fd readyFence, float) override { 41 mRenderFence = sp<Fence>::make(readyFence.release()); 42 } 43 getClientTargetAcquireFence()44 const sp<Fence>& getClientTargetAcquireFence() const override { return mRenderFence; } 45 supportsCompositionStrategyPrediction()46 bool supportsCompositionStrategyPrediction() const override { return false; } 47 isValid()48 bool isValid() const override { return true; } 49 initialize()50 void initialize() override {} 51 getSize()52 const ui::Size& getSize() const override { return mSize; } 53 isProtected()54 bool isProtected() const override { return mBuffer->getUsage() & GRALLOC_USAGE_PROTECTED; } 55 setDisplaySize(const ui::Size &)56 void setDisplaySize(const ui::Size&) override {} 57 setBufferDataspace(ui::Dataspace)58 void setBufferDataspace(ui::Dataspace) override {} 59 setBufferPixelFormat(ui::PixelFormat)60 void setBufferPixelFormat(ui::PixelFormat) override {} 61 setProtected(bool)62 void setProtected(bool /* useProtected */) override {} 63 beginFrame(bool)64 status_t beginFrame(bool /* mustRecompose */) override { return OK; } 65 prepareFrame(bool,bool)66 void prepareFrame(bool /* usesClientComposition */, bool /* usesDeviceComposition */) override { 67 } 68 onPresentDisplayCompleted()69 void onPresentDisplayCompleted() override {} 70 dump(std::string &)71 void dump(std::string& /* result */) const override {} 72 73 private: 74 std::shared_ptr<renderengine::ExternalTexture> mBuffer; 75 76 sp<Fence> mRenderFence = Fence::NO_FENCE; 77 78 ui::Size mSize; 79 }; 80 81 } // namespace android 82