Various cleanup around resources and nine-patches.
Remove the stuff that doesn't use preloaded drawables when in compatibility mode, since this works fine ever since we were able to deal with drawables in a different density than the canvas. Change the snapshot function on View to return a snapshot at the same size that will actually be drawn on screen (when in compatibility mode), to be able to show scaling artifacts and all. This change was original an attempt to fix issue #2101917: Text field edges appears to be improperly rounded. That turns out to probably be something deeper in the graphics system, but also included here is the debugging code I did to try to track down the problem to make it easy to turn on again later. Change-Id: I34bfca629639c7ff103f3989d88874112ef778d9
This commit is contained in:
@ -24,7 +24,6 @@ import android.util.TypedValue;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Provides access to an application's raw asset files; see {@link Resources}
|
||||
|
@ -66,8 +66,6 @@ public class Resources {
|
||||
= new SparseArray<ColorStateList>();
|
||||
private static boolean mPreloaded;
|
||||
|
||||
private final LongSparseArray<Drawable.ConstantState> mPreloadedDrawables;
|
||||
|
||||
/*package*/ final TypedValue mTmpValue = new TypedValue();
|
||||
|
||||
// These are protected by the mTmpValue lock.
|
||||
@ -158,11 +156,6 @@ public class Resources {
|
||||
}
|
||||
updateConfiguration(config, metrics);
|
||||
assets.ensureStringBlocks();
|
||||
if (mCompatibilityInfo.isScalingRequired()) {
|
||||
mPreloadedDrawables = emptySparseArray();
|
||||
} else {
|
||||
mPreloadedDrawables = sPreloadedDrawables;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1669,7 +1662,7 @@ public class Resources {
|
||||
return dr;
|
||||
}
|
||||
|
||||
Drawable.ConstantState cs = mPreloadedDrawables.get(key);
|
||||
Drawable.ConstantState cs = sPreloadedDrawables.get(key);
|
||||
if (cs != null) {
|
||||
dr = cs.newDrawable();
|
||||
} else {
|
||||
@ -1976,7 +1969,6 @@ public class Resources {
|
||||
mMetrics.setToDefaults();
|
||||
updateConfiguration(null, null);
|
||||
mAssets.ensureStringBlocks();
|
||||
mPreloadedDrawables = sPreloadedDrawables;
|
||||
mCompatibilityInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
|
||||
}
|
||||
}
|
||||
|
@ -6038,16 +6038,23 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
|
||||
* some form of this public, but should think about the API.
|
||||
*/
|
||||
Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor) {
|
||||
final int width = mRight - mLeft;
|
||||
final int height = mBottom - mTop;
|
||||
int width = mRight - mLeft;
|
||||
int height = mBottom - mTop;
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, height, quality);
|
||||
final AttachInfo attachInfo = mAttachInfo;
|
||||
final float scale = attachInfo.mApplicationScale;
|
||||
width = (int) ((width * scale) + 0.5f);
|
||||
height = (int) ((height * scale) + 0.5f);
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(width > 0 ? width : 1,
|
||||
height > 0 ? height : 1, quality);
|
||||
if (bitmap == null) {
|
||||
throw new OutOfMemoryError();
|
||||
}
|
||||
|
||||
bitmap.setDensity(getResources().getDisplayMetrics().densityDpi);
|
||||
|
||||
Canvas canvas;
|
||||
final AttachInfo attachInfo = mAttachInfo;
|
||||
if (attachInfo != null) {
|
||||
canvas = attachInfo.mCanvas;
|
||||
if (canvas == null) {
|
||||
@ -6070,6 +6077,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
|
||||
|
||||
computeScroll();
|
||||
final int restoreCount = canvas.save();
|
||||
canvas.scale(scale, scale);
|
||||
canvas.translate(-mScrollX, -mScrollY);
|
||||
|
||||
// Temporarily remove the dirty mask
|
||||
|
@ -1,4 +1,25 @@
|
||||
/*
|
||||
**
|
||||
** Copyright 2006, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "9patch"
|
||||
#define LOG_NDEBUG 1
|
||||
|
||||
#include <utils/ResourceTypes.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include "SkCanvas.h"
|
||||
#include "SkRegion.h"
|
||||
@ -62,6 +83,9 @@ public:
|
||||
|
||||
if (destDensity == srcDensity || destDensity == 0
|
||||
|| srcDensity == 0) {
|
||||
LOGV("Drawing unscaled 9-patch: (%g,%g)-(%g,%g)",
|
||||
SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop),
|
||||
SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom));
|
||||
NinePatch_Draw(canvas, bounds, *bitmap, *chunk, paint, NULL);
|
||||
} else {
|
||||
canvas->save();
|
||||
@ -74,6 +98,11 @@ public:
|
||||
bounds.fBottom = SkScalarDiv(bounds.fBottom-bounds.fTop, scale);
|
||||
bounds.fLeft = bounds.fTop = 0;
|
||||
|
||||
LOGV("Drawing scaled 9-patch: (%g,%g)-(%g,%g) srcDensity=%d destDensity=%d",
|
||||
SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop),
|
||||
SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom),
|
||||
srcDensity, destDensity);
|
||||
|
||||
NinePatch_Draw(canvas, bounds, *bitmap, *chunk, paint, NULL);
|
||||
|
||||
canvas->restore();
|
||||
|
@ -16,8 +16,10 @@
|
||||
*/
|
||||
|
||||
#define LOG_TAG "NinePatch"
|
||||
#define LOG_NDEBUG 1
|
||||
|
||||
#include <utils/ResourceTypes.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkCanvas.h"
|
||||
@ -25,7 +27,7 @@
|
||||
#include "SkPaint.h"
|
||||
#include "SkUnPreMultiply.h"
|
||||
|
||||
#define USE_TRACEx
|
||||
#define USE_TRACE
|
||||
|
||||
#ifdef USE_TRACE
|
||||
static bool gTrace;
|
||||
@ -130,10 +132,10 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds,
|
||||
|
||||
SkASSERT(canvas || outRegion);
|
||||
|
||||
#if 0
|
||||
#ifdef USE_TRACE
|
||||
if (canvas) {
|
||||
const SkMatrix& m = canvas->getTotalMatrix();
|
||||
SkDebugf("ninepatch [%g %g %g] [%g %g %g]\n",
|
||||
LOGV("ninepatch [%g %g %g] [%g %g %g]\n",
|
||||
SkScalarToFloat(m[0]), SkScalarToFloat(m[1]), SkScalarToFloat(m[2]),
|
||||
SkScalarToFloat(m[3]), SkScalarToFloat(m[4]), SkScalarToFloat(m[5]));
|
||||
}
|
||||
@ -141,10 +143,10 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds,
|
||||
|
||||
#ifdef USE_TRACE
|
||||
if (gTrace) {
|
||||
SkDEBUGF(("======== ninepatch bounds [%g %g]\n", SkScalarToFloat(bounds.width()), SkScalarToFloat(bounds.height())));
|
||||
SkDEBUGF(("======== ninepatch paint bm [%d,%d]\n", bitmap.width(), bitmap.height()));
|
||||
SkDEBUGF(("======== ninepatch xDivs [%d,%d]\n", chunk.xDivs[0], chunk.xDivs[1]));
|
||||
SkDEBUGF(("======== ninepatch yDivs [%d,%d]\n", chunk.yDivs[0], chunk.yDivs[1]));
|
||||
LOGV("======== ninepatch bounds [%g %g]\n", SkScalarToFloat(bounds.width()), SkScalarToFloat(bounds.height()));
|
||||
LOGV("======== ninepatch paint bm [%d,%d]\n", bitmap.width(), bitmap.height());
|
||||
LOGV("======== ninepatch xDivs [%d,%d]\n", chunk.xDivs[0], chunk.xDivs[1]);
|
||||
LOGV("======== ninepatch yDivs [%d,%d]\n", chunk.yDivs[0], chunk.yDivs[1]);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -153,7 +155,7 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds,
|
||||
(paint && paint->getXfermode() == NULL && paint->getAlpha() == 0))
|
||||
{
|
||||
#ifdef USE_TRACE
|
||||
if (gTrace) SkDEBUGF(("======== abort ninepatch draw\n"));
|
||||
if (gTrace) LOGV("======== abort ninepatch draw\n");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
@ -198,8 +200,8 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds,
|
||||
}
|
||||
int numFixedYPixelsRemaining = bitmapHeight - numStretchyYPixelsRemaining;
|
||||
|
||||
#if 0
|
||||
SkDebugf("NinePatch [%d %d] bounds [%g %g %g %g] divs [%d %d]\n",
|
||||
#ifdef USE_TRACE
|
||||
LOGV("NinePatch [%d %d] bounds [%g %g %g %g] divs [%d %d]\n",
|
||||
bitmap.width(), bitmap.height(),
|
||||
SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop),
|
||||
SkScalarToFloat(bounds.width()), SkScalarToFloat(bounds.height()),
|
||||
@ -302,13 +304,13 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds,
|
||||
goto nextDiv;
|
||||
}
|
||||
if (canvas) {
|
||||
#if 0
|
||||
SkDebugf("-- src [%d %d %d %d] dst [%g %g %g %g]\n",
|
||||
#ifdef USE_TRACE
|
||||
LOGV("-- src [%d %d %d %d] dst [%g %g %g %g]\n",
|
||||
src.fLeft, src.fTop, src.width(), src.height(),
|
||||
SkScalarToFloat(dst.fLeft), SkScalarToFloat(dst.fTop),
|
||||
SkScalarToFloat(dst.width()), SkScalarToFloat(dst.height()));
|
||||
if (2 == src.width() && SkIntToScalar(5) == dst.width()) {
|
||||
SkDebugf("--- skip patch\n");
|
||||
LOGV("--- skip patch\n");
|
||||
}
|
||||
#endif
|
||||
drawStretchyPatch(canvas, src, dst, bitmap, *paint, initColor,
|
||||
|
@ -21,6 +21,7 @@ import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
@ -170,6 +171,11 @@ public class NinePatchDrawable extends Drawable {
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
if (false) {
|
||||
float[] pts = new float[2];
|
||||
canvas.getMatrix().mapPoints(pts);
|
||||
Log.v("9patch", "Drawing 9-patch @ " + pts[0] + "," + pts[1] + ": " + getBounds());
|
||||
}
|
||||
mNinePatch.draw(canvas, getBounds(), mPaint);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user