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