blob: 50ba9bff3fdebc48b619f7cf8c1d157502f936b7 [file] [log] [blame]
Patrick Williams7584c6a2022-10-29 02:10:58 +00001/*
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
26namespace android {
27
28// ScreenCaptureRenderSurface is a RenderSurface that returns a preallocated buffer used by
29// ScreenCaptureOutput.
30class ScreenCaptureRenderSurface : public compositionengine::RenderSurface {
31public:
32 ScreenCaptureRenderSurface(std::shared_ptr<renderengine::ExternalTexture> buffer)
33 : mBuffer(std::move(buffer)){};
34
35 std::shared_ptr<renderengine::ExternalTexture> dequeueBuffer(
36 base::unique_fd* /* bufferFence */) override {
37 return mBuffer;
38 }
39
Alec Mourif97df4d2023-09-06 02:10:05 +000040 void queueBuffer(base::unique_fd readyFence, float) override {
Patrick Williams7584c6a2022-10-29 02:10:58 +000041 mRenderFence = sp<Fence>::make(readyFence.release());
42 }
43
44 const sp<Fence>& getClientTargetAcquireFence() const override { return mRenderFence; }
45
46 bool supportsCompositionStrategyPrediction() const override { return false; }
47
48 bool isValid() const override { return true; }
49
50 void initialize() override {}
51
52 const ui::Size& getSize() const override { return mSize; }
53
54 bool isProtected() const override { return mBuffer->getUsage() & GRALLOC_USAGE_PROTECTED; }
55
56 void setDisplaySize(const ui::Size&) override {}
57
58 void setBufferDataspace(ui::Dataspace) override {}
59
60 void setBufferPixelFormat(ui::PixelFormat) override {}
61
62 void setProtected(bool /* useProtected */) override {}
63
64 status_t beginFrame(bool /* mustRecompose */) override { return OK; }
65
66 void prepareFrame(bool /* usesClientComposition */, bool /* usesDeviceComposition */) override {
67 }
68
69 void onPresentDisplayCompleted() override {}
70
71 void dump(std::string& /* result */) const override {}
72
73private:
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