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 #pragma once 17 18 #include "SkiaCanvas.h" 19 #include "SkiaDisplayList.h" 20 #include "ReorderBarrierDrawables.h" 21 #include <SkLiteRecorder.h> 22 23 namespace android { 24 namespace uirenderer { 25 namespace skiapipeline { 26 27 /** 28 * A SkiaCanvas implementation that records drawing operations for deferred rendering backed by a 29 * SkLiteRecorder and a SkiaDisplayList. 30 */ 31 class SkiaRecordingCanvas : public SkiaCanvas { 32 public: SkiaRecordingCanvas(uirenderer::RenderNode * renderNode,int width,int height)33 explicit SkiaRecordingCanvas(uirenderer::RenderNode* renderNode, int width, int height) { 34 initDisplayList(renderNode, width, height); 35 } 36 setBitmap(const SkBitmap & bitmap)37 virtual void setBitmap(const SkBitmap& bitmap) override { 38 LOG_ALWAYS_FATAL("DisplayListCanvas is not backed by a bitmap."); 39 } 40 resetRecording(int width,int height,uirenderer::RenderNode * renderNode)41 virtual void resetRecording(int width, int height, 42 uirenderer::RenderNode* renderNode) override { 43 initDisplayList(renderNode, width, height); 44 } 45 46 virtual uirenderer::DisplayList* finishRecording() override; 47 48 virtual void drawBitmap(Bitmap& bitmap, float left, float top, 49 const SkPaint* paint) override; 50 virtual void drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, 51 const SkPaint* paint) override; 52 virtual void drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop, 53 float srcRight, float srcBottom, float dstLeft, float dstTop, 54 float dstRight, float dstBottom, const SkPaint* paint) override; 55 virtual void drawNinePatch(Bitmap& hwuiBitmap, const android::Res_png_9patch& chunk, 56 float dstLeft, float dstTop, float dstRight, float dstBottom, 57 const SkPaint* paint) override; 58 59 virtual void drawRoundRect(uirenderer::CanvasPropertyPrimitive* left, 60 uirenderer::CanvasPropertyPrimitive* top, uirenderer::CanvasPropertyPrimitive* right, 61 uirenderer::CanvasPropertyPrimitive* bottom, uirenderer::CanvasPropertyPrimitive* rx, 62 uirenderer::CanvasPropertyPrimitive* ry, 63 uirenderer::CanvasPropertyPaint* paint) override; 64 virtual void drawCircle(uirenderer::CanvasPropertyPrimitive* x, 65 uirenderer::CanvasPropertyPrimitive* y, uirenderer::CanvasPropertyPrimitive* radius, 66 uirenderer::CanvasPropertyPaint* paint) override; 67 68 virtual void drawVectorDrawable(VectorDrawableRoot* vectorDrawable) override; 69 70 virtual void insertReorderBarrier(bool enableReorder) override; 71 virtual void drawLayer(uirenderer::DeferredLayerUpdater* layerHandle) override; 72 virtual void drawRenderNode(uirenderer::RenderNode* renderNode) override; 73 virtual void callDrawGLFunction(Functor* functor, 74 uirenderer::GlFunctorLifecycleListener* listener) override; 75 76 private: 77 SkLiteRecorder mRecorder; 78 std::unique_ptr<SkiaDisplayList> mDisplayList; 79 StartReorderBarrierDrawable* mCurrentBarrier; 80 81 /** 82 * A new SkiaDisplayList is created or recycled if available. 83 * 84 * @param renderNode is optional and used to recycle an old display list. 85 * @param width used to calculate recording bounds. 86 * @param height used to calculate recording bounds. 87 */ 88 void initDisplayList(uirenderer::RenderNode* renderNode, int width, int height); 89 }; 90 91 }; // namespace skiapipeline 92 }; // namespace uirenderer 93 }; // namespace android 94