のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

TextView.Invalidate

/frameworks/base/core/java/android/view/View.java
   8530   /**
   8531      * This is where the invalidate() work actually happens. A full invalidate()
   8532      * causes the drawing cache to be invalidated, but this function can be called with
   8533      * invalidateCache set to false to skip that invalidation step for cases that do not
   8534      * need it (for example, a component that remains at the same dimensions with the same
   8535      * content).
   8536      *
   8537      * @param invalidateCache Whether the drawing cache for this view should be invalidated as
   8538      * well. This is usually true for a full invalidate, but may be set to false if the
   8539      * View's contents or dimensions have not changed.
   8540      */
   8541     void invalidate(boolean invalidateCache) {
   8542         if (ViewDebug.TRACE_HIERARCHY) {
   8543             ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE);
   8544         }
   8545 
   8546         if (skipInvalidate()) {
   8547             return;
   8548         }
   8549         if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) ||
   8550                 (invalidateCache && (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) ||
   8551                 (mPrivateFlags & INVALIDATED) != INVALIDATED || isOpaque() != mLastIsOpaque) {
   8552             mLastIsOpaque = isOpaque();
   8553             mPrivateFlags &= ~DRAWN;
   8554             mPrivateFlags |= DIRTY;
   8555             if (invalidateCache) {
   8556                 mPrivateFlags |= INVALIDATED;
   8557                 mPrivateFlags &= ~DRAWING_CACHE_VALID;
   8558             }
   8559             final AttachInfo ai = mAttachInfo;
   8560             final ViewParent p = mParent;
   8561             //noinspection PointlessBooleanExpression,ConstantConditions
   8562             if (!HardwareRenderer.RENDER_DIRTY_REGIONS) {
   8563                 if (p != null && ai != null && ai.mHardwareAccelerated) {
   8564                     // fast-track for GL-enabled applications; just invalidate the whole hierarchy
   8565                     // with a null dirty rect, which tells the ViewAncestor to redraw everything
   8566                     p.invalidateChild(this, null);
   8567                     return;
   8568                 }
   8569             }
   8570 
   8571             if (p != null && ai != null) {
   8572                 final Rect r = ai.mTmpInvalRect;
   8573                 r.set(0, 0, mRight - mLeft, mBottom - mTop);
   8574                 // Don't call invalidate -- we don't want to internally scroll
   8575                 // our own bounds
   8576                 p.invalidateChild(this, r);
   8577             }
   8578         }
   8579     }

http://tools.oesf.biz/android-4.0.3_r1.0/xref/frameworks/base/core/java/android/view/View.java
/frameworks/base/core/java/android/view/ViewGroup.java
3880     /**
   3881      * Don't call or override this method. It is used for the implementation of
   3882      * the view hierarchy.
   3883      */
   3884     public final void invalidateChild(View child, final Rect dirty) {
   3885         if (ViewDebug.TRACE_HIERARCHY) {
   3886             ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE_CHILD);
   3887         }
   3888 
   3889         ViewParent parent = this;
   3890 
   3891         final AttachInfo attachInfo = mAttachInfo;
   3892         if (attachInfo != null) {
   3893             // If the child is drawing an animation, we want to copy this flag onto
   3894             // ourselves and the parent to make sure the invalidate request goes
   3895             // through
   3896             final boolean drawAnimation = (child.mPrivateFlags & DRAW_ANIMATION) == DRAW_ANIMATION;
   3897 
   3898             if (dirty == null) {
   3899                 if (child.mLayerType != LAYER_TYPE_NONE) {
   3900                     mPrivateFlags |= INVALIDATED;
   3901                     mPrivateFlags &= ~DRAWING_CACHE_VALID;
   3902                     child.mLocalDirtyRect.setEmpty();
   3903                 }
   3904                 do {
   3905                     View view = null;
   3906                     if (parent instanceof View) {
   3907                         view = (View) parent;
   3908                         if (view.mLayerType != LAYER_TYPE_NONE) {
   3909                             view.mLocalDirtyRect.setEmpty();
   3910                             if (view.getParent() instanceof View) {
   3911                                 final View grandParent = (View) view.getParent();
   3912                                 grandParent.mPrivateFlags |= INVALIDATED;
   3913                                 grandParent.mPrivateFlags &= ~DRAWING_CACHE_VALID;
   3914                             }
   3915                         }
   3916                         if ((view.mPrivateFlags & DIRTY_MASK) != 0) {
   3917                             // already marked dirty - we're done
   3918                             break;
   3919                         }
   3920                     }
   3921 
   3922                     if (drawAnimation) {
   3923                         if (view != null) {
   3924                             view.mPrivateFlags |= DRAW_ANIMATION;
   3925                         } else if (parent instanceof ViewRootImpl) {
   3926                             ((ViewRootImpl) parent).mIsAnimating = true;
   3927                         }
   3928                     }
   3929 
   3930                     if (parent instanceof ViewRootImpl) {
   3931                         ((ViewRootImpl) parent).invalidate();
   3932                         parent = null;
   3933                     } else if (view != null) {
   3934                         if ((view.mPrivateFlags & DRAWN) == DRAWN ||
   3935                                 (view.mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) {
   3936                             view.mPrivateFlags &= ~DRAWING_CACHE_VALID;
   3937                             view.mPrivateFlags |= DIRTY;
   3938                             parent = view.mParent;
   3939                         } else {
   3940                             parent = null;
   3941                         }
   3942                     }
   3943                 } while (parent != null);
   3944             } else {
   3945                 // Check whether the child that requests the invalidate is fully opaque
   3946                 final boolean isOpaque = child.isOpaque() && !drawAnimation &&
   3947                         child.getAnimation() == null;
   3948                 // Mark the child as dirty, using the appropriate flag
   3949                 // Make sure we do not set both flags at the same time
   3950                 int opaqueFlag = isOpaque ? DIRTY_OPAQUE : DIRTY;
   3951 
   3952                 if (child.mLayerType != LAYER_TYPE_NONE) {
   3953                     mPrivateFlags |= INVALIDATED;
   3954                     mPrivateFlags &= ~DRAWING_CACHE_VALID;
   3955                     child.mLocalDirtyRect.union(dirty);
   3956                 }
   3957 
   3958                 final int[] location = attachInfo.mInvalidateChildLocation;
   3959                 location[CHILD_LEFT_INDEX] = child.mLeft;
   3960                 location[CHILD_TOP_INDEX] = child.mTop;
   3961                 Matrix childMatrix = child.getMatrix();
   3962                 if (!childMatrix.isIdentity()) {
   3963                     RectF boundingRect = attachInfo.mTmpTransformRect;
   3964                     boundingRect.set(dirty);
   3965                     //boundingRect.inset(-0.5f, -0.5f);
   3966                     childMatrix.mapRect(boundingRect);
   3967                     dirty.set((int) (boundingRect.left - 0.5f),
   3968                             (int) (boundingRect.top - 0.5f),
   3969                             (int) (boundingRect.right + 0.5f),
   3970                             (int) (boundingRect.bottom + 0.5f));
   3971                 }
   3972 
   3973                 do {
   3974                     View view = null;
   3975                     if (parent instanceof View) {
   3976                         view = (View) parent;
   3977                         if (view.mLayerType != LAYER_TYPE_NONE &&
   3978                                 view.getParent() instanceof View) {
   3979                             final View grandParent = (View) view.getParent();
   3980                             grandParent.mPrivateFlags |= INVALIDATED;
   3981                             grandParent.mPrivateFlags &= ~DRAWING_CACHE_VALID;
   3982                         }
   3983                     }
   3984 
   3985                     if (drawAnimation) {
   3986                         if (view != null) {
   3987                             view.mPrivateFlags |= DRAW_ANIMATION;
   3988                         } else if (parent instanceof ViewRootImpl) {
   3989                             ((ViewRootImpl) parent).mIsAnimating = true;
   3990                         }
   3991                     }
   3992 
   3993                     // If the parent is dirty opaque or not dirty, mark it dirty with the opaque
   3994                     // flag coming from the child that initiated the invalidate
   3995                     if (view != null) {
   3996                         if ((view.mViewFlags & FADING_EDGE_MASK) != 0 &&
   3997                                 view.getSolidColor() == 0) {
   3998                             opaqueFlag = DIRTY;
   3999                         }
   4000                         if ((view.mPrivateFlags & DIRTY_MASK) != DIRTY) {
   4001                             view.mPrivateFlags = (view.mPrivateFlags & ~DIRTY_MASK) | opaqueFlag;
   4002                         }
   4003                     }
   4004 
   4005                     parent = parent.invalidateChildInParent(location, dirty);
   4006                     if (view != null) {
   4007                         // Account for transform on current parent
   4008                         Matrix m = view.getMatrix();
   4009                         if (!m.isIdentity()) {
   4010                             RectF boundingRect = attachInfo.mTmpTransformRect;
   4011                             boundingRect.set(dirty);
   4012                             m.mapRect(boundingRect);
   4013                             dirty.set((int) boundingRect.left, (int) boundingRect.top,
   4014                                     (int) (boundingRect.right + 0.5f),
   4015                                     (int) (boundingRect.bottom + 0.5f));
   4016                         }
   4017                     }
   4018                 } while (parent != null);
   4019             }
   4020         }
   4021     }


http://tools.oesf.biz/android-4.0.3_r1.0/xref/frameworks/base/core/java/android/view/ViewGroup.java