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