| 1 | /* |
| 2 | * Copyright (C) 2020 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 | package android.view; |
| 18 | |
| 19 | import static java.util.Objects.requireNonNull; |
| 20 | |
| 21 | import android.annotation.NonNull; |
| 22 | import android.graphics.Point; |
| 23 | import android.graphics.Rect; |
| 24 | |
| 25 | /** |
| 26 | * A session represents the scope of interaction between a {@link ScrollCaptureCallback} and the |
| 27 | * system during an active scroll capture operation. |
| 28 | */ |
| 29 | public class ScrollCaptureSession { |
| 30 | |
| 31 | private final Surface mSurface; |
| 32 | private final Rect mScrollBounds; |
| 33 | private final Point mPositionInWindow; |
| 34 | |
| 35 | /** |
| 36 | * Constructs a new session instance. |
| 37 | * |
| 38 | * @param surface the surface to consume generated images |
| 39 | * @param scrollBounds the bounds of the capture area within the containing view |
| 40 | * @param positionInWindow the offset of scrollBounds within the window |
| 41 | */ |
| 42 | public ScrollCaptureSession(@NonNull Surface surface, @NonNull Rect scrollBounds, |
| 43 | @NonNull Point positionInWindow) { |
| 44 | mSurface = requireNonNull(surface); |
| 45 | mScrollBounds = requireNonNull(scrollBounds); |
| 46 | mPositionInWindow = requireNonNull(positionInWindow); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Returns a |
| 51 | * <a href="https://source.android.com/devices/graphics/arch-bq-gralloc">BufferQueue</a> in the |
| 52 | * form of a {@link Surface} for transfer of image buffers. |
| 53 | * <p> |
| 54 | * The surface is guaranteed to remain {@link Surface#isValid() valid} until the session |
| 55 | * {@link ScrollCaptureCallback#onScrollCaptureEnd(Runnable) ends}. |
| 56 | * |
| 57 | * @return the surface for transferring image buffers |
| 58 | * @throws IllegalStateException if the session has been closed |
| 59 | */ |
| 60 | @NonNull |
| 61 | public Surface getSurface() { |
| 62 | return mSurface; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns the {@code scroll bounds}, as provided by |
| 67 | * {@link ScrollCaptureCallback#onScrollCaptureSearch}. |
| 68 | * |
| 69 | * @return the area of scrolling content within the containing view |
| 70 | */ |
| 71 | @NonNull |
| 72 | public Rect getScrollBounds() { |
| 73 | return mScrollBounds; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the offset of {@code scroll bounds} within the window. |
| 78 | * |
| 79 | * @return the area of scrolling content within the containing view |
| 80 | */ |
| 81 | @NonNull |
| 82 | public Point getPositionInWindow() { |
| 83 | return mPositionInWindow; |
| 84 | } |
| 85 | } |