Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d41f40a4 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Stop worker threads on memory trim & fix bad pointer access" into jb-mr2-dev

parents 71b00177 c5cbee7d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -310,6 +310,7 @@ void Caches::flush(FlushMode mode) {
            fontRenderer->flush();
            textureCache.flush();
            pathCache.clear();
            tasks.stop();
            // fall through
        case kFlushMode_Layers:
            layerCache.clear();
+4 −3
Original line number Diff line number Diff line
@@ -347,14 +347,15 @@ void PathCache::PathProcessor::onProcess(const sp<Task<SkBitmap*> >& task) {
// Paths
///////////////////////////////////////////////////////////////////////////////

void PathCache::remove(SkPath* path) {
void PathCache::remove(const path_pair_t& pair) {
    Vector<PathDescription> pathsToRemove;
    LruCache<PathDescription, PathTexture*>::Iterator i(mCache);

    while (i.next()) {
        const PathDescription& key = i.key();
        if (key.type == kShapePath &&
                (key.shape.path.mPath == path || key.shape.path.mPath == path->getSourcePath())) {
                (key.shape.path.mPath == pair.getFirst() ||
                        key.shape.path.mPath == pair.getSecond())) {
            pathsToRemove.push(key);
        }
    }
@@ -366,7 +367,7 @@ void PathCache::remove(SkPath* path) {

void PathCache::removeDeferred(SkPath* path) {
    Mutex::Autolock l(mLock);
    mGarbage.push(path);
    mGarbage.push(path_pair_t(path, const_cast<SkPath*>(path->getSourcePath())));
}

void PathCache::clearGarbage() {
+11 −5
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include "Debug.h"
#include "Properties.h"
#include "Texture.h"
#include "utils/Pair.h"

class SkBitmap;
class SkCanvas;
@@ -214,10 +215,6 @@ public:
            bool useCenter, SkPaint* paint);
    PathTexture* get(SkPath* path, SkPaint* paint);

    /**
     * Removes an entry.
     */
    void remove(SkPath* path);
    /**
     * Removes the specified path. This is meant to be called from threads
     * that are not the EGL context thread.
@@ -251,6 +248,8 @@ public:
            float& left, float& top, float& offset, uint32_t& width, uint32_t& height);

private:
    typedef Pair<SkPath*, SkPath*> path_pair_t;

    PathTexture* addTexture(const PathDescription& entry,
            const SkPath *path, const SkPaint* paint);
    PathTexture* addTexture(const PathDescription& entry, SkBitmap* bitmap);
@@ -260,6 +259,12 @@ private:
        return mCache.get(entry);
    }

    /**
     * Removes an entry.
     * The pair must define first=path, second=sourcePath
     */
    void remove(const path_pair_t& pair);

    /**
     * Ensures there is enough space in the cache for a texture of the specified
     * dimensions.
@@ -318,7 +323,8 @@ private:
    bool mDebugEnabled;

    sp<PathProcessor> mProcessor;
    Vector<SkPath*> mGarbage;

    Vector<path_pair_t> mGarbage;
    mutable Mutex mLock;
}; // class PathCache

+6 −0
Original line number Diff line number Diff line
@@ -48,6 +48,12 @@ bool TaskManager::canRunTasks() const {
    return mThreads.size() > 0;
}

void TaskManager::stop() {
    for (size_t i = 0; i < mThreads.size(); i++) {
        mThreads[i]->exit();
    }
}

bool TaskManager::addTaskBase(const sp<TaskBase>& task, const sp<TaskProcessorBase>& processor) {
    if (mThreads.size() > 0) {
        TaskWrapper wrapper(task, processor);
+6 −0
Original line number Diff line number Diff line
@@ -47,6 +47,12 @@ public:
     */
    bool canRunTasks() const;

    /**
     * Stops all allocated threads. Adding tasks will start
     * the threads again as necessary.
     */
    void stop();

private:
    template <typename T>
    friend class TaskProcessor;
Loading