blob: aa6e43c3bc2746f40c4a5cd8c8aaa6b73088ffca [file] [log] [blame]
John Reck10dd0582016-03-31 16:36:16 -07001/*
2 * Copyright (C) 2016 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
Stan Iliev1a025a72018-09-05 16:35:11 -040019#include "Matrix.h"
John Reck95801462016-09-01 09:44:09 -070020#include "Rect.h"
John Reck1bcacfd2017-11-03 10:12:19 -070021#include "renderthread/RenderThread.h"
John Reck10dd0582016-03-31 16:36:16 -070022
Kevin Lubick1175dc02022-02-28 12:41:27 -050023#include <SkRefCnt.h>
24
25class SkBitmap;
26class SkImage;
27struct SkRect;
John Reck10dd0582016-03-31 16:36:16 -070028
29namespace android {
Stan Iliev1a025a72018-09-05 16:35:11 -040030class Bitmap;
sergeyv59eecb522016-11-17 17:54:57 -080031class GraphicBuffer;
Mathias Agopian3d7d5f92017-05-01 15:13:20 -070032class Surface;
John Reck10dd0582016-03-31 16:36:16 -070033namespace uirenderer {
34
Stan Iliev1a025a72018-09-05 16:35:11 -040035class DeferredLayerUpdater;
36class Layer;
37
John Recke94cbc72016-04-25 13:03:44 -070038// Keep in sync with PixelCopy.java codes
39enum class CopyResult {
40 Success = 0,
41 UnknownError = 1,
42 Timeout = 2,
43 SourceEmpty = 3,
44 SourceInvalid = 4,
45 DestinationInvalid = 5,
46};
47
John Reck10dd0582016-03-31 16:36:16 -070048class Readback {
49public:
Stan Iliev1a025a72018-09-05 16:35:11 -040050 explicit Readback(renderthread::RenderThread& thread) : mRenderThread(thread) {}
Chris Craik764045d2016-07-06 17:14:05 -070051 /**
52 * Copies the surface's most recently queued buffer into the provided bitmap.
53 */
Alec Mouri8a82b142019-12-17 09:41:48 -080054 CopyResult copySurfaceInto(ANativeWindow* window, const Rect& srcRect, SkBitmap* bitmap);
Chris Craik764045d2016-07-06 17:14:05 -070055
Stan Iliev1a025a72018-09-05 16:35:11 -040056 CopyResult copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap);
John Reck76005182021-06-09 22:43:05 -040057 CopyResult copyImageInto(const sk_sp<SkImage>& image, SkBitmap* bitmap);
Stan Iliev1a025a72018-09-05 16:35:11 -040058
59 CopyResult copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);
60
61private:
John Reck2abc5492021-05-18 00:34:26 -040062 CopyResult copySurfaceIntoLegacy(ANativeWindow* window, const Rect& srcRect, SkBitmap* bitmap);
ramindani3952ed62021-08-12 15:55:12 +000063 CopyResult copyImageInto(const sk_sp<SkImage>& image, const Rect& srcRect, SkBitmap* bitmap);
Stan Iliev1a025a72018-09-05 16:35:11 -040064
65 bool copyLayerInto(Layer* layer, const SkRect* srcRect, const SkRect* dstRect,
66 SkBitmap* bitmap);
Derek Sollenbergerc4fbada2016-11-07 16:05:41 -050067
68 renderthread::RenderThread& mRenderThread;
John Reck10dd0582016-03-31 16:36:16 -070069};
70
John Reck1bcacfd2017-11-03 10:12:19 -070071} // namespace uirenderer
72} // namespace android