BakedOpRenderer.h revision 0b7e8245db728d127ada698be63d78b33fc6e4da
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 * Lightweight alternative to Layer. Owns the persistent state of an offscreen render target, and 33 * encompasses enough information to draw it back on screen (minus paint properties, which are held 34 * by LayerOp). 35 */ 36class OffscreenBuffer { 37public: 38 OffscreenBuffer(Caches& caches, uint32_t textureWidth, uint32_t textureHeight, 39 uint32_t viewportWidth, uint32_t viewportHeight); 40 uint32_t viewportWidth; 41 uint32_t viewportHeight; 42 Texture texture; 43 Rect texCoords; 44 Region region; 45}; 46 47/** 48 * Main rendering manager for a collection of work - one frame + any contained FBOs. 49 * 50 * Manages frame and FBO lifecycle, binding the GL framebuffer as appropriate. This is the only 51 * place where FBOs are bound, created, and destroyed. 52 * 53 * All rendering operations will be sent by the Dispatcher, a collection of static methods, 54 * which has intentionally limited access to the renderer functionality. 55 */ 56class BakedOpRenderer { 57public: 58 BakedOpRenderer(Caches& caches, RenderState& renderState, bool opaque) 59 : mRenderState(renderState) 60 , mCaches(caches) 61 , mOpaque(opaque) { 62 } 63 64 static OffscreenBuffer* createOffscreenBuffer(uint32_t width, uint32_t height); 65 static void destroyOffscreenBuffer(OffscreenBuffer*); 66 67 RenderState& renderState() { return mRenderState; } 68 Caches& caches() { return mCaches; } 69 70 void startFrame(uint32_t width, uint32_t height); 71 void endFrame(); 72 OffscreenBuffer* createLayer(uint32_t width, uint32_t height); 73 void startLayer(OffscreenBuffer* offscreenBuffer); 74 void endLayer(); 75 76 Texture* getTexture(const SkBitmap* bitmap); 77 78 void renderGlop(const BakedOpState& state, const Glop& glop); 79 bool didDraw() { return mHasDrawn; } 80private: 81 void setViewport(uint32_t width, uint32_t height); 82 83 RenderState& mRenderState; 84 Caches& mCaches; 85 bool mOpaque; 86 bool mHasDrawn = false; 87 88 // render target state - setup by start/end layer/frame 89 // only valid to use in between start/end pairs. 90 struct { 91 GLuint frameBufferId = 0; 92 OffscreenBuffer* offscreenBuffer = nullptr; 93 uint32_t viewportWidth = 0; 94 uint32_t viewportHeight = 0; 95 Matrix4 orthoMatrix; 96 } mRenderTarget; 97}; 98 99/** 100 * Provides all "onBitmapOp(...)" style static methods for every op type, which convert the 101 * RecordedOps and their state to Glops, and renders them with the provided BakedOpRenderer. 102 * 103 * This dispatcher is separate from the renderer so that the dispatcher / renderer interaction is 104 * minimal through public BakedOpRenderer APIs. 105 */ 106class BakedOpDispatcher { 107public: 108 // Declares all "onBitmapOp(...)" style methods for every op type 109#define DISPATCH_METHOD(Type) \ 110 static void on##Type(BakedOpRenderer& renderer, const Type& op, const BakedOpState& state); 111 MAP_OPS(DISPATCH_METHOD); 112}; 113 114}; // namespace uirenderer 115}; // namespace android 116 117#endif // ANDROID_HWUI_BAKED_OP_RENDERER_H 118