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(Surface& surface, const Rect& srcRect, SkBitmap* bitmap); 51 52 CopyResult copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap); 53 54 CopyResult copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap); 55 56 private: 57 CopyResult copyImageInto(const sk_sp<SkImage>& image, Matrix4& texTransform, 58 const Rect& srcRect, SkBitmap* bitmap); 59 60 bool copyLayerInto(Layer* layer, const SkRect* srcRect, const SkRect* dstRect, 61 SkBitmap* bitmap); 62 63 renderthread::RenderThread& mRenderThread; 64 }; 65 66 } // namespace uirenderer 67 } // namespace android 68