OpenGLRenderer.h revision 64e445bf74bee2098781d608cedfd723d8cc88d3
1/* 2 * Copyright (C) 2010 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_OPENGL_RENDERER_H 18#define ANDROID_HWUI_OPENGL_RENDERER_H 19 20#include "CanvasState.h" 21#include "Debug.h" 22#include "Extensions.h" 23#include "Matrix.h" 24#include "Program.h" 25#include "Rect.h" 26#include "Snapshot.h" 27#include "UvMapper.h" 28#include "Vertex.h" 29#include "Caches.h" 30#include "utils/PaintUtils.h" 31 32#include <GLES2/gl2.h> 33#include <GLES2/gl2ext.h> 34 35#include <SkBitmap.h> 36#include <SkCanvas.h> 37#include <SkColorFilter.h> 38#include <SkDrawLooper.h> 39#include <SkMatrix.h> 40#include <SkPaint.h> 41#include <SkRegion.h> 42#include <SkXfermode.h> 43 44#include <utils/Blur.h> 45#include <utils/Functor.h> 46#include <utils/RefBase.h> 47#include <utils/SortedVector.h> 48 49#include <cutils/compiler.h> 50 51#include <androidfw/ResourceTypes.h> 52 53#include <vector> 54 55class SkShader; 56 57namespace android { 58namespace uirenderer { 59 60enum class DrawOpMode { 61 kImmediate, 62 kDefer, 63 kFlush 64}; 65 66class DeferredDisplayState; 67struct Glop; 68class RenderState; 69class RenderNode; 70class TextDrawFunctor; 71class VertexBuffer; 72 73enum StateDeferFlags { 74 kStateDeferFlag_Draw = 0x1, 75 kStateDeferFlag_Clip = 0x2 76}; 77 78enum ClipSideFlags { 79 kClipSide_None = 0x0, 80 kClipSide_Left = 0x1, 81 kClipSide_Top = 0x2, 82 kClipSide_Right = 0x4, 83 kClipSide_Bottom = 0x8, 84 kClipSide_Full = 0xF, 85 kClipSide_ConservativeFull = 0x1F 86}; 87 88enum VertexBufferDisplayFlags { 89 kVertexBuffer_Offset = 0x1, 90 kVertexBuffer_ShadowInterp = 0x2, 91}; 92 93/** 94 * Defines additional transformation that should be applied by the model view matrix, beyond that of 95 * the currentTransform() 96 */ 97enum ModelViewMode { 98 /** 99 * Used when the model view should simply translate geometry passed to the shader. The resulting 100 * matrix will be a simple translation. 101 */ 102 kModelViewMode_Translate = 0, 103 104 /** 105 * Used when the model view should translate and scale geometry. The resulting matrix will be a 106 * translation + scale. This is frequently used together with VBO 0, the (0,0,1,1) rect. 107 */ 108 kModelViewMode_TranslateAndScale = 1, 109}; 110 111/////////////////////////////////////////////////////////////////////////////// 112// Renderer 113/////////////////////////////////////////////////////////////////////////////// 114/** 115 * OpenGL Renderer implementation. 116 */ 117class OpenGLRenderer : public CanvasStateClient { 118public: 119 OpenGLRenderer(RenderState& renderState); 120 virtual ~OpenGLRenderer(); 121 122 void initProperties(); 123 void initLight(float lightRadius, uint8_t ambientShadowAlpha, 124 uint8_t spotShadowAlpha); 125 void setLightCenter(const Vector3& lightCenter); 126 127 /* 128 * Prepares the renderer to draw a frame. This method must be invoked 129 * at the beginning of each frame. Only the specified rectangle of the 130 * frame is assumed to be dirty. A clip will automatically be set to 131 * the specified rectangle. 132 * 133 * @param opaque If true, the target surface is considered opaque 134 * and will not be cleared. If false, the target surface 135 * will be cleared 136 */ 137 virtual void prepareDirty(int viewportWidth, int viewportHeight, 138 float left, float top, float right, float bottom, bool opaque); 139 140 /** 141 * Indicates the end of a frame. This method must be invoked whenever 142 * the caller is done rendering a frame. 143 * Returns true if any drawing was done during the frame (the output 144 * has changed / is "dirty" and should be displayed to the user). 145 */ 146 virtual bool finish(); 147 148 void callDrawGLFunction(Functor* functor, Rect& dirty); 149 150 void pushLayerUpdate(Layer* layer); 151 void cancelLayerUpdate(Layer* layer); 152 void flushLayerUpdates(); 153 void markLayersAsBuildLayers(); 154 155 virtual int saveLayer(float left, float top, float right, float bottom, 156 const SkPaint* paint, int flags) { 157 return saveLayer(left, top, right, bottom, paint, flags, nullptr); 158 } 159 160 // Specialized saveLayer implementation, which will pass the convexMask to an FBO layer, if 161 // created, which will in turn clip to that mask when drawn back/restored. 162 int saveLayer(float left, float top, float right, float bottom, 163 const SkPaint* paint, int flags, const SkPath* convexMask); 164 165 int saveLayerDeferred(float left, float top, float right, float bottom, 166 const SkPaint* paint, int flags); 167 168 void drawRenderNode(RenderNode* displayList, Rect& dirty, int32_t replayFlags = 1); 169 void drawLayer(Layer* layer); 170 void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint); 171 void drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount, 172 TextureVertex* vertices, bool pureTranslate, const Rect& bounds, const SkPaint* paint); 173 void drawBitmap(const SkBitmap* bitmap, Rect src, Rect dst, 174 const SkPaint* paint); 175 void drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight, 176 const float* vertices, const int* colors, const SkPaint* paint); 177 void drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry, 178 TextureVertex* vertices, uint32_t indexCount, const SkPaint* paint); 179 void drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry, 180 float left, float top, float right, float bottom, const SkPaint* paint); 181 void drawColor(int color, SkXfermode::Mode mode); 182 void drawRect(float left, float top, float right, float bottom, 183 const SkPaint* paint); 184 void drawRoundRect(float left, float top, float right, float bottom, 185 float rx, float ry, const SkPaint* paint); 186 void drawCircle(float x, float y, float radius, const SkPaint* paint); 187 void drawOval(float left, float top, float right, float bottom, 188 const SkPaint* paint); 189 void drawArc(float left, float top, float right, float bottom, 190 float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint); 191 void drawPath(const SkPath* path, const SkPaint* paint); 192 void drawLines(const float* points, int count, const SkPaint* paint); 193 void drawPoints(const float* points, int count, const SkPaint* paint); 194 void drawTextOnPath(const char* text, int bytesCount, int count, const SkPath* path, 195 float hOffset, float vOffset, const SkPaint* paint); 196 void drawPosText(const char* text, int bytesCount, int count, 197 const float* positions, const SkPaint* paint); 198 void drawText(const char* text, int bytesCount, int count, float x, float y, 199 const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds, 200 DrawOpMode drawOpMode = DrawOpMode::kImmediate); 201 void drawRects(const float* rects, int count, const SkPaint* paint); 202 203 void drawShadow(float casterAlpha, 204 const VertexBuffer* ambientShadowVertexBuffer, 205 const VertexBuffer* spotShadowVertexBuffer); 206 207 void setDrawFilter(SkDrawFilter* filter); 208 209 /** 210 * Store the current display state (most importantly, the current clip and transform), and 211 * additionally map the state's bounds from local to window coordinates. 212 * 213 * Returns true if quick-rejected 214 */ 215 bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags); 216 void restoreDisplayState(const DeferredDisplayState& state, bool skipClipRestore = false); 217 void setupMergedMultiDraw(const Rect* clipRect); 218 219 bool isCurrentTransformSimple() { 220 return currentTransform()->isSimple(); 221 } 222 223 Caches& getCaches() { 224 return mCaches; 225 } 226 227 RenderState& renderState() { 228 return mRenderState; 229 } 230 231 int getViewportWidth() { return mState.getViewportWidth(); } 232 int getViewportHeight() { return mState.getViewportHeight(); } 233 234 /** 235 * Scales the alpha on the current snapshot. This alpha value will be modulated 236 * with other alpha values when drawing primitives. 237 */ 238 void scaleAlpha(float alpha) { mState.scaleAlpha(alpha); } 239 240 /** 241 * Inserts a named event marker in the stream of GL commands. 242 */ 243 void eventMark(const char* name) const; 244 245 /** 246 * Inserts a formatted event marker in the stream of GL commands. 247 */ 248 void eventMarkDEBUG(const char *fmt, ...) const; 249 250 /** 251 * Inserts a named group marker in the stream of GL commands. This marker 252 * can be used by tools to group commands into logical groups. A call to 253 * this method must always be followed later on by a call to endMark(). 254 */ 255 void startMark(const char* name) const; 256 257 /** 258 * Closes the last group marker opened by startMark(). 259 */ 260 void endMark() const; 261 262 /** 263 * Gets the alpha and xfermode out of a paint object. If the paint is null 264 * alpha will be 255 and the xfermode will be SRC_OVER. This method does 265 * not multiply the paint's alpha by the current snapshot's alpha, and does 266 * not replace the alpha with the overrideLayerAlpha 267 * 268 * @param paint The paint to extract values from 269 * @param alpha Where to store the resulting alpha 270 * @param mode Where to store the resulting xfermode 271 */ 272 static inline void getAlphaAndModeDirect(const SkPaint* paint, int* alpha, 273 SkXfermode::Mode* mode) { 274 *mode = getXfermodeDirect(paint); 275 *alpha = getAlphaDirect(paint); 276 } 277 278 static inline SkXfermode::Mode getXfermodeDirect(const SkPaint* paint) { 279 if (!paint) return SkXfermode::kSrcOver_Mode; 280 return PaintUtils::getXfermode(paint->getXfermode()); 281 } 282 283 static inline int getAlphaDirect(const SkPaint* paint) { 284 if (!paint) return 255; 285 return paint->getAlpha(); 286 } 287 288 struct TextShadow { 289 SkScalar radius; 290 float dx; 291 float dy; 292 SkColor color; 293 }; 294 295 static inline bool getTextShadow(const SkPaint* paint, TextShadow* textShadow) { 296 SkDrawLooper::BlurShadowRec blur; 297 if (paint && paint->getLooper() && paint->getLooper()->asABlurShadow(&blur)) { 298 if (textShadow) { 299 textShadow->radius = Blur::convertSigmaToRadius(blur.fSigma); 300 textShadow->dx = blur.fOffset.fX; 301 textShadow->dy = blur.fOffset.fY; 302 textShadow->color = blur.fColor; 303 } 304 return true; 305 } 306 return false; 307 } 308 309 static inline bool hasTextShadow(const SkPaint* paint) { 310 return getTextShadow(paint, nullptr); 311 } 312 313 /** 314 * Build the best transform to use to rasterize text given a full 315 * transform matrix, and whether filteration is needed. 316 * 317 * Returns whether filtration is needed 318 */ 319 bool findBestFontTransform(const mat4& transform, SkMatrix* outMatrix) const; 320 321#if DEBUG_MERGE_BEHAVIOR 322 void drawScreenSpaceColorRect(float left, float top, float right, float bottom, int color) { 323 mCaches.setScissorEnabled(false); 324 325 // should only be called outside of other draw ops, so stencil can only be in test state 326 bool stencilWasEnabled = mCaches.stencil.isTestEnabled(); 327 mCaches.stencil.disable(); 328 329 drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true); 330 331 if (stencilWasEnabled) mCaches.stencil.enableTest(); 332 mDirty = true; 333 } 334#endif 335 336 const Vector3& getLightCenter() const { return mState.currentLightCenter(); } 337 float getLightRadius() const { return mLightRadius; } 338 uint8_t getAmbientShadowAlpha() const { return mAmbientShadowAlpha; } 339 uint8_t getSpotShadowAlpha() const { return mSpotShadowAlpha; } 340 341 /////////////////////////////////////////////////////////////////// 342 /// State manipulation 343 344 int getSaveCount() const; 345 int save(int flags); 346 void restore(); 347 void restoreToCount(int saveCount); 348 349 void setGlobalMatrix(const Matrix4& matrix) { 350 mState.setMatrix(matrix); 351 } 352 void setLocalMatrix(const Matrix4& matrix); 353 void setLocalMatrix(const SkMatrix& matrix); 354 void concatMatrix(const SkMatrix& matrix) { mState.concatMatrix(matrix); } 355 356 void translate(float dx, float dy, float dz = 0.0f); 357 void rotate(float degrees); 358 void scale(float sx, float sy); 359 void skew(float sx, float sy); 360 361 void setMatrix(const Matrix4& matrix); // internal only convenience method 362 void concatMatrix(const Matrix4& matrix); // internal only convenience method 363 364 const Rect& getLocalClipBounds() const { return mState.getLocalClipBounds(); } 365 const Rect& getRenderTargetClipBounds() const { return mState.getRenderTargetClipBounds(); } 366 bool quickRejectConservative(float left, float top, 367 float right, float bottom) const { 368 return mState.quickRejectConservative(left, top, right, bottom); 369 } 370 371 bool clipRect(float left, float top, 372 float right, float bottom, SkRegion::Op op); 373 bool clipPath(const SkPath* path, SkRegion::Op op); 374 bool clipRegion(const SkRegion* region, SkRegion::Op op); 375 376 /** 377 * Does not support different clipping Ops (that is, every call to setClippingOutline is 378 * effectively using SkRegion::kReplaceOp) 379 * 380 * The clipping outline is independent from the regular clip. 381 */ 382 void setClippingOutline(LinearAllocator& allocator, const Outline* outline); 383 void setClippingRoundRect(LinearAllocator& allocator, 384 const Rect& rect, float radius, bool highPriority = true); 385 void setProjectionPathMask(LinearAllocator& allocator, const SkPath* path); 386 387 inline bool hasRectToRectTransform() const { return mState.hasRectToRectTransform(); } 388 inline const mat4* currentTransform() const { return mState.currentTransform(); } 389 390 /////////////////////////////////////////////////////////////////// 391 /// CanvasStateClient interface 392 393 virtual void onViewportInitialized() override; 394 virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override; 395 virtual GLuint getTargetFbo() const override { return 0; } 396 397 SkPath* allocPathForFrame() { 398 std::unique_ptr<SkPath> path(new SkPath()); 399 SkPath* returnPath = path.get(); 400 mTempPaths.push_back(std::move(path)); 401 return returnPath; 402 } 403 404 void setBaseTransform(const Matrix4& matrix) { mBaseTransform = matrix; } 405 406protected: 407 /** 408 * Perform the setup specific to a frame. This method does not 409 * issue any OpenGL commands. 410 */ 411 void setupFrameState(int viewportWidth, int viewportHeight, 412 float left, float top, float right, float bottom, bool opaque); 413 414 /** 415 * Indicates the start of rendering. This method will setup the 416 * initial OpenGL state (viewport, clearing the buffer, etc.) 417 */ 418 void startFrame(); 419 420 /** 421 * Clears the underlying surface if needed. 422 */ 423 virtual void clear(float left, float top, float right, float bottom, bool opaque); 424 425 /** 426 * Call this method after updating a layer during a drawing pass. 427 */ 428 void resumeAfterLayer(); 429 430 /** 431 * This method is called whenever a stencil buffer is required. Subclasses 432 * should override this method and call attachStencilBufferToLayer() on the 433 * appropriate layer(s). 434 */ 435 virtual void ensureStencilBuffer(); 436 437 /** 438 * Obtains a stencil render buffer (allocating it if necessary) and 439 * attaches it to the specified layer. 440 */ 441 void attachStencilBufferToLayer(Layer* layer); 442 443 /** 444 * Draw a rectangle list. Currently only used for the the stencil buffer so that the stencil 445 * will have a value of 'n' in every unclipped pixel, where 'n' is the number of rectangles 446 * in the list. 447 */ 448 void drawRectangleList(const RectangleList& rectangleList); 449 450 bool quickRejectSetupScissor(float left, float top, float right, float bottom, 451 const SkPaint* paint = nullptr); 452 bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = nullptr) { 453 return quickRejectSetupScissor(bounds.left, bounds.top, 454 bounds.right, bounds.bottom, paint); 455 } 456 457 /** 458 * Compose the layer defined in the current snapshot with the layer 459 * defined by the previous snapshot. 460 * 461 * The current snapshot *must* be a layer (flag kFlagIsLayer set.) 462 * 463 * @param curent The current snapshot containing the layer to compose 464 * @param previous The previous snapshot to compose the current layer with 465 */ 466 virtual void composeLayer(const Snapshot& current, const Snapshot& previous); 467 468 /** 469 * Marks the specified region as dirty at the specified bounds. 470 */ 471 void dirtyLayerUnchecked(Rect& bounds, Region* region); 472 473 /** 474 * Returns the region of the current layer. 475 */ 476 virtual Region* getRegion() const { 477 return mState.currentRegion(); 478 } 479 480 /** 481 * Indicates whether rendering is currently targeted at a layer. 482 */ 483 virtual bool hasLayer() const { 484 return (mState.currentFlags() & Snapshot::kFlagFboTarget) && mState.currentRegion(); 485 } 486 487 /** 488 * Renders the specified layer as a textured quad. 489 * 490 * @param layer The layer to render 491 * @param rect The bounds of the layer 492 */ 493 void drawTextureLayer(Layer* layer, const Rect& rect); 494 495 /** 496 * Gets the alpha and xfermode out of a paint object. If the paint is null 497 * alpha will be 255 and the xfermode will be SRC_OVER. Accounts for snapshot alpha. 498 * 499 * @param paint The paint to extract values from 500 * @param alpha Where to store the resulting alpha 501 * @param mode Where to store the resulting xfermode 502 */ 503 inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) const; 504 505 /** 506 * Gets the alpha from a layer, accounting for snapshot alpha 507 * 508 * @param layer The layer from which the alpha is extracted 509 */ 510 inline float getLayerAlpha(const Layer* layer) const; 511 512 /** 513 * Set to true to suppress error checks at the end of a frame. 514 */ 515 virtual bool suppressErrorChecks() const { 516 return false; 517 } 518 519 CanvasState mState; 520 Caches& mCaches; 521 RenderState& mRenderState; 522 523private: 524 enum class GlopRenderType { 525 Standard, 526 Multi, 527 LayerClear 528 }; 529 530 void renderGlop(const Glop& glop, GlopRenderType type = GlopRenderType::Standard); 531 532 /** 533 * Discards the content of the framebuffer if supported by the driver. 534 * This method should be called at the beginning of a frame to optimize 535 * rendering on some tiler architectures. 536 */ 537 void discardFramebuffer(float left, float top, float right, float bottom); 538 539 /** 540 * Sets the clipping rectangle using glScissor. The clip is defined by 541 * the current snapshot's clipRect member. 542 */ 543 void setScissorFromClip(); 544 545 /** 546 * Sets the clipping region using the stencil buffer. The clip region 547 * is defined by the current snapshot's clipRegion member. 548 */ 549 void setStencilFromClip(); 550 551 /** 552 * Given the local bounds of the layer, calculates ... 553 */ 554 void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer); 555 556 /** 557 * Given the local bounds + clip of the layer, updates current snapshot's empty/invisible 558 */ 559 void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip, 560 bool fboLayer, int alpha); 561 562 /** 563 * Creates a new layer stored in the specified snapshot. 564 * 565 * @param snapshot The snapshot associated with the new layer 566 * @param left The left coordinate of the layer 567 * @param top The top coordinate of the layer 568 * @param right The right coordinate of the layer 569 * @param bottom The bottom coordinate of the layer 570 * @param alpha The translucency of the layer 571 * @param mode The blending mode of the layer 572 * @param flags The layer save flags 573 * @param mask A mask to use when drawing the layer back, may be empty 574 * 575 * @return True if the layer was successfully created, false otherwise 576 */ 577 bool createLayer(float left, float top, float right, float bottom, 578 const SkPaint* paint, int flags, const SkPath* convexMask); 579 580 /** 581 * Creates a new layer stored in the specified snapshot as an FBO. 582 * 583 * @param layer The layer to store as an FBO 584 * @param snapshot The snapshot associated with the new layer 585 * @param bounds The bounds of the layer 586 */ 587 bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip); 588 589 /** 590 * Compose the specified layer as a region. 591 * 592 * @param layer The layer to compose 593 * @param rect The layer's bounds 594 */ 595 void composeLayerRegion(Layer* layer, const Rect& rect); 596 597 /** 598 * Restores the content in layer to the screen, swapping the blend mode, 599 * specifically used in the restore() of a saveLayerAlpha(). 600 * 601 * This allows e.g. a layer that would have been drawn on top of existing content (with SrcOver) 602 * to be drawn underneath. 603 * 604 * This will always ignore the canvas transform. 605 */ 606 void composeLayerRectSwapped(Layer* layer, const Rect& rect); 607 608 /** 609 * Draws the content in layer to the screen. 610 */ 611 void composeLayerRect(Layer* layer, const Rect& rect); 612 613 /** 614 * Clears all the regions corresponding to the current list of layers. 615 * This method MUST be invoked before any drawing operation. 616 */ 617 void clearLayerRegions(); 618 619 /** 620 * Mark the layer as dirty at the specified coordinates. The coordinates 621 * are transformed with the supplied matrix. 622 */ 623 void dirtyLayer(const float left, const float top, 624 const float right, const float bottom, const Matrix4& transform); 625 626 /** 627 * Mark the layer as dirty at the specified coordinates. 628 */ 629 void dirtyLayer(const float left, const float top, 630 const float right, const float bottom); 631 632 /** 633 * Draws a colored rectangle with the specified color. The specified coordinates 634 * are transformed by the current snapshot's transform matrix unless specified 635 * otherwise. 636 * 637 * @param left The left coordinate of the rectangle 638 * @param top The top coordinate of the rectangle 639 * @param right The right coordinate of the rectangle 640 * @param bottom The bottom coordinate of the rectangle 641 * @param paint The paint containing the color, blending mode, etc. 642 * @param ignoreTransform True if the current transform should be ignored 643 */ 644 void drawColorRect(float left, float top, float right, float bottom, 645 const SkPaint* paint, bool ignoreTransform = false); 646 647 /** 648 * Draws a series of colored rectangles with the specified color. The specified 649 * coordinates are transformed by the current snapshot's transform matrix unless 650 * specified otherwise. 651 * 652 * @param rects A list of rectangles, 4 floats (left, top, right, bottom) 653 * per rectangle 654 * @param paint The paint containing the color, blending mode, etc. 655 * @param ignoreTransform True if the current transform should be ignored 656 * @param dirty True if calling this method should dirty the current layer 657 * @param clip True if the rects should be clipped, false otherwise 658 */ 659 void drawColorRects(const float* rects, int count, const SkPaint* paint, 660 bool ignoreTransform = false, bool dirty = true, bool clip = true); 661 662 /** 663 * Draws the shape represented by the specified path texture. 664 * This method invokes drawPathTexture() but takes into account 665 * the extra left/top offset and the texture offset to correctly 666 * position the final shape. 667 * 668 * @param left The left coordinate of the shape to render 669 * @param top The top coordinate of the shape to render 670 * @param texture The texture reprsenting the shape 671 * @param paint The paint to draw the shape with 672 */ 673 void drawShape(float left, float top, PathTexture* texture, const SkPaint* paint); 674 675 /** 676 * Renders a strip of polygons with the specified paint, used for tessellated geometry. 677 * 678 * @param vertexBuffer The VertexBuffer to be drawn 679 * @param paint The paint to render with 680 * @param flags flags with which to draw 681 */ 682 void drawVertexBuffer(float translateX, float translateY, const VertexBuffer& vertexBuffer, 683 const SkPaint* paint, int flags = 0); 684 685 /** 686 * Convenience for translating method 687 */ 688 void drawVertexBuffer(const VertexBuffer& vertexBuffer, 689 const SkPaint* paint, int flags = 0) { 690 drawVertexBuffer(0.0f, 0.0f, vertexBuffer, paint, flags); 691 } 692 693 /** 694 * Renders the convex hull defined by the specified path as a strip of polygons. 695 * 696 * @param path The hull of the path to draw 697 * @param paint The paint to render with 698 */ 699 void drawConvexPath(const SkPath& path, const SkPaint* paint); 700 701 /** 702 * Draws text underline and strike-through if needed. 703 * 704 * @param text The text to decor 705 * @param bytesCount The number of bytes in the text 706 * @param totalAdvance The total advance in pixels, defines underline/strikethrough length 707 * @param x The x coordinate where the text will be drawn 708 * @param y The y coordinate where the text will be drawn 709 * @param paint The paint to draw the text with 710 */ 711 void drawTextDecorations(float totalAdvance, float x, float y, const SkPaint* paint); 712 713 /** 714 * Draws shadow layer on text (with optional positions). 715 * 716 * @param paint The paint to draw the shadow with 717 * @param text The text to draw 718 * @param bytesCount The number of bytes in the text 719 * @param count The number of glyphs in the text 720 * @param positions The x, y positions of individual glyphs (or NULL) 721 * @param fontRenderer The font renderer object 722 * @param alpha The alpha value for drawing the shadow 723 * @param x The x coordinate where the shadow will be drawn 724 * @param y The y coordinate where the shadow will be drawn 725 */ 726 void drawTextShadow(const SkPaint* paint, const char* text, int bytesCount, int count, 727 const float* positions, FontRenderer& fontRenderer, int alpha, 728 float x, float y); 729 730 /** 731 * Draws a path texture. Path textures are alpha8 bitmaps that need special 732 * compositing to apply colors/filters/etc. 733 * 734 * @param texture The texture to render 735 * @param x The x coordinate where the texture will be drawn 736 * @param y The y coordinate where the texture will be drawn 737 * @param paint The paint to draw the texture with 738 */ 739 void drawPathTexture(PathTexture* texture, float x, float y, const SkPaint* paint); 740 741 /** 742 * Resets the texture coordinates stored in mMeshVertices. Setting the values 743 * back to default is achieved by calling: 744 * 745 * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); 746 * 747 * @param u1 The left coordinate of the texture 748 * @param v1 The bottom coordinate of the texture 749 * @param u2 The right coordinate of the texture 750 * @param v2 The top coordinate of the texture 751 */ 752 void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2); 753 754 /** 755 * Returns true if the specified paint will draw invisible text. 756 */ 757 bool canSkipText(const SkPaint* paint) const; 758 759 bool updateLayer(Layer* layer, bool inFrame); 760 void updateLayers(); 761 void flushLayers(); 762 763#if DEBUG_LAYERS_AS_REGIONS 764 /** 765 * Renders the specified region as a series of rectangles. This method 766 * is used for debugging only. 767 */ 768 void drawRegionRectsDebug(const Region& region); 769#endif 770 771 /** 772 * Renders the specified region as a series of rectangles. The region 773 * must be in screen-space coordinates. 774 */ 775 void drawRegionRects(const SkRegion& region, const SkPaint& paint, bool dirty = false); 776 777 /** 778 * Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS 779 * is turned on. 780 */ 781 void debugClip(); 782 783 void debugOverdraw(bool enable, bool clear); 784 void renderOverdraw(); 785 void countOverdraw(); 786 787 /** 788 * Should be invoked every time the glScissor is modified. 789 */ 790 inline void dirtyClip() { mState.setDirtyClip(true); } 791 792 inline const UvMapper& getMapper(const Texture* texture) { 793 return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper; 794 } 795 796 /** 797 * Returns a texture object for the specified bitmap. The texture can 798 * come from the texture cache or an atlas. If this method returns 799 * NULL, the texture could not be found and/or allocated. 800 */ 801 Texture* getTexture(const SkBitmap* bitmap); 802 803 bool reportAndClearDirty() { bool ret = mDirty; mDirty = false; return ret; } 804 inline Snapshot* writableSnapshot() { return mState.writableSnapshot(); } 805 inline const Snapshot* currentSnapshot() const { return mState.currentSnapshot(); } 806 807 // State used to define the clipping region 808 Rect mTilingClip; 809 // Is the target render surface opaque 810 bool mOpaque; 811 // Is a frame currently being rendered 812 bool mFrameStarted; 813 814 // Default UV mapper 815 const UvMapper mUvMapper; 816 817 // List of rectangles to clear after saveLayer() is invoked 818 std::vector<Rect> mLayers; 819 // List of layers to update at the beginning of a frame 820 std::vector< sp<Layer> > mLayerUpdates; 821 822 // See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in 823 // Properties.h 824 bool mScissorOptimizationDisabled; 825 826 bool mSkipOutlineClip; 827 828 // True if anything has been drawn since the last call to 829 // reportAndClearDirty() 830 bool mDirty; 831 832 // Lighting + shadows 833 Vector3 mLightCenter; 834 float mLightRadius; 835 uint8_t mAmbientShadowAlpha; 836 uint8_t mSpotShadowAlpha; 837 838 // Paths kept alive for the duration of the frame 839 std::vector<std::unique_ptr<SkPath>> mTempPaths; 840 841 /** 842 * Initial transform for a rendering pass; transform from global device 843 * coordinates to the current RenderNode's drawing content coordinates, 844 * with the RenderNode's RenderProperty transforms already applied. 845 * Calling setMatrix(mBaseTransform) will result in drawing at the origin 846 * of the DisplayList's recorded surface prior to any Canvas 847 * transformation. 848 */ 849 Matrix4 mBaseTransform; 850 851 friend class Layer; 852 friend class TextDrawFunctor; 853 friend class DrawBitmapOp; 854 friend class DrawPatchOp; 855 856}; // class OpenGLRenderer 857 858}; // namespace uirenderer 859}; // namespace android 860 861#endif // ANDROID_HWUI_OPENGL_RENDERER_H 862