1 /* 2 * Copyright (C) 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 <stdint.h> 20 #include <sys/types.h> 21 22 #include <binder/IBinder.h> 23 #include <binder/Parcel.h> 24 #include <binder/Parcelable.h> 25 #include <gui/SpHash.h> 26 #include <ui/GraphicTypes.h> 27 #include <ui/PixelFormat.h> 28 #include <ui/Rect.h> 29 #include <unordered_set> 30 31 namespace android::gui { 32 33 struct CaptureArgs : public Parcelable { 34 const static int32_t UNSET_UID = -1; 35 virtual ~CaptureArgs() = default; 36 37 ui::PixelFormat pixelFormat{ui::PixelFormat::RGBA_8888}; 38 Rect sourceCrop; 39 float frameScaleX{1}; 40 float frameScaleY{1}; 41 bool captureSecureLayers{false}; 42 int32_t uid{UNSET_UID}; 43 // Force capture to be in a color space. If the value is ui::Dataspace::UNKNOWN, the captured 44 // result will be in a colorspace appropriate for capturing the display contents 45 // The display may use non-RGB dataspace (ex. displayP3) that could cause pixel data could be 46 // different from SRGB (byte per color), and failed when checking colors in tests. 47 // NOTE: In normal cases, we want the screen to be captured in display's colorspace. 48 ui::Dataspace dataspace = ui::Dataspace::UNKNOWN; 49 50 // The receiver of the capture can handle protected buffer. A protected buffer has 51 // GRALLOC_USAGE_PROTECTED usage bit and must not be accessed unprotected behaviour. 52 // Any read/write access from unprotected context will result in undefined behaviour. 53 // Protected contents are typically DRM contents. This has no direct implication to the 54 // secure property of the surface, which is specified by the application explicitly to avoid 55 // the contents being accessed/captured by screenshot or unsecure display. 56 bool allowProtected = false; 57 58 bool grayscale = false; 59 60 std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles; 61 62 // Hint that the caller will use the screenshot animation as part of a transition animation. 63 // The canonical example would be screen rotation - in such a case any color shift in the 64 // screenshot is a detractor so composition in the display's colorspace is required. 65 // Otherwise, the system may choose a colorspace that is more appropriate for use-cases 66 // such as file encoding or for blending HDR content into an ap's UI, where the display's 67 // exact colorspace is not an appropriate intermediate result. 68 // Note that if the caller is requesting a specific dataspace, this hint does nothing. 69 bool hintForSeamlessTransition = false; 70 71 virtual status_t writeToParcel(Parcel* output) const; 72 virtual status_t readFromParcel(const Parcel* input); 73 }; 74 75 struct DisplayCaptureArgs : CaptureArgs { 76 sp<IBinder> displayToken; 77 uint32_t width{0}; 78 uint32_t height{0}; 79 bool useIdentityTransform{false}; 80 81 status_t writeToParcel(Parcel* output) const override; 82 status_t readFromParcel(const Parcel* input) override; 83 }; 84 85 }; // namespace android::gui 86