1 /* 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 19 #include "Matrix.h" 20 #include "Rect.h" 21 #include "renderthread/RenderThread.h" 22 23 #include <SkBitmap.h> 24 25 namespace android { 26 class Bitmap; 27 class GraphicBuffer; 28 class Surface; 29 namespace uirenderer { 30 31 class DeferredLayerUpdater; 32 class Layer; 33 34 // Keep in sync with PixelCopy.java codes 35 enum class CopyResult { 36 Success = 0, 37 UnknownError = 1, 38 Timeout = 2, 39 SourceEmpty = 3, 40 SourceInvalid = 4, 41 DestinationInvalid = 5, 42 }; 43 44 class Readback { 45 public: Readback(renderthread::RenderThread & thread)46 explicit Readback(renderthread::RenderThread& thread) : mRenderThread(thread) {} 47 /** 48 * Copies the surface's most recently queued buffer into the provided bitmap. 49 */ 50 CopyResult copySurfaceInto(ANativeWindow* window, const Rect& srcRect, SkBitmap* bitmap); 51 52 CopyResult copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap); 53 CopyResult copyImageInto(const sk_sp<SkImage>& image, SkBitmap* bitmap); 54 55 CopyResult copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap); 56 57 private: 58 CopyResult copySurfaceIntoLegacy(ANativeWindow* window, const Rect& srcRect, SkBitmap* bitmap); 59 CopyResult copyImageInto(const sk_sp<SkImage>& image, Matrix4& texTransform, 60 const Rect& srcRect, SkBitmap* bitmap); 61 62 bool copyLayerInto(Layer* layer, const SkRect* srcRect, const SkRect* dstRect, 63 SkBitmap* bitmap); 64 65 renderthread::RenderThread& mRenderThread; 66 }; 67 68 } // namespace uirenderer 69 } // namespace android 70