BakedOpRenderer.h revision 9fded232a9548a304e0145011df8849fba0dcda7
1/* 2 * Copyright (C) 2015 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#ifndef ANDROID_HWUI_BAKED_OP_RENDERER_H 18#define ANDROID_HWUI_BAKED_OP_RENDERER_H 19 20#include "BakedOpState.h" 21#include "Matrix.h" 22 23namespace android { 24namespace uirenderer { 25 26class Caches; 27struct Glop; 28class Layer; 29class RenderState; 30 31/** 32 * Main rendering manager for a collection of work - one frame + any contained FBOs. 33 * 34 * Manages frame and FBO lifecycle, binding the GL framebuffer as appropriate. This is the only 35 * place where FBOs are bound, created, and destroyed. 36 * 37 * All rendering operations will be sent by the Dispatcher, a collection of static methods, 38 * which has intentionally limited access to the renderer functionality. 39 */ 40class BakedOpRenderer { 41public: 42 BakedOpRenderer(Caches& caches, RenderState& renderState, bool opaque) 43 : mRenderState(renderState) 44 , mCaches(caches) 45 , mOpaque(opaque) { 46 } 47 48 RenderState& renderState() { return mRenderState; } 49 Caches& caches() { return mCaches; } 50 51 void startFrame(uint32_t width, uint32_t height); 52 void endFrame(); 53 OffscreenBuffer* startTemporaryLayer(uint32_t width, uint32_t height); 54 void startRepaintLayer(OffscreenBuffer* offscreenBuffer); 55 void endLayer(); 56 57 Texture* getTexture(const SkBitmap* bitmap); 58 59 void renderGlop(const BakedOpState& state, const Glop& glop); 60 bool didDraw() { return mHasDrawn; } 61private: 62 void setViewport(uint32_t width, uint32_t height); 63 64 RenderState& mRenderState; 65 Caches& mCaches; 66 bool mOpaque; 67 bool mHasDrawn = false; 68 69 // render target state - setup by start/end layer/frame 70 // only valid to use in between start/end pairs. 71 struct { 72 GLuint frameBufferId = 0; 73 OffscreenBuffer* offscreenBuffer = nullptr; 74 uint32_t viewportWidth = 0; 75 uint32_t viewportHeight = 0; 76 Matrix4 orthoMatrix; 77 } mRenderTarget; 78}; 79 80/** 81 * Provides all "onBitmapOp(...)" style static methods for every op type, which convert the 82 * RecordedOps and their state to Glops, and renders them with the provided BakedOpRenderer. 83 * 84 * This dispatcher is separate from the renderer so that the dispatcher / renderer interaction is 85 * minimal through public BakedOpRenderer APIs. 86 */ 87class BakedOpDispatcher { 88public: 89 // Declares all "onBitmapOp(...)" style methods for every op type 90#define DISPATCH_METHOD(Type) \ 91 static void on##Type(BakedOpRenderer& renderer, const Type& op, const BakedOpState& state); 92 MAP_OPS(DISPATCH_METHOD); 93}; 94 95}; // namespace uirenderer 96}; // namespace android 97 98#endif // ANDROID_HWUI_BAKED_OP_RENDERER_H 99