Cleanup various clang warnings, use unique_ptrs in several places

Change-Id: I347904b25e51fcc7de14b1e72f1acd0f6ba26f3f
This commit is contained in:
Chris Craik
2014-12-22 17:16:56 -08:00
parent e84a208317
commit 51d6a3db97
30 changed files with 133 additions and 226 deletions

View File

@@ -36,7 +36,6 @@ BaseRenderNodeAnimator::BaseRenderNodeAnimator(float finalValue)
, mFinalValue(finalValue)
, mDeltaValue(0)
, mFromValue(0)
, mInterpolator(0)
, mStagingPlayState(NOT_STARTED)
, mPlayState(NOT_STARTED)
, mHasStartValue(false)
@@ -47,7 +46,6 @@ BaseRenderNodeAnimator::BaseRenderNodeAnimator(float finalValue)
}
BaseRenderNodeAnimator::~BaseRenderNodeAnimator() {
delete mInterpolator;
}
void BaseRenderNodeAnimator::checkMutable() {
@@ -58,8 +56,7 @@ void BaseRenderNodeAnimator::checkMutable() {
void BaseRenderNodeAnimator::setInterpolator(Interpolator* interpolator) {
checkMutable();
delete mInterpolator;
mInterpolator = interpolator;
mInterpolator.reset(interpolator);
}
void BaseRenderNodeAnimator::setStartValue(float value) {
@@ -119,7 +116,7 @@ void BaseRenderNodeAnimator::transitionToRunning(AnimationContext& context) {
}
// No interpolator was set, use the default
if (!mInterpolator) {
mInterpolator = Interpolator::createDefaultInterpolator();
mInterpolator.reset(Interpolator::createDefaultInterpolator());
}
if (mDuration < 0 || mDuration > 50000) {
ALOGW("Your duration is strange and confusing: %" PRId64, mDuration);

View File

@@ -16,6 +16,7 @@
#ifndef ANIMATOR_H
#define ANIMATOR_H
#include <memory>
#include <cutils/compiler.h>
#include <utils/RefBase.h>
#include <utils/StrongPointer.h>
@@ -99,7 +100,7 @@ protected:
float mDeltaValue;
float mFromValue;
Interpolator* mInterpolator;
std::unique_ptr<Interpolator> mInterpolator;
PlayState mStagingPlayState;
PlayState mPlayState;
bool mHasStartValue;

View File

@@ -224,9 +224,8 @@ void Caches::terminate() {
mCurrentBuffer = 0;
glDeleteBuffers(1, &mMeshIndices);
delete[] mRegionMesh;
mMeshIndices = 0;
mRegionMesh = NULL;
mRegionMesh.release();
glDeleteBuffers(1, &mShadowStripsIndices);
mShadowStripsIndices = 0;
@@ -406,7 +405,7 @@ bool Caches::bindIndicesBufferInternal(const GLuint buffer) {
bool Caches::bindQuadIndicesBuffer() {
if (!mMeshIndices) {
uint16_t* regionIndices = new uint16_t[gMaxNumberOfQuads * 6];
std::unique_ptr<uint16_t[]> regionIndices(new uint16_t[gMaxNumberOfQuads * 6]);
for (uint32_t i = 0; i < gMaxNumberOfQuads; i++) {
uint16_t quad = i * 4;
int index = i * 6;
@@ -421,9 +420,7 @@ bool Caches::bindQuadIndicesBuffer() {
glGenBuffers(1, &mMeshIndices);
bool force = bindIndicesBufferInternal(mMeshIndices);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, gMaxNumberOfQuads * 6 * sizeof(uint16_t),
regionIndices, GL_STATIC_DRAW);
delete[] regionIndices;
regionIndices.get(), GL_STATIC_DRAW);
return force;
}
@@ -432,14 +429,12 @@ bool Caches::bindQuadIndicesBuffer() {
bool Caches::bindShadowIndicesBuffer() {
if (!mShadowStripsIndices) {
uint16_t* shadowIndices = new uint16_t[MAX_SHADOW_INDEX_COUNT];
ShadowTessellator::generateShadowIndices(shadowIndices);
std::unique_ptr<uint16_t[]> shadowIndices(new uint16_t[MAX_SHADOW_INDEX_COUNT]);
ShadowTessellator::generateShadowIndices(shadowIndices.get());
glGenBuffers(1, &mShadowStripsIndices);
bool force = bindIndicesBufferInternal(mShadowStripsIndices);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_SHADOW_INDEX_COUNT * sizeof(uint16_t),
shadowIndices, GL_STATIC_DRAW);
delete[] shadowIndices;
shadowIndices.get(), GL_STATIC_DRAW);
return force;
}
@@ -687,10 +682,10 @@ void Caches::unregisterFunctors(uint32_t functorCount) {
TextureVertex* Caches::getRegionMesh() {
// Create the mesh, 2 triangles and 4 vertices per rectangle in the region
if (!mRegionMesh) {
mRegionMesh = new TextureVertex[gMaxNumberOfQuads * 4];
mRegionMesh.reset(new TextureVertex[gMaxNumberOfQuads * 4]);
}
return mRegionMesh;
return mRegionMesh.get();
}
///////////////////////////////////////////////////////////////////////////////

View File

@@ -416,7 +416,7 @@ private:
Extensions& mExtensions;
// Used to render layers
TextureVertex* mRegionMesh;
std::unique_ptr<TextureVertex[]> mRegionMesh;
// Global index buffer
GLuint mMeshIndices;

View File

@@ -62,18 +62,6 @@ void DisplayListData::cleanupResources() {
resourceCache.unlock();
for (size_t i = 0; i < paints.size(); i++) {
delete paints.itemAt(i);
}
for (size_t i = 0; i < regions.size(); i++) {
delete regions.itemAt(i);
}
for (size_t i = 0; i < paths.size(); i++) {
delete paths.itemAt(i);
}
bitmapResources.clear();
ownedBitmapResources.clear();
patchResources.clear();

View File

@@ -137,10 +137,10 @@ public:
Vector<const SkBitmap*> ownedBitmapResources;
Vector<const Res_png_9patch*> patchResources;
Vector<const SkPaint*> paints;
Vector<const SkPath*> paths;
std::vector<std::unique_ptr<const SkPaint>> paints;
std::vector<std::unique_ptr<const SkRegion>> regions;
std::vector<std::unique_ptr<const SkPath>> paths;
SortedVector<const SkPath*> sourcePaths;
Vector<const SkRegion*> regions;
Vector<Functor*> functors;
const Vector<Chunk>& getChunks() const {

View File

@@ -17,10 +17,6 @@
#ifndef ANDROID_HWUI_DISPLAY_OPERATION_H
#define ANDROID_HWUI_DISPLAY_OPERATION_H
#ifndef LOG_TAG
#define LOG_TAG "OpenGLRenderer"
#endif
#include <SkColor.h>
#include <SkPath.h>
#include <SkPathOps.h>
@@ -39,11 +35,6 @@
#include "UvMapper.h"
#include "utils/LinearAllocator.h"
#define CRASH() do { \
*(int *)(uintptr_t) 0xbbadbeef = 0; \
((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \
} while(false)
// Use OP_LOG for logging with arglist, OP_LOGS if just printing char*
#define OP_LOGS(s) OP_LOG("%s", (s))
#define OP_LOG(s, ...) ALOGD( "%*s" s, level * 2, "", __VA_ARGS__ )
@@ -66,9 +57,9 @@ class DisplayListOp {
public:
// These objects should always be allocated with a LinearAllocator, and never destroyed/deleted.
// standard new() intentionally not implemented, and delete/deconstructor should never be used.
virtual ~DisplayListOp() { CRASH(); }
static void operator delete(void* ptr) { CRASH(); }
/** static void* operator new(size_t size); PURPOSELY OMITTED **/
virtual ~DisplayListOp() { LOG_ALWAYS_FATAL("Destructor not supported"); }
static void operator delete(void* ptr) { LOG_ALWAYS_FATAL("delete not supported"); }
static void* operator new(size_t size) = delete; /** PURPOSELY OMITTED **/
static void* operator new(size_t size, LinearAllocator& allocator) {
return allocator.alloc(size);
}
@@ -93,10 +84,6 @@ public:
class StateOp : public DisplayListOp {
public:
StateOp() {};
virtual ~StateOp() {}
virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level,
bool useQuickReject) {
// default behavior only affects immediate, deferrable state, issue directly to renderer
@@ -869,7 +856,7 @@ public:
patchOp->mLocalBounds.top + 0.5f);
// Copy & transform all the vertices for the current operation
TextureVertex* opVertices = opMesh->vertices;
TextureVertex* opVertices = opMesh->vertices.get();
for (uint32_t j = 0; j < vertexCount; j++, opVertices++) {
TextureVertex::set(vertex++,
opVertices->x + tx, opVertices->y + ty,

View File

@@ -234,21 +234,22 @@ private:
inline const SkPath* refPath(const SkPath* path) {
if (!path) return nullptr;
const SkPath* pathCopy = mPathMap.valueFor(path);
if (pathCopy == nullptr || pathCopy->getGenerationID() != path->getGenerationID()) {
const SkPath* cachedPath = mPathMap.valueFor(path);
if (cachedPath == nullptr || cachedPath->getGenerationID() != path->getGenerationID()) {
SkPath* newPathCopy = new SkPath(*path);
newPathCopy->setSourcePath(path);
cachedPath = newPathCopy;
std::unique_ptr<const SkPath> copy(newPathCopy);
mDisplayListData->paths.push_back(std::move(copy));
pathCopy = newPathCopy;
// replaceValueFor() performs an add if the entry doesn't exist
mPathMap.replaceValueFor(path, pathCopy);
mDisplayListData->paths.add(pathCopy);
mPathMap.replaceValueFor(path, cachedPath);
}
if (mDisplayListData->sourcePaths.indexOf(path) < 0) {
mResourceCache.incrementRefcount(path);
mDisplayListData->sourcePaths.add(path);
}
return pathCopy;
return cachedPath;
}
inline const SkPaint* refPaint(const SkPaint* paint) {
@@ -258,8 +259,8 @@ private:
// so that we don't need to modify the paint every time we access it.
SkTLazy<SkPaint> filteredPaint;
if (mDrawFilter.get()) {
paint = filteredPaint.init();
mDrawFilter->filter(filteredPaint.get(), SkDrawFilter::kPaint_Type);
paint = filteredPaint.init();
mDrawFilter->filter(filteredPaint.get(), SkDrawFilter::kPaint_Type);
}
// compute the hash key for the paint and check the cache.
@@ -268,10 +269,12 @@ private:
// In the unlikely event that 2 unique paints have the same hash we do a
// object equality check to ensure we don't erroneously dedup them.
if (cachedPaint == nullptr || *cachedPaint != *paint) {
cachedPaint = new SkPaint(*paint);
cachedPaint = new SkPaint(*paint);
std::unique_ptr<const SkPaint> copy(cachedPaint);
mDisplayListData->paints.push_back(std::move(copy));
// replaceValueFor() performs an add if the entry doesn't exist
mPaintMap.replaceValueFor(key, cachedPaint);
mDisplayListData->paints.add(cachedPaint);
}
return cachedPaint;
@@ -279,10 +282,12 @@ private:
inline SkPaint* copyPaint(const SkPaint* paint) {
if (!paint) return nullptr;
SkPaint* paintCopy = new SkPaint(*paint);
mDisplayListData->paints.add(paintCopy);
return paintCopy;
SkPaint* returnPaint = new SkPaint(*paint);
std::unique_ptr<const SkPaint> copy(returnPaint);
mDisplayListData->paints.push_back(std::move(copy));
return returnPaint;
}
inline const SkRegion* refRegion(const SkRegion* region) {
@@ -290,16 +295,18 @@ private:
return region;
}
const SkRegion* regionCopy = mRegionMap.valueFor(region);
const SkRegion* cachedRegion = mRegionMap.valueFor(region);
// TODO: Add generation ID to SkRegion
if (regionCopy == nullptr) {
regionCopy = new SkRegion(*region);
if (cachedRegion == nullptr) {
std::unique_ptr<const SkRegion> copy(new SkRegion(*region));
cachedRegion = copy.get();
mDisplayListData->regions.push_back(std::move(copy));
// replaceValueFor() performs an add if the entry doesn't exist
mRegionMap.replaceValueFor(region, regionCopy);
mDisplayListData->regions.add(regionCopy);
mRegionMap.replaceValueFor(region, cachedRegion);
}
return regionCopy;
return cachedRegion;
}
inline const SkBitmap* refBitmap(const SkBitmap* bitmap) {

View File

@@ -770,15 +770,12 @@ void FontRenderer::blurImage(uint8_t** image, int32_t width, int32_t height, flo
}
#endif
float *gaussian = new float[2 * intRadius + 1];
Blur::generateGaussianWeights(gaussian, intRadius);
std::unique_ptr<float[]> gaussian(new float[2 * intRadius + 1]);
Blur::generateGaussianWeights(gaussian.get(), intRadius);
uint8_t* scratch = new uint8_t[width * height];
Blur::horizontal(gaussian, intRadius, *image, scratch, width, height);
Blur::vertical(gaussian, intRadius, scratch, *image, width, height);
delete[] gaussian;
delete[] scratch;
std::unique_ptr<uint8_t[]> scratch(new uint8_t[width * height]);
Blur::horizontal(gaussian.get(), intRadius, *image, scratch.get(), width, height);
Blur::vertical(gaussian.get(), intRadius, scratch.get(), *image, width, height);
}
static uint32_t calculateCacheSize(const Vector<CacheTexture*>& cacheTextures) {

View File

@@ -183,12 +183,6 @@ Lookup3GammaFontRenderer::Lookup3GammaFontRenderer(): GammaFontRenderer() {
memset(mRenderersUsageCount, 0, sizeof(uint32_t) * kGammaCount);
}
Lookup3GammaFontRenderer::~Lookup3GammaFontRenderer() {
for (int i = 0; i < kGammaCount; i++) {
delete mRenderers[i];
}
}
void Lookup3GammaFontRenderer::endPrecaching() {
for (int i = 0; i < kGammaCount; i++) {
if (mRenderers[i]) {
@@ -199,8 +193,7 @@ void Lookup3GammaFontRenderer::endPrecaching() {
void Lookup3GammaFontRenderer::clear() {
for (int i = 0; i < kGammaCount; i++) {
delete mRenderers[i];
mRenderers[i] = NULL;
mRenderers[i].release();
}
}
@@ -221,8 +214,7 @@ void Lookup3GammaFontRenderer::flush() {
if (count <= 1 || min < 0) return;
delete mRenderers[min];
mRenderers[min] = NULL;
mRenderers[min].release();
// Also eliminate the caches for large glyphs, as they consume significant memory
for (int i = 0; i < kGammaCount; ++i) {
@@ -233,14 +225,12 @@ void Lookup3GammaFontRenderer::flush() {
}
FontRenderer* Lookup3GammaFontRenderer::getRenderer(Gamma gamma) {
FontRenderer* renderer = mRenderers[gamma];
if (!renderer) {
renderer = new FontRenderer();
mRenderers[gamma] = renderer;
renderer->setGammaTable(&mGammaTable[gamma * 256]);
if (!mRenderers[gamma]) {
mRenderers[gamma].reset(new FontRenderer());
mRenderers[gamma]->setGammaTable(&mGammaTable[gamma * 256]);
}
mRenderersUsageCount[gamma]++;
return renderer;
return mRenderers[gamma].get();
}
FontRenderer& Lookup3GammaFontRenderer::getFontRenderer(const SkPaint* paint) {

View File

@@ -151,8 +151,6 @@ private:
class Lookup3GammaFontRenderer: public GammaFontRenderer {
public:
~Lookup3GammaFontRenderer();
void clear() override;
void flush() override;
@@ -165,10 +163,9 @@ public:
uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const override {
if (fontRenderer >= kGammaCount) return 0;
FontRenderer* renderer = mRenderers[fontRenderer];
if (!renderer) return 0;
if (!mRenderers[fontRenderer]) return 0;
return renderer->getCacheSize(format);
return mRenderers[fontRenderer]->getCacheSize(format);
}
void describe(ProgramDescription& description, const SkPaint* paint) const override {
@@ -192,7 +189,7 @@ private:
FontRenderer* getRenderer(Gamma gamma);
uint32_t mRenderersUsageCount[kGammaCount];
FontRenderer* mRenderers[kGammaCount];
std::unique_ptr<FontRenderer> mRenderers[kGammaCount];
uint8_t mGammaTable[256 * kGammaCount];

View File

@@ -52,10 +52,10 @@ int GradientCacheEntry::compare(const GradientCacheEntry& lhs, const GradientCac
int deltaInt = int(lhs.count) - int(rhs.count);
if (deltaInt != 0) return deltaInt;
deltaInt = memcmp(lhs.colors, rhs.colors, lhs.count * sizeof(uint32_t));
deltaInt = memcmp(lhs.colors.get(), rhs.colors.get(), lhs.count * sizeof(uint32_t));
if (deltaInt != 0) return deltaInt;
return memcmp(lhs.positions, rhs.positions, lhs.count * sizeof(float));
return memcmp(lhs.positions.get(), rhs.positions.get(), lhs.count * sizeof(float));
}
///////////////////////////////////////////////////////////////////////////////

View File

@@ -42,20 +42,12 @@ struct GradientCacheEntry {
}
GradientCacheEntry(const GradientCacheEntry& entry) {
copy(entry.colors, entry.positions, entry.count);
}
~GradientCacheEntry() {
delete[] colors;
delete[] positions;
copy(entry.colors.get(), entry.positions.get(), entry.count);
}
GradientCacheEntry& operator=(const GradientCacheEntry& entry) {
if (this != &entry) {
delete[] colors;
delete[] positions;
copy(entry.colors, entry.positions, entry.count);
copy(entry.colors.get(), entry.positions.get(), entry.count);
}
return *this;
@@ -73,18 +65,18 @@ struct GradientCacheEntry {
return compare(*this, other) != 0;
}
uint32_t* colors;
float* positions;
std::unique_ptr<uint32_t[]> colors;
std::unique_ptr<float[]> positions;
uint32_t count;
private:
void copy(uint32_t* colors, float* positions, uint32_t count) {
this->count = count;
this->colors = new uint32_t[count];
this->positions = new float[count];
this->colors.reset(new uint32_t[count]);
this->positions.reset(new float[count]);
memcpy(this->colors, colors, count * sizeof(uint32_t));
memcpy(this->positions, positions, count * sizeof(float));
memcpy(this->colors.get(), colors, count * sizeof(uint32_t));
memcpy(this->positions.get(), positions, count * sizeof(float));
}
}; // GradientCacheEntry

View File

@@ -88,14 +88,12 @@ float OvershootInterpolator::interpolate(float t) {
return t * t * ((mTension + 1) * t + mTension) + 1.0f;
}
LUTInterpolator::LUTInterpolator(float* values, size_t size) {
mValues = values;
mSize = size;
LUTInterpolator::LUTInterpolator(float* values, size_t size)
: mValues(values)
, mSize(size) {
}
LUTInterpolator::~LUTInterpolator() {
delete mValues;
mValues = 0;
}
float LUTInterpolator::interpolate(float input) {
@@ -112,7 +110,7 @@ float LUTInterpolator::interpolate(float input) {
LOG_ALWAYS_FATAL_IF(i1 < 0 || i2 < 0, "negatives in interpolation!"
" i1=%d, i2=%d, input=%f, lutpos=%f, size=%zu, values=%p, ipart=%f, weight=%f",
i1, i2, input, lutpos, mSize, mValues, ipart, weight);
i1, i2, input, lutpos, mSize, mValues.get(), ipart, weight);
float v1 = mValues[i1];
float v2 = mValues[i2];

View File

@@ -17,6 +17,7 @@
#define INTERPOLATOR_H
#include <stddef.h>
#include <memory>
#include <cutils/compiler.h>
@@ -107,7 +108,7 @@ public:
virtual float interpolate(float input);
private:
float* mValues;
std::unique_ptr<float[]> mValues;
size_t mSize;
};

View File

@@ -54,14 +54,12 @@ Layer::Layer(Type layerType, RenderState& renderState, const uint32_t layerWidth
texture.height = layerHeight;
colorFilter = NULL;
deferredUpdateScheduled = false;
renderer = NULL;
renderNode = NULL;
fbo = 0;
stencil = NULL;
debugDrawUpdate = false;
hasDrawnSinceUpdate = false;
forceFilter = false;
deferredList = NULL;
convexMask = NULL;
rendererLightPosDirty = true;
wasBuildLayered = false;
@@ -76,8 +74,6 @@ Layer::~Layer() {
deleteTexture();
delete[] mesh;
delete deferredList;
delete renderer;
}
uint32_t Layer::computeIdealWidth(uint32_t layerWidth) {
@@ -90,7 +86,7 @@ uint32_t Layer::computeIdealHeight(uint32_t layerHeight) {
void Layer::requireRenderer() {
if (!renderer) {
renderer = new LayerRenderer(renderState, this);
renderer.reset(new LayerRenderer(renderState, this));
renderer->initProperties();
}
}
@@ -241,8 +237,7 @@ void Layer::defer(const OpenGLRenderer& rootRenderer) {
dirtyRect.set(0, 0, width, height);
}
delete deferredList;
deferredList = new DeferredDisplayList(dirtyRect);
deferredList.reset(new DeferredDisplayList(dirtyRect));
DeferStateStruct deferredState(*deferredList, *renderer,
RenderNode::kReplayFlag_ClipChildren);
@@ -260,10 +255,7 @@ void Layer::defer(const OpenGLRenderer& rootRenderer) {
void Layer::cancelDefer() {
renderNode = NULL;
deferredUpdateScheduled = false;
if (deferredList) {
delete deferredList;
deferredList = NULL;
}
deferredList.release();
}
void Layer::flush() {

View File

@@ -21,6 +21,7 @@
#include <sys/types.h>
#include <utils/StrongPointer.h>
#include <utils/RefBase.h>
#include <memory>
#include <GLES2/gl2.h>
@@ -44,9 +45,9 @@ namespace uirenderer {
// Forward declarations
class Caches;
class RenderNode;
class RenderState;
class OpenGLRenderer;
class RenderNode;
class DeferredDisplayList;
struct DeferStateStruct;
@@ -320,7 +321,7 @@ public:
* Used for deferred updates.
*/
bool deferredUpdateScheduled;
OpenGLRenderer* renderer;
std::unique_ptr<OpenGLRenderer> renderer;
sp<RenderNode> renderNode;
Rect dirtyRect;
bool debugDrawUpdate;
@@ -417,7 +418,7 @@ private:
* Used to defer display lists when the layer is updated with a
* display list.
*/
DeferredDisplayList* deferredList;
std::unique_ptr<DeferredDisplayList> deferredList;
/**
* This convex path should be used to mask the layer's draw to the screen.

View File

@@ -313,10 +313,6 @@ void OpenGLRenderer::endTiling() {
bool OpenGLRenderer::finish() {
renderOverdraw();
endTiling();
for (size_t i = 0; i < mTempPaths.size(); i++) {
delete mTempPaths[i];
}
mTempPaths.clear();
// When finish() is invoked on FBO 0 we've reached the end
@@ -800,7 +796,7 @@ bool OpenGLRenderer::createLayer(float left, float top, float right, float botto
bounds.getWidth(), bounds.getHeight());
// Enqueue the buffer coordinates to clear the corresponding region later
mLayers.push(new Rect(bounds));
mLayers.push_back(Rect(bounds));
}
}
@@ -1295,14 +1291,12 @@ void OpenGLRenderer::clearLayerRegions() {
Vertex* vertex = mesh;
for (uint32_t i = 0; i < count; i++) {
Rect* bounds = mLayers.itemAt(i);
const Rect& bounds = mLayers[i];
Vertex::set(vertex++, bounds->left, bounds->top);
Vertex::set(vertex++, bounds->right, bounds->top);
Vertex::set(vertex++, bounds->left, bounds->bottom);
Vertex::set(vertex++, bounds->right, bounds->bottom);
delete bounds;
Vertex::set(vertex++, bounds.left, bounds.top);
Vertex::set(vertex++, bounds.right, bounds.top);
Vertex::set(vertex++, bounds.left, bounds.bottom);
Vertex::set(vertex++, bounds.right, bounds.bottom);
}
// We must clear the list of dirty rects before we
// call setupDraw() to prevent stencil setup to do
@@ -1324,9 +1318,6 @@ void OpenGLRenderer::clearLayerRegions() {
if (scissorChanged) mCaches.enableScissor();
} else {
for (uint32_t i = 0; i < count; i++) {
delete mLayers.itemAt(i);
}
mLayers.clear();
}
}
@@ -2046,17 +2037,15 @@ void OpenGLRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int m
const uint32_t count = meshWidth * meshHeight * 6;
Vector<ColorTextureVertex> mesh; // TODO: use C++11 unique_ptr
mesh.setCapacity(count);
ColorTextureVertex* vertex = mesh.editArray();
std::unique_ptr<ColorTextureVertex[]> mesh(new ColorTextureVertex[count]);
ColorTextureVertex* vertex = &mesh[0];
bool cleanupColors = false;
std::unique_ptr<int[]> tempColors;
if (!colors) {
uint32_t colorsCount = (meshWidth + 1) * (meshHeight + 1);
int* newColors = new int[colorsCount];
memset(newColors, 0xff, colorsCount * sizeof(int));
colors = newColors;
cleanupColors = true;
tempColors.reset(new int[colorsCount]);
memset(tempColors.get(), 0xff, colorsCount * sizeof(int));
colors = tempColors.get();
}
mCaches.activeTexture(0);
@@ -2099,14 +2088,12 @@ void OpenGLRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int m
}
if (quickRejectSetupScissor(left, top, right, bottom)) {
if (cleanupColors) delete[] colors;
return;
}
if (!texture) {
texture = mCaches.textureCache.get(bitmap);
if (!texture) {
if (cleanupColors) delete[] colors;
return;
}
}
@@ -2145,8 +2132,6 @@ void OpenGLRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int m
glDisableVertexAttribArray(slot);
}
if (cleanupColors) delete[] colors;
mDirty = true;
}

View File

@@ -62,12 +62,11 @@ class TextSetupFunctor;
class VertexBuffer;
struct DrawModifiers {
DrawModifiers() {
reset();
}
DrawModifiers()
: mOverrideLayerAlpha(0.0f) {}
void reset() {
memset(this, 0, sizeof(DrawModifiers));
mOverrideLayerAlpha = 0.0f;
}
float mOverrideLayerAlpha;
@@ -391,9 +390,10 @@ public:
virtual GLuint onGetTargetFbo() const override { return 0; }
SkPath* allocPathForFrame() {
SkPath* path = new SkPath();
mTempPaths.push_back(path);
return path;
std::unique_ptr<SkPath> path(new SkPath());
SkPath* returnPath = path.get();
mTempPaths.push_back(std::move(path));
return returnPath;
}
protected:
@@ -1029,7 +1029,7 @@ private:
RenderState& mRenderState;
// List of rectangles to clear after saveLayer() is invoked
Vector<Rect*> mLayers;
std::vector<Rect> mLayers;
// List of layers to update at the beginning of a frame
Vector< sp<Layer> > mLayerUpdates;
@@ -1069,7 +1069,7 @@ private:
uint8_t mSpotShadowAlpha;
// Paths kept alive for the duration of the frame
std::vector<SkPath*> mTempPaths;
std::vector<std::unique_ptr<SkPath>> mTempPaths;
friend class Layer;
friend class TextSetupFunctor;

View File

@@ -32,11 +32,7 @@ namespace uirenderer {
// Constructors/destructor
///////////////////////////////////////////////////////////////////////////////
Patch::Patch(): vertices(NULL), verticesCount(0), indexCount(0), hasEmptyQuads(false) {
}
Patch::~Patch() {
delete[] vertices;
Patch::Patch(): vertices(), verticesCount(0), indexCount(0), hasEmptyQuads(false) {
}
///////////////////////////////////////////////////////////////////////////////
@@ -55,7 +51,7 @@ TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeig
TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeight,
float width, float height, const UvMapper& mapper, const Res_png_9patch* patch) {
if (vertices) return vertices;
if (vertices) return vertices.get();
int8_t emptyQuads = 0;
mColors = patch->getColors();
@@ -77,8 +73,8 @@ TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeig
uint32_t maxVertices = ((xCount + 1) * (yCount + 1) - emptyQuads) * 4;
if (maxVertices == 0) return NULL;
TextureVertex* tempVertices = new TextureVertex[maxVertices];
TextureVertex* vertex = tempVertices;
vertices.reset(new TextureVertex[maxVertices]);
TextureVertex* vertex = vertices.get();
const int32_t* xDivs = patch->getXDivs();
const int32_t* yDivs = patch->getYDivs();
@@ -157,15 +153,13 @@ TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeig
width, bitmapWidth, quadCount);
}
if (verticesCount == maxVertices) {
vertices = tempVertices;
} else {
vertices = new TextureVertex[verticesCount];
memcpy(vertices, tempVertices, verticesCount * sizeof(TextureVertex));
delete[] tempVertices;
if (verticesCount != maxVertices) {
std::unique_ptr<TextureVertex[]> reducedVertices(new TextureVertex[verticesCount]);
memcpy(reducedVertices.get(), vertices.get(), verticesCount * sizeof(TextureVertex));
vertices = std::move(reducedVertices);
}
return vertices;
return vertices.get();
}
void Patch::generateRow(const int32_t* xDivs, uint32_t xCount, TextureVertex*& vertex,

View File

@@ -40,14 +40,13 @@ struct TextureVertex;
class Patch {
public:
Patch();
~Patch();
/**
* Returns the size of this patch's mesh in bytes.
*/
uint32_t getSize() const;
TextureVertex* vertices;
std::unique_ptr<TextureVertex[]> vertices;
uint32_t verticesCount;
uint32_t indexCount;
bool hasEmptyQuads;

View File

@@ -229,7 +229,6 @@ void getStrokeVerticesFromPerimeter(const PaintInfo& paintInfo, const Vector<Ver
current->x - totalOffset.x,
current->y - totalOffset.y);
last = current;
current = next;
lastNormal = nextNormal;
}
@@ -372,7 +371,6 @@ void getFillVerticesFromPerimeterAA(const PaintInfo& paintInfo, const Vector<Ver
current->y - totalOffset.y,
maxAlpha);
last = current;
current = next;
lastNormal = nextNormal;
}
@@ -700,7 +698,6 @@ void getStrokeVerticesFromPerimeterAA(const PaintInfo& paintInfo, const Vector<V
current->y - outerOffset.y,
0.0f);
last = current;
current = next;
lastNormal = nextNormal;
}

View File

@@ -34,7 +34,6 @@ namespace uirenderer {
class CpuPixelBuffer: public PixelBuffer {
public:
CpuPixelBuffer(GLenum format, uint32_t width, uint32_t height);
~CpuPixelBuffer();
uint8_t* map(AccessMode mode = kAccessMode_ReadWrite);
void unmap();
@@ -44,23 +43,19 @@ public:
void upload(uint32_t x, uint32_t y, uint32_t width, uint32_t height, int offset);
private:
uint8_t* mBuffer;
std::unique_ptr<uint8_t[]> mBuffer;
};
CpuPixelBuffer::CpuPixelBuffer(GLenum format, uint32_t width, uint32_t height):
PixelBuffer(format, width, height) {
mBuffer = new uint8_t[width * height * formatSize(format)];
}
CpuPixelBuffer::~CpuPixelBuffer() {
delete[] mBuffer;
CpuPixelBuffer::CpuPixelBuffer(GLenum format, uint32_t width, uint32_t height)
: PixelBuffer(format, width, height)
, mBuffer(new uint8_t[width * height * formatSize(format)]) {
}
uint8_t* CpuPixelBuffer::map(AccessMode mode) {
if (mAccessMode == kAccessMode_None) {
mAccessMode = mode;
}
return mBuffer;
return mBuffer.get();
}
void CpuPixelBuffer::unmap() {
@@ -68,12 +63,12 @@ void CpuPixelBuffer::unmap() {
}
uint8_t* CpuPixelBuffer::getMappedPointer() const {
return mAccessMode == kAccessMode_None ? NULL : mBuffer;
return mAccessMode == kAccessMode_None ? nullptr : mBuffer.get();
}
void CpuPixelBuffer::upload(uint32_t x, uint32_t y, uint32_t width, uint32_t height, int offset) {
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height,
mFormat, GL_UNSIGNED_BYTE, mBuffer + offset);
mFormat, GL_UNSIGNED_BYTE, &mBuffer[offset]);
}
///////////////////////////////////////////////////////////////////////////////

View File

@@ -417,11 +417,6 @@ ProgramCache::~ProgramCache() {
void ProgramCache::clear() {
PROGRAM_LOGD("Clearing program cache");
size_t count = mCache.size();
for (size_t i = 0; i < count; i++) {
delete mCache.valueAt(i);
}
mCache.clear();
}
@@ -433,14 +428,14 @@ Program* ProgramCache::get(const ProgramDescription& description) {
key = PROGRAM_KEY_TEXTURE;
}
ssize_t index = mCache.indexOfKey(key);
auto iter = mCache.find(key);
Program* program = NULL;
if (index < 0) {
if (iter == mCache.end()) {
description.log("Could not find program");
program = generateProgram(description, key);
mCache.add(key, program);
mCache[key] = std::unique_ptr<Program>(program);
} else {
program = mCache.valueAt(index);
program = iter->second.get();
}
return program;
}

View File

@@ -20,6 +20,7 @@
#include <utils/KeyedVector.h>
#include <utils/Log.h>
#include <utils/String8.h>
#include <map>
#include <GLES2/gl2.h>
@@ -55,7 +56,7 @@ private:
void printLongString(const String8& shader) const;
KeyedVector<programid, Program*> mCache;
std::map<programid, std::unique_ptr<Program>> mCache;
const bool mHasES3;
}; // class ProgramCache

View File

@@ -870,7 +870,7 @@ void RenderNode::issueOperations(OpenGLRenderer& renderer, T& handler) {
return;
}
const bool drawLayer = (mLayer && (&renderer != mLayer->renderer));
const bool drawLayer = (mLayer && (&renderer != mLayer->renderer.get()));
// If we are updating the contents of mLayer, we don't want to apply any of
// the RenderNode's properties to this issueOperations pass. Those will all
// be applied when the layer is drawn, aka when this is true.

View File

@@ -39,8 +39,8 @@ struct Vertex {
float x, y;
static inline void set(Vertex* vertex, float x, float y) {
vertex[0].x = x;
vertex[0].y = y;
vertex->x = x;
vertex->y = y;
}
static inline void set(Vertex* vertex, Vector2 val) {

View File

@@ -47,14 +47,13 @@ CanvasContext::CanvasContext(RenderThread& thread, bool translucent,
, mOpaque(!translucent)
, mCanvas(NULL)
, mHaveNewSurface(false)
, mAnimationContext(contextFactory->createAnimationContext(mRenderThread.timeLord()))
, mRootRenderNode(rootRenderNode) {
mAnimationContext = contextFactory->createAnimationContext(mRenderThread.timeLord());
mRenderThread.renderState().registerCanvasContext(this);
}
CanvasContext::~CanvasContext() {
destroy();
delete mAnimationContext;
mRenderThread.renderState().unregisterCanvasContext(this);
}

View File

@@ -128,7 +128,7 @@ private:
OpenGLRenderer* mCanvas;
bool mHaveNewSurface;
DamageAccumulator mDamageAccumulator;
AnimationContext* mAnimationContext;
std::unique_ptr<AnimationContext> mAnimationContext;
const sp<RenderNode> mRootRenderNode;

View File

@@ -83,7 +83,7 @@ int main(int argc, char* argv[]) {
rootNode->setPropertyFieldsDirty(RenderNode::GENERIC);
ContextFactory factory;
RenderProxy* proxy = new RenderProxy(false, rootNode, &factory);
std::unique_ptr<RenderProxy> proxy(new RenderProxy(false, rootNode, &factory));
proxy->loadSystemProperties();
proxy->initialize(surface);
float lightX = width / 2.0;
@@ -123,7 +123,6 @@ int main(int argc, char* argv[]) {
sleep(5);
delete proxy;
rootNode->decStrong(0);
printf("Success!\n");