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

Commit 69d62097 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

cleanup, remove unused fields. Also make sure that we don't systematically...

cleanup, remove unused fields. Also make sure that we don't systematically allocate a Surface in Surface.java if only a SurfaceControl is needed (Common case).
parent 17f638b3
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -145,8 +145,27 @@ static void setSurfaceControl(JNIEnv* env, jobject clazz,

static sp<Surface> getSurface(JNIEnv* env, jobject clazz)
{
    Surface* const p = (Surface*)env->GetIntField(clazz, so.surface);
    return sp<Surface>(p);
    sp<Surface> result((Surface*)env->GetIntField(clazz, so.surface));
    if (result == 0) {
        /*
         * if this method is called from the WindowManager's process, it means
         * the client is is not remote, and therefore is allowed to have
         * a Surface (data), so we create it here. 
         * If we don't have a SurfaceControl, it means we're in a different
         * process.
         */
        
        SurfaceControl* const control = 
            (SurfaceControl*)env->GetIntField(clazz, so.surfaceControl);
        if (control) {
            result = control->getSurface();
            if (result != 0) {
                result->incStrong(clazz);
                env->SetIntField(clazz, so.surface, (int)result.get());
            }
        }
    }
    return result;
}

static void setSurface(JNIEnv* env, jobject clazz, const sp<Surface>& surface)
@@ -510,7 +529,6 @@ static void Surface_copyFrom(
     * This is used by the WindowManagerService just after constructing
     * a Surface and is necessary for returning the Surface reference to
     * the caller. At this point, we should only have a SurfaceControl.
     * 
     */
    
    const sp<SurfaceControl>& surface = getSurfaceControl(env, clazz);
@@ -519,7 +537,6 @@ static void Surface_copyFrom(
        // we reassign the surface only if it's a different one
        // otherwise we would loose our client-side state.
        setSurfaceControl(env, clazz, rhs);
        setSurface(env, clazz, rhs->getSurface());
    }
}

+1 −4
Original line number Diff line number Diff line
@@ -138,8 +138,7 @@ private:
            const sp<SurfaceComposerClient>& client,
            const sp<ISurface>& surface,
            const ISurfaceFlingerClient::surface_data_t& data,
            uint32_t w, uint32_t h, PixelFormat format, uint32_t flags,
            bool owner = true);
            uint32_t w, uint32_t h, PixelFormat format, uint32_t flags);

    ~SurfaceControl();

@@ -152,7 +151,6 @@ private:
    uint32_t                    mIdentity;
    PixelFormat                 mFormat;
    uint32_t                    mFlags;
    const bool                  mOwner;
    mutable Mutex               mLock;
    
    mutable sp<Surface>         mSurfaceData;
@@ -252,7 +250,6 @@ private:
    uint32_t                    mIdentity;
    PixelFormat                 mFormat;
    uint32_t                    mFlags;
    const bool                  mOwner;
    mutable Region              mDirtyRegion;
    mutable Rect                mSwapRectangle;
    mutable uint8_t             mBackbufferIndex;
+5 −10
Original line number Diff line number Diff line
@@ -152,13 +152,13 @@ SurfaceControl::SurfaceControl(
        const sp<SurfaceComposerClient>& client, 
        const sp<ISurface>& surface,
        const ISurfaceFlingerClient::surface_data_t& data,
        uint32_t w, uint32_t h, PixelFormat format, uint32_t flags,
        bool owner)
        uint32_t w, uint32_t h, PixelFormat format, uint32_t flags)
    : mClient(client), mSurface(surface),
      mToken(data.token), mIdentity(data.identity),
      mFormat(format), mFlags(flags), mOwner(owner)
      mFormat(format), mFlags(flags)
{
}
        
SurfaceControl::~SurfaceControl()
{
    destroy();
@@ -166,10 +166,7 @@ SurfaceControl::~SurfaceControl()

void SurfaceControl::destroy()
{
    // Destroy the surface in SurfaceFlinger if we were the owner
    // (in any case, a client won't be able to, because it won't have the
    // right permission).
    if (mOwner && mToken>=0 && mClient!=0) {
    if (isValid()) {
        mClient->destroySurface(mToken);
    }

@@ -351,14 +348,12 @@ sp<Surface> SurfaceControl::getSurface() const
Surface::Surface(const sp<SurfaceControl>& surface)
    : mClient(surface->mClient), mSurface(surface->mSurface),
      mToken(surface->mToken), mIdentity(surface->mIdentity),
      mFormat(surface->mFormat), mFlags(surface->mFlags),
      mOwner(surface->mOwner)
      mFormat(surface->mFormat), mFlags(surface->mFlags)
{
    init();
}

Surface::Surface(const Parcel& parcel)
    : mOwner(false)
{
    sp<IBinder> clientBinder = parcel.readStrongBinder();
    mSurface    = interface_cast<ISurface>(parcel.readStrongBinder());