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 55 class SkShader; 56 57 namespace android { 58 namespace uirenderer { 59 60 enum class DrawOpMode { 61 kImmediate, 62 kDefer, 63 kFlush 64 }; 65 66 class DeferredDisplayState; 67 struct Glop; 68 class RenderState; 69 class RenderNode; 70 class TextDrawFunctor; 71 class VertexBuffer; 72 73 enum StateDeferFlags { 74 kStateDeferFlag_Draw = 0x1, 75 kStateDeferFlag_Clip = 0x2 76 }; 77 78 enum 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 88 enum 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 */ 97 enum 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 */ 117 class OpenGLRenderer : public CanvasStateClient { 118 public: 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 glyph_t* glyphs, int bytesCount, int count, const SkPath* path, 195 float hOffset, float vOffset, const SkPaint* paint); 196 void drawText(const glyph_t* glyphs, int bytesCount, int count, float x, float y, 197 const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds, 198 DrawOpMode drawOpMode = DrawOpMode::kImmediate); 199 void drawRects(const float* rects, int count, const SkPaint* paint); 200 201 void drawShadow(float casterAlpha, 202 const VertexBuffer* ambientShadowVertexBuffer, 203 const VertexBuffer* spotShadowVertexBuffer); 204 205 void setDrawFilter(SkDrawFilter* filter); 206 207 /** 208 * Store the current display state (most importantly, the current clip and transform), and 209 * additionally map the state's bounds from local to window coordinates. 210 * 211 * Returns true if quick-rejected 212 */ 213 bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags); 214 void restoreDisplayState(const DeferredDisplayState& state, bool skipClipRestore = false); 215 void setupMergedMultiDraw(const Rect* clipRect); 216 217 bool isCurrentTransformSimple() { 218 return currentTransform()->isSimple(); 219 } 220 221 Caches& getCaches() { 222 return mCaches; 223 } 224 225 RenderState& renderState() { 226 return mRenderState; 227 } 228 229 int getViewportWidth() { return mState.getViewportWidth(); } 230 int getViewportHeight() { return mState.getViewportHeight(); } 231 232 /** 233 * Scales the alpha on the current snapshot. This alpha value will be modulated 234 * with other alpha values when drawing primitives. 235 */ 236 void scaleAlpha(float alpha) { mState.scaleAlpha(alpha); } 237 238 /** 239 * Inserts a named event marker in the stream of GL commands. 240 */ 241 void eventMark(const char* name) const; 242 243 /** 244 * Inserts a formatted event marker in the stream of GL commands. 245 */ 246 void eventMarkDEBUG(const char *fmt, ...) const; 247 248 /** 249 * Inserts a named group marker in the stream of GL commands. This marker 250 * can be used by tools to group commands into logical groups. A call to 251 * this method must always be followed later on by a call to endMark(). 252 */ 253 void startMark(const char* name) const; 254 255 /** 256 * Closes the last group marker opened by startMark(). 257 */ 258 void endMark() const; 259 260 /** 261 * Build the best transform to use to rasterize text given a full 262 * transform matrix, and whether filteration is needed. 263 * 264 * Returns whether filtration is needed 265 */ 266 bool findBestFontTransform(const mat4& transform, SkMatrix* outMatrix) const; 267 268 #if DEBUG_MERGE_BEHAVIOR 269 void drawScreenSpaceColorRect(float left, float top, float right, float bottom, int color) { 270 mCaches.setScissorEnabled(false); 271 272 // should only be called outside of other draw ops, so stencil can only be in test state 273 bool stencilWasEnabled = mCaches.stencil.isTestEnabled(); 274 mCaches.stencil.disable(); 275 276 drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true); 277 278 if (stencilWasEnabled) mCaches.stencil.enableTest(); 279 mDirty = true; 280 } 281 #endif 282 283 const Vector3& getLightCenter() const { return mState.currentLightCenter(); } 284 float getLightRadius() const { return mLightRadius; } 285 uint8_t getAmbientShadowAlpha() const { return mAmbientShadowAlpha; } 286 uint8_t getSpotShadowAlpha() const { return mSpotShadowAlpha; } 287 288 /////////////////////////////////////////////////////////////////// 289 /// State manipulation 290 291 int getSaveCount() const; 292 int save(int flags); 293 void restore(); 294 void restoreToCount(int saveCount); 295 296 void setGlobalMatrix(const Matrix4& matrix) { 297 mState.setMatrix(matrix); 298 } 299 void setLocalMatrix(const Matrix4& matrix); 300 void setLocalMatrix(const SkMatrix& matrix); 301 void concatMatrix(const SkMatrix& matrix) { mState.concatMatrix(matrix); } 302 303 void translate(float dx, float dy, float dz = 0.0f); 304 void rotate(float degrees); 305 void scale(float sx, float sy); 306 void skew(float sx, float sy); 307 308 void setMatrix(const Matrix4& matrix); // internal only convenience method 309 void concatMatrix(const Matrix4& matrix); // internal only convenience method 310 311 const Rect& getLocalClipBounds() const { return mState.getLocalClipBounds(); } 312 const Rect& getRenderTargetClipBounds() const { return mState.getRenderTargetClipBounds(); } 313 bool quickRejectConservative(float left, float top, 314 float right, float bottom) const { 315 return mState.quickRejectConservative(left, top, right, bottom); 316 } 317 318 bool clipRect(float left, float top, 319 float right, float bottom, SkRegion::Op op); 320 bool clipPath(const SkPath* path, SkRegion::Op op); 321 bool clipRegion(const SkRegion* region, SkRegion::Op op); 322 323 /** 324 * Does not support different clipping Ops (that is, every call to setClippingOutline is 325 * effectively using SkRegion::kReplaceOp) 326 * 327 * The clipping outline is independent from the regular clip. 328 */ 329 void setClippingOutline(LinearAllocator& allocator, const Outline* outline); 330 void setClippingRoundRect(LinearAllocator& allocator, 331 const Rect& rect, float radius, bool highPriority = true); 332 void setProjectionPathMask(LinearAllocator& allocator, const SkPath* path); 333 334 inline bool hasRectToRectTransform() const { return mState.hasRectToRectTransform(); } 335 inline const mat4* currentTransform() const { return mState.currentTransform(); } 336 337 /////////////////////////////////////////////////////////////////// 338 /// CanvasStateClient interface 339 340 virtual void onViewportInitialized() override; 341 virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override; 342 virtual GLuint getTargetFbo() const override { return 0; } 343 344 SkPath* allocPathForFrame() { 345 std::unique_ptr<SkPath> path(new SkPath()); 346 SkPath* returnPath = path.get(); 347 mTempPaths.push_back(std::move(path)); 348 return returnPath; 349 } 350 351 void setBaseTransform(const Matrix4& matrix) { mBaseTransform = matrix; } 352 353 protected: 354 /** 355 * Perform the setup specific to a frame. This method does not 356 * issue any OpenGL commands. 357 */ 358 void setupFrameState(int viewportWidth, int viewportHeight, 359 float left, float top, float right, float bottom, bool opaque); 360 361 /** 362 * Indicates the start of rendering. This method will setup the 363 * initial OpenGL state (viewport, clearing the buffer, etc.) 364 */ 365 void startFrame(); 366 367 /** 368 * Clears the underlying surface if needed. 369 */ 370 virtual void clear(float left, float top, float right, float bottom, bool opaque); 371 372 /** 373 * Call this method after updating a layer during a drawing pass. 374 */ 375 void resumeAfterLayer(); 376 377 /** 378 * This method is called whenever a stencil buffer is required. Subclasses 379 * should override this method and call attachStencilBufferToLayer() on the 380 * appropriate layer(s). 381 */ 382 virtual void ensureStencilBuffer(); 383 384 /** 385 * Obtains a stencil render buffer (allocating it if necessary) and 386 * attaches it to the specified layer. 387 */ 388 void attachStencilBufferToLayer(Layer* layer); 389 390 /** 391 * Draw a rectangle list. Currently only used for the the stencil buffer so that the stencil 392 * will have a value of 'n' in every unclipped pixel, where 'n' is the number of rectangles 393 * in the list. 394 */ 395 void drawRectangleList(const RectangleList& rectangleList); 396 397 bool quickRejectSetupScissor(float left, float top, float right, float bottom, 398 const SkPaint* paint = nullptr); 399 bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = nullptr) { 400 return quickRejectSetupScissor(bounds.left, bounds.top, 401 bounds.right, bounds.bottom, paint); 402 } 403 404 /** 405 * Compose the layer defined in the current snapshot with the layer 406 * defined by the previous snapshot. 407 * 408 * The current snapshot *must* be a layer (flag kFlagIsLayer set.) 409 * 410 * @param curent The current snapshot containing the layer to compose 411 * @param previous The previous snapshot to compose the current layer with 412 */ 413 virtual void composeLayer(const Snapshot& current, const Snapshot& previous); 414 415 /** 416 * Marks the specified region as dirty at the specified bounds. 417 */ 418 void dirtyLayerUnchecked(Rect& bounds, Region* region); 419 420 /** 421 * Returns the region of the current layer. 422 */ 423 virtual Region* getRegion() const { 424 return mState.currentRegion(); 425 } 426 427 /** 428 * Indicates whether rendering is currently targeted at a layer. 429 */ 430 virtual bool hasLayer() const { 431 return (mState.currentFlags() & Snapshot::kFlagFboTarget) && mState.currentRegion(); 432 } 433 434 /** 435 * Renders the specified layer as a textured quad. 436 * 437 * @param layer The layer to render 438 * @param rect The bounds of the layer 439 */ 440 void drawTextureLayer(Layer* layer, const Rect& rect); 441 442 /** 443 * Gets the alpha from a layer, accounting for snapshot alpha 444 * 445 * @param layer The layer from which the alpha is extracted 446 */ 447 inline float getLayerAlpha(const Layer* layer) const; 448 449 /** 450 * Set to true to suppress error checks at the end of a frame. 451 */ 452 virtual bool suppressErrorChecks() const { 453 return false; 454 } 455 456 CanvasState mState; 457 Caches& mCaches; 458 RenderState& mRenderState; 459 460 private: 461 enum class GlopRenderType { 462 Standard, 463 Multi, 464 LayerClear 465 }; 466 467 void renderGlop(const Glop& glop, GlopRenderType type = GlopRenderType::Standard); 468 469 /** 470 * Discards the content of the framebuffer if supported by the driver. 471 * This method should be called at the beginning of a frame to optimize 472 * rendering on some tiler architectures. 473 */ 474 void discardFramebuffer(float left, float top, float right, float bottom); 475 476 /** 477 * Sets the clipping rectangle using glScissor. The clip is defined by 478 * the current snapshot's clipRect member. 479 */ 480 void setScissorFromClip(); 481 482 /** 483 * Sets the clipping region using the stencil buffer. The clip region 484 * is defined by the current snapshot's clipRegion member. 485 */ 486 void setStencilFromClip(); 487 488 /** 489 * Given the local bounds of the layer, calculates ... 490 */ 491 void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer); 492 493 /** 494 * Given the local bounds + clip of the layer, updates current snapshot's empty/invisible 495 */ 496 void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip, 497 bool fboLayer, int alpha); 498 499 /** 500 * Creates a new layer stored in the specified snapshot. 501 * 502 * @param snapshot The snapshot associated with the new layer 503 * @param left The left coordinate of the layer 504 * @param top The top coordinate of the layer 505 * @param right The right coordinate of the layer 506 * @param bottom The bottom coordinate of the layer 507 * @param alpha The translucency of the layer 508 * @param mode The blending mode of the layer 509 * @param flags The layer save flags 510 * @param mask A mask to use when drawing the layer back, may be empty 511 * 512 * @return True if the layer was successfully created, false otherwise 513 */ 514 bool createLayer(float left, float top, float right, float bottom, 515 const SkPaint* paint, int flags, const SkPath* convexMask); 516 517 /** 518 * Creates a new layer stored in the specified snapshot as an FBO. 519 * 520 * @param layer The layer to store as an FBO 521 * @param snapshot The snapshot associated with the new layer 522 * @param bounds The bounds of the layer 523 */ 524 bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip); 525 526 /** 527 * Compose the specified layer as a region. 528 * 529 * @param layer The layer to compose 530 * @param rect The layer's bounds 531 */ 532 void composeLayerRegion(Layer* layer, const Rect& rect); 533 534 /** 535 * Restores the content in layer to the screen, swapping the blend mode, 536 * specifically used in the restore() of a saveLayerAlpha(). 537 * 538 * This allows e.g. a layer that would have been drawn on top of existing content (with SrcOver) 539 * to be drawn underneath. 540 * 541 * This will always ignore the canvas transform. 542 */ 543 void composeLayerRectSwapped(Layer* layer, const Rect& rect); 544 545 /** 546 * Draws the content in layer to the screen. 547 */ 548 void composeLayerRect(Layer* layer, const Rect& rect); 549 550 /** 551 * Clears all the regions corresponding to the current list of layers. 552 * This method MUST be invoked before any drawing operation. 553 */ 554 void clearLayerRegions(); 555 556 /** 557 * Mark the layer as dirty at the specified coordinates. The coordinates 558 * are transformed with the supplied matrix. 559 */ 560 void dirtyLayer(const float left, const float top, 561 const float right, const float bottom, const Matrix4& transform); 562 563 /** 564 * Mark the layer as dirty at the specified coordinates. 565 */ 566 void dirtyLayer(const float left, const float top, 567 const float right, const float bottom); 568 569 /** 570 * Draws a colored rectangle with the specified color. The specified coordinates 571 * are transformed by the current snapshot's transform matrix unless specified 572 * otherwise. 573 * 574 * @param left The left coordinate of the rectangle 575 * @param top The top coordinate of the rectangle 576 * @param right The right coordinate of the rectangle 577 * @param bottom The bottom coordinate of the rectangle 578 * @param paint The paint containing the color, blending mode, etc. 579 * @param ignoreTransform True if the current transform should be ignored 580 */ 581 void drawColorRect(float left, float top, float right, float bottom, 582 const SkPaint* paint, bool ignoreTransform = false); 583 584 /** 585 * Draws a series of colored rectangles with the specified color. The specified 586 * coordinates are transformed by the current snapshot's transform matrix unless 587 * specified otherwise. 588 * 589 * @param rects A list of rectangles, 4 floats (left, top, right, bottom) 590 * per rectangle 591 * @param paint The paint containing the color, blending mode, etc. 592 * @param ignoreTransform True if the current transform should be ignored 593 * @param dirty True if calling this method should dirty the current layer 594 * @param clip True if the rects should be clipped, false otherwise 595 */ 596 void drawColorRects(const float* rects, int count, const SkPaint* paint, 597 bool ignoreTransform = false, bool dirty = true, bool clip = true); 598 599 /** 600 * Draws the shape represented by the specified path texture. 601 * This method invokes drawPathTexture() but takes into account 602 * the extra left/top offset and the texture offset to correctly 603 * position the final shape. 604 * 605 * @param left The left coordinate of the shape to render 606 * @param top The top coordinate of the shape to render 607 * @param texture The texture reprsenting the shape 608 * @param paint The paint to draw the shape with 609 */ 610 void drawShape(float left, float top, PathTexture* texture, const SkPaint* paint); 611 612 /** 613 * Renders a strip of polygons with the specified paint, used for tessellated geometry. 614 * 615 * @param vertexBuffer The VertexBuffer to be drawn 616 * @param paint The paint to render with 617 * @param flags flags with which to draw 618 */ 619 void drawVertexBuffer(float translateX, float translateY, const VertexBuffer& vertexBuffer, 620 const SkPaint* paint, int flags = 0); 621 622 /** 623 * Convenience for translating method 624 */ 625 void drawVertexBuffer(const VertexBuffer& vertexBuffer, 626 const SkPaint* paint, int flags = 0) { 627 drawVertexBuffer(0.0f, 0.0f, vertexBuffer, paint, flags); 628 } 629 630 /** 631 * Renders the convex hull defined by the specified path as a strip of polygons. 632 * 633 * @param path The hull of the path to draw 634 * @param paint The paint to render with 635 */ 636 void drawConvexPath(const SkPath& path, const SkPaint* paint); 637 638 /** 639 * Draws shadow layer on text (with optional positions). 640 * 641 * @param paint The paint to draw the shadow with 642 * @param text The text to draw 643 * @param count The number of glyphs in the text 644 * @param positions The x, y positions of individual glyphs (or NULL) 645 * @param fontRenderer The font renderer object 646 * @param alpha The alpha value for drawing the shadow 647 * @param x The x coordinate where the shadow will be drawn 648 * @param y The y coordinate where the shadow will be drawn 649 */ 650 void drawTextShadow(const SkPaint* paint, const glyph_t* glyphs, int count, 651 const float* positions, FontRenderer& fontRenderer, int alpha, 652 float x, float y); 653 654 /** 655 * Draws a path texture. Path textures are alpha8 bitmaps that need special 656 * compositing to apply colors/filters/etc. 657 * 658 * @param texture The texture to render 659 * @param x The x coordinate where the texture will be drawn 660 * @param y The y coordinate where the texture will be drawn 661 * @param paint The paint to draw the texture with 662 */ 663 void drawPathTexture(PathTexture* texture, float x, float y, const SkPaint* paint); 664 665 /** 666 * Resets the texture coordinates stored in mMeshVertices. Setting the values 667 * back to default is achieved by calling: 668 * 669 * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); 670 * 671 * @param u1 The left coordinate of the texture 672 * @param v1 The bottom coordinate of the texture 673 * @param u2 The right coordinate of the texture 674 * @param v2 The top coordinate of the texture 675 */ 676 void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2); 677 678 /** 679 * Returns true if the specified paint will draw invisible text. 680 */ 681 bool canSkipText(const SkPaint* paint) const; 682 683 bool updateLayer(Layer* layer, bool inFrame); 684 void updateLayers(); 685 void flushLayers(); 686 687 #if DEBUG_LAYERS_AS_REGIONS 688 /** 689 * Renders the specified region as a series of rectangles. This method 690 * is used for debugging only. 691 */ 692 void drawRegionRectsDebug(const Region& region); 693 #endif 694 695 /** 696 * Renders the specified region as a series of rectangles. The region 697 * must be in screen-space coordinates. 698 */ 699 void drawRegionRects(const SkRegion& region, const SkPaint& paint, bool dirty = false); 700 701 /** 702 * Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS 703 * is turned on. 704 */ 705 void debugClip(); 706 707 void debugOverdraw(bool enable, bool clear); 708 void renderOverdraw(); 709 void countOverdraw(); 710 711 /** 712 * Should be invoked every time the glScissor is modified. 713 */ 714 inline void dirtyClip() { mState.setDirtyClip(true); } 715 716 inline const UvMapper& getMapper(const Texture* texture) { 717 return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper; 718 } 719 720 /** 721 * Returns a texture object for the specified bitmap. The texture can 722 * come from the texture cache or an atlas. If this method returns 723 * NULL, the texture could not be found and/or allocated. 724 */ 725 Texture* getTexture(const SkBitmap* bitmap); 726 727 bool reportAndClearDirty() { bool ret = mDirty; mDirty = false; return ret; } 728 inline Snapshot* writableSnapshot() { return mState.writableSnapshot(); } 729 inline const Snapshot* currentSnapshot() const { return mState.currentSnapshot(); } 730 731 // State used to define the clipping region 732 Rect mTilingClip; 733 // Is the target render surface opaque 734 bool mOpaque; 735 // Is a frame currently being rendered 736 bool mFrameStarted; 737 738 // Default UV mapper 739 const UvMapper mUvMapper; 740 741 // List of rectangles to clear after saveLayer() is invoked 742 std::vector<Rect> mLayers; 743 // List of layers to update at the beginning of a frame 744 std::vector< sp<Layer> > mLayerUpdates; 745 746 // See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in 747 // Properties.h 748 bool mScissorOptimizationDisabled; 749 750 bool mSkipOutlineClip; 751 752 // True if anything has been drawn since the last call to 753 // reportAndClearDirty() 754 bool mDirty; 755 756 // Lighting + shadows 757 Vector3 mLightCenter; 758 float mLightRadius; 759 uint8_t mAmbientShadowAlpha; 760 uint8_t mSpotShadowAlpha; 761 762 // Paths kept alive for the duration of the frame 763 std::vector<std::unique_ptr<SkPath>> mTempPaths; 764 765 /** 766 * Initial transform for a rendering pass; transform from global device 767 * coordinates to the current RenderNode's drawing content coordinates, 768 * with the RenderNode's RenderProperty transforms already applied. 769 * Calling setMatrix(mBaseTransform) will result in drawing at the origin 770 * of the DisplayList's recorded surface prior to any Canvas 771 * transformation. 772 */ 773 Matrix4 mBaseTransform; 774 775 friend class Layer; 776 friend class TextDrawFunctor; 777 friend class DrawBitmapOp; 778 friend class DrawPatchOp; 779 780 }; // class OpenGLRenderer 781 782 }; // namespace uirenderer 783 }; // namespace android 784 785 #endif // ANDROID_HWUI_OPENGL_RENDERER_H 786