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

Commit d2d06d7a authored by Vishnu Nair's avatar Vishnu Nair Committed by Android (Google) Code Review
Browse files

Merge changes from topic "remove_surface_size"

* changes:
  SF: User buffer size instead of layer size when calculating size
  SF: User buffer size to compute crop, set geometry and update cursor pos
parents 2df57354 88a11f26
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -59,8 +59,7 @@ static const int LAYER_BASE = INT32_MAX - 10;
class InputSurface {
public:
    InputSurface(const sp<SurfaceComposerClient>& scc, int width, int height) {
        mSurfaceControl = scc->createSurface(String8("Test Surface"),
                width, height, PIXEL_FORMAT_RGBA_8888,
        mSurfaceControl = scc->createSurface(String8("Test Surface"), 0, 0, PIXEL_FORMAT_RGBA_8888,
                                             ISurfaceComposerClient::eFXSurfaceColor);

        InputChannel::openInputChannelPair("testchannels", mServerChannel, mClientChannel);
+7 −5
Original line number Diff line number Diff line
@@ -501,7 +501,7 @@ Region BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime

    // FIXME: postedRegion should be dirty & bounds
    // transform the dirty region to window-manager space
    return getTransform().transform(Region(Rect(getActiveWidth(s), getActiveHeight(s))));
    return getTransform().transform(Region(getBufferSize(s)));
}

// transaction
@@ -624,11 +624,13 @@ void BufferLayer::drawWithOpenGL(const RenderArea& renderArea, bool useIdentityT

    ui::Transform t = getTransform();
    Rect win = bounds;
    const int bufferWidth = getBufferSize(s).getWidth();
    const int bufferHeight = getBufferSize(s).getHeight();

    float left = float(win.left) / float(getActiveWidth(s));
    float top = float(win.top) / float(getActiveHeight(s));
    float right = float(win.right) / float(getActiveWidth(s));
    float bottom = float(win.bottom) / float(getActiveHeight(s));
    const float left = float(win.left) / float(bufferWidth);
    const float top = float(win.top) / float(bufferHeight);
    const float right = float(win.right) / float(bufferWidth);
    const float bottom = float(win.bottom) / float(bufferHeight);

    // TODO: we probably want to generate the texture coords with the mesh
    // here we assume that we only have 4 vertices
+27 −49
Original line number Diff line number Diff line
@@ -367,27 +367,24 @@ Rect Layer::computeInitialCrop(const sp<const DisplayDevice>& display) const {
    // layerstack space, and convert-back to layer space.
    // if there are no window scaling involved, this operation will map to full
    // pixels in the buffer.
    // FIXME: the 3 lines below can produce slightly incorrect clipping when we have
    // a viewport clipping and a window transform. we should use floating point to fix this.

    Rect activeCrop(getActiveWidth(s), getActiveHeight(s));
    Rect crop = getCrop(s);
    if (!crop.isEmpty()) {
        activeCrop.intersect(crop, &activeCrop);
    }

    FloatRect activeCropFloat = computeBounds();
    ui::Transform t = getTransform();
    activeCrop = t.transform(activeCrop);
    if (!activeCrop.intersect(display->getViewport(), &activeCrop)) {
    // Transform to screen space.
    activeCropFloat = t.transform(activeCropFloat);
    activeCropFloat = activeCropFloat.intersect(display->getViewport().toFloatRect());
    // Back to layer space to work with the content crop.
    activeCropFloat = t.inverse().transform(activeCropFloat);
    // This needs to be here as transform.transform(Rect) computes the
    // transformed rect and then takes the bounding box of the result before
    // returning. This means
    // transform.inverse().transform(transform.transform(Rect)) != Rect
    // in which case we need to make sure the final rect is clipped to the
    // display bounds.
    Rect activeCrop{activeCropFloat};
    if (!activeCrop.intersect(getBufferSize(s), &activeCrop)) {
        activeCrop.clear();
    }

    const auto& p = mDrawingParent.promote();
    if (p != nullptr) {
        auto parentCrop = p->computeInitialCrop(display);
        activeCrop.intersect(parentCrop, &activeCrop);
    }

    return activeCrop;
}

@@ -399,24 +396,8 @@ FloatRect Layer::computeCrop(const sp<const DisplayDevice>& display) const {
    // In addition there is a WM-specified crop we pull from our drawing state.
    const State& s(getDrawingState());

    // Screen space to make reduction to parent crop clearer.
    Rect activeCrop = computeInitialCrop(display);
    ui::Transform t = getTransform();
    // Back to layer space to work with the content crop.
    activeCrop = t.inverse().transform(activeCrop);

    // This needs to be here as transform.transform(Rect) computes the
    // transformed rect and then takes the bounding box of the result before
    // returning. This means
    // transform.inverse().transform(transform.transform(Rect)) != Rect
    // in which case we need to make sure the final rect is clipped to the
    // display bounds.
    if (!activeCrop.intersect(Rect(getActiveWidth(s), getActiveHeight(s)), &activeCrop)) {
        activeCrop.clear();
    }

    // subtract the transparent region and snap to the bounds
    activeCrop = reduce(activeCrop, getActiveTransparentRegion(s));
    Rect bufferSize = getBufferSize(s);

    // Transform the window crop to match the buffer coordinate system,
    // which means using the inverse of the current transform set on the
@@ -437,8 +418,8 @@ FloatRect Layer::computeCrop(const sp<const DisplayDevice>& display) const {
                        ui::Transform(invTransform)).getOrientation();
    }

    int winWidth = getActiveWidth(s);
    int winHeight = getActiveHeight(s);
    int winWidth = bufferSize.getWidth();
    int winHeight = bufferSize.getHeight();
    if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
        // If the activeCrop has been rotate the ends are rotated but not
        // the space itself so when transforming ends back we can't rely on
@@ -450,10 +431,10 @@ FloatRect Layer::computeCrop(const sp<const DisplayDevice>& display) const {
        if (is_h_flipped == is_v_flipped) {
            invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
        }
        winWidth = getActiveHeight(s);
        winHeight = getActiveWidth(s);
        std::swap(winWidth, winHeight);
    }
    const Rect winCrop = activeCrop.transform(invTransform, getActiveWidth(s), getActiveHeight(s));
    const Rect winCrop =
            activeCrop.transform(invTransform, bufferSize.getWidth(), bufferSize.getHeight());

    // below, crop is intersected with winCrop expressed in crop's coordinate space
    float xScale = crop.getWidth() / float(winWidth);
@@ -489,6 +470,8 @@ void Layer::setGeometry(const sp<const DisplayDevice>& display, uint32_t z) {

    // this gives us only the "orientation" component of the transform
    const State& s(getDrawingState());
    const int bufferWidth = getBufferSize(s).getWidth();
    const int bufferHeight = getBufferSize(s).getHeight();
    auto blendMode = HWC2::BlendMode::None;
    if (!isOpaque(s) || getAlpha() != 1.0f) {
        blendMode =
@@ -519,16 +502,15 @@ void Layer::setGeometry(const sp<const DisplayDevice>& display, uint32_t z) {
        // transform.inverse().transform(transform.transform(Rect)) != Rect
        // in which case we need to make sure the final rect is clipped to the
        // display bounds.
        if (!activeCrop.intersect(Rect(getActiveWidth(s), getActiveHeight(s)), &activeCrop)) {
        if (!activeCrop.intersect(Rect(bufferWidth, bufferHeight), &activeCrop)) {
            activeCrop.clear();
        }
        // mark regions outside the crop as transparent
        activeTransparentRegion.orSelf(Rect(0, 0, getActiveWidth(s), activeCrop.top));
        activeTransparentRegion.orSelf(
                Rect(0, activeCrop.bottom, getActiveWidth(s), getActiveHeight(s)));
        activeTransparentRegion.orSelf(Rect(0, 0, bufferWidth, activeCrop.top));
        activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, bufferWidth, bufferHeight));
        activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom));
        activeTransparentRegion.orSelf(
                Rect(activeCrop.right, activeCrop.top, getActiveWidth(s), activeCrop.bottom));
                Rect(activeCrop.right, activeCrop.top, bufferWidth, activeCrop.bottom));
    }

    // computeBounds returns a FloatRect to provide more accuracy during the
@@ -664,11 +646,7 @@ void Layer::updateCursorPosition(const sp<const DisplayDevice>& display) {

    // Apply the layer's transform, followed by the display's global transform
    // Here we're guaranteed that the layer's transform preserves rects
    Rect win(getActiveWidth(s), getActiveHeight(s));
    Rect crop = getCrop(s);
    if (!crop.isEmpty()) {
        win.intersect(crop, &win);
    }
    Rect win = getCroppedBufferSize(s);
    // Subtract the transparent region and snap to the bounds
    Rect bounds = reduce(win, getActiveTransparentRegion(s));
    Rect frame(getTransform().transform(bounds));
+6 −6
Original line number Diff line number Diff line
@@ -596,6 +596,12 @@ public:
    int32_t getZ() const;
    virtual void pushPendingState();

    /**
     * Returns active buffer size in the correct orientation. Buffer size is determined by undoing
     * any buffer transformations. If the layer has no buffer then return INVALID_RECT.
     */
    virtual Rect getBufferSize(const Layer::State&) const { return Rect::INVALID_RECT; }

protected:
    // constant
    sp<SurfaceFlinger> mFlinger;
@@ -819,12 +825,6 @@ private:
     * bounds are constrained by its parent bounds.
     */
    Rect getCroppedBufferSize(const Layer::State& s) const;

    /**
     * Returns active buffer size in the correct orientation. Buffer size is determined by undoing
     * any buffer transformations. If the layer has no buffer then return INVALID_RECT.
     */
    virtual Rect getBufferSize(const Layer::State&) const { return Rect::INVALID_RECT; }
};

} // namespace android
+20 −5
Original line number Diff line number Diff line
@@ -3707,11 +3707,24 @@ status_t SurfaceFlinger::createLayer(
            result = createBufferStateLayer(client, uniqueName, w, h, flags, handle, &layer);
            break;
        case ISurfaceComposerClient::eFXSurfaceColor:
            // check if buffer size is set for color layer.
            if (w > 0 || h > 0) {
                ALOGE("createLayer() failed, w or h cannot be set for color layer (w=%d, h=%d)",
                      int(w), int(h));
                return BAD_VALUE;
            }

            result = createColorLayer(client,
                    uniqueName, w, h, flags,
                    handle, &layer);
            break;
        case ISurfaceComposerClient::eFXSurfaceContainer:
            // check if buffer size is set for container layer.
            if (w > 0 || h > 0) {
                ALOGE("createLayer() failed, w or h cannot be set for container layer (w=%d, h=%d)",
                      int(w), int(h));
                return BAD_VALUE;
            }
            result = createContainerLayer(client,
                    uniqueName, w, h, flags,
                    handle, &layer);
@@ -5161,12 +5174,14 @@ status_t SurfaceFlinger::captureLayers(const sp<IBinder>& layerHandleBinder,
        const ui::Transform& getTransform() const override { return mTransform; }
        Rect getBounds() const override {
            const Layer::State& layerState(mLayer->getDrawingState());
            return Rect(mLayer->getActiveWidth(layerState), mLayer->getActiveHeight(layerState));
            return mLayer->getBufferSize(layerState);
        }
        int getHeight() const override {
            return mLayer->getActiveHeight(mLayer->getDrawingState());
            return mLayer->getBufferSize(mLayer->getDrawingState()).getHeight();
        }
        int getWidth() const override {
            return mLayer->getBufferSize(mLayer->getDrawingState()).getWidth();
        }
        int getWidth() const override { return mLayer->getActiveWidth(mLayer->getDrawingState()); }
        bool isSecure() const override { return false; }
        bool needsFiltering() const override { return mNeedsFiltering; }
        Rect getSourceCrop() const override {
@@ -5240,12 +5255,12 @@ status_t SurfaceFlinger::captureLayers(const sp<IBinder>& layerHandleBinder,
    Rect crop(sourceCrop);
    if (sourceCrop.width() <= 0) {
        crop.left = 0;
        crop.right = parent->getActiveWidth(parent->getCurrentState());
        crop.right = parent->getBufferSize(parent->getCurrentState()).getWidth();
    }

    if (sourceCrop.height() <= 0) {
        crop.top = 0;
        crop.bottom = parent->getActiveHeight(parent->getCurrentState());
        crop.bottom = parent->getBufferSize(parent->getCurrentState()).getHeight();
    }

    int32_t reqWidth = crop.width() * frameScale;
Loading