Skip to content

Commit

Permalink
graphics: correctly pass layer alpha level through
Browse files Browse the repository at this point in the history
  • Loading branch information
morphis committed May 18, 2018
1 parent 238a26a commit 1037e8a
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 25 deletions.
1 change: 1 addition & 0 deletions android/hwcomposer/hwcomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ static int hwc_set(hwc_composer_device_1_t* dev, size_t numDisplays,
rcEnc->rcPostLayer(rcEnc,
layer->name,
cb->hostHandle,
layer->planeAlpha / 255,
layer->sourceCrop.left,
layer->sourceCrop.top,
layer->sourceCrop.right,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef int (renderControl_APIENTRY *rcGetDisplayHeight_client_proc_t) (void * c
typedef int (renderControl_APIENTRY *rcGetDisplayDpiX_client_proc_t) (void * ctx, uint32_t);
typedef int (renderControl_APIENTRY *rcGetDisplayDpiY_client_proc_t) (void * ctx, uint32_t);
typedef int (renderControl_APIENTRY *rcGetDisplayVsyncPeriod_client_proc_t) (void * ctx, uint32_t);
typedef void (renderControl_APIENTRY *rcPostLayer_client_proc_t) (void * ctx, const char*, uint32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t);
typedef void (renderControl_APIENTRY *rcPostLayer_client_proc_t) (void * ctx, const char*, uint32_t, float, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t);
typedef void (renderControl_APIENTRY *rcPostAllLayersDone_client_proc_t) (void * ctx);


Expand Down
5 changes: 3 additions & 2 deletions android/opengl/system/renderControl_enc/renderControl_enc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ int rcGetDisplayVsyncPeriod_enc(void *self , uint32_t displayId)
return retval;
}

void rcPostLayer_enc(void *self , const char* name, uint32_t colorBuffer, int32_t sourceCropLeft, int32_t sourceCropTop, int32_t sourceCropRight, int32_t sourceCropBottom, int32_t displayFrameLeft, int32_t displayFrameTop, int32_t displayFrameRight, int32_t displayFrameBottom)
void rcPostLayer_enc(void *self , const char* name, uint32_t colorBuffer, float alpha, int32_t sourceCropLeft, int32_t sourceCropTop, int32_t sourceCropRight, int32_t sourceCropBottom, int32_t displayFrameLeft, int32_t displayFrameTop, int32_t displayFrameRight, int32_t displayFrameBottom)
{

renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self;
Expand All @@ -1294,7 +1294,7 @@ void rcPostLayer_enc(void *self , const char* name, uint32_t colorBuffer, int32_
const unsigned int __size_name = (strlen(name) + 1);
unsigned char *ptr;
unsigned char *buf;
const size_t sizeWithoutChecksum = 8 + __size_name + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 1*4;
const size_t sizeWithoutChecksum = 8 + __size_name + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 1*4;
const size_t checksumSize = checksumCalculator->checksumByteSize();
const size_t totalSize = sizeWithoutChecksum + checksumSize;
buf = stream->alloc(totalSize);
Expand All @@ -1305,6 +1305,7 @@ void rcPostLayer_enc(void *self , const char* name, uint32_t colorBuffer, int32_
*(unsigned int *)(ptr) = __size_name; ptr += 4;
memcpy(ptr, name, __size_name);ptr += __size_name;
memcpy(ptr, &colorBuffer, 4); ptr += 4;
memcpy(ptr, &alpha, 4); ptr += 4;
memcpy(ptr, &sourceCropLeft, 4); ptr += 4;
memcpy(ptr, &sourceCropTop, 4); ptr += 4;
memcpy(ptr, &sourceCropRight, 4); ptr += 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {
int rcGetDisplayDpiX(uint32_t displayId);
int rcGetDisplayDpiY(uint32_t displayId);
int rcGetDisplayVsyncPeriod(uint32_t displayId);
void rcPostLayer(const char* name, uint32_t colorBuffer, int32_t sourceCropLeft, int32_t sourceCropTop, int32_t sourceCropRight, int32_t sourceCropBottom, int32_t displayFrameLeft, int32_t displayFrameTop, int32_t displayFrameRight, int32_t displayFrameBottom);
void rcPostLayer(const char* name, uint32_t colorBuffer, float alpha, int32_t sourceCropLeft, int32_t sourceCropTop, int32_t sourceCropRight, int32_t sourceCropBottom, int32_t displayFrameLeft, int32_t displayFrameTop, int32_t displayFrameRight, int32_t displayFrameBottom);
void rcPostAllLayersDone();
};

Expand Down Expand Up @@ -262,10 +262,10 @@ int rcGetDisplayVsyncPeriod(uint32_t displayId)
return ctx->rcGetDisplayVsyncPeriod(ctx, displayId);
}

void rcPostLayer(const char* name, uint32_t colorBuffer, int32_t sourceCropLeft, int32_t sourceCropTop, int32_t sourceCropRight, int32_t sourceCropBottom, int32_t displayFrameLeft, int32_t displayFrameTop, int32_t displayFrameRight, int32_t displayFrameBottom)
void rcPostLayer(const char* name, uint32_t colorBuffer, float alpha, int32_t sourceCropLeft, int32_t sourceCropTop, int32_t sourceCropRight, int32_t sourceCropBottom, int32_t displayFrameLeft, int32_t displayFrameTop, int32_t displayFrameRight, int32_t displayFrameBottom)
{
GET_CONTEXT;
ctx->rcPostLayer(ctx, name, colorBuffer, sourceCropLeft, sourceCropTop, sourceCropRight, sourceCropBottom, displayFrameLeft, displayFrameTop, displayFrameRight, displayFrameBottom);
ctx->rcPostLayer(ctx, name, colorBuffer, alpha, sourceCropLeft, sourceCropTop, sourceCropRight, sourceCropBottom, displayFrameLeft, displayFrameTop, displayFrameRight, displayFrameBottom);
}

void rcPostAllLayersDone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ GL_ENTRY(int, rcGetDisplayHeight, uint32_t displayId)
GL_ENTRY(int, rcGetDisplayDpiX, uint32_t displayId)
GL_ENTRY(int, rcGetDisplayDpiY, uint32_t displayId)
GL_ENTRY(int, rcGetDisplayVsyncPeriod, uint32_t displayId)
GL_ENTRY(void, rcPostLayer, const char* name, uint32_t colorBuffer, int32_t sourceCropLeft, int32_t sourceCropTop, int32_t sourceCropRight, int32_t sourceCropBottom, int32_t displayFrameLeft, int32_t displayFrameTop, int32_t displayFrameRight, int32_t displayFrameBottom)
GL_ENTRY(void, rcPostLayer, const char* name, uint32_t colorBuffer, float alpha, int32_t sourceCropLeft, int32_t sourceCropTop, int32_t sourceCropRight, int32_t sourceCropBottom, int32_t displayFrameLeft, int32_t displayFrameTop, int32_t displayFrameRight, int32_t displayFrameBottom)
GL_ENTRY(void, rcPostAllLayersDone)
3 changes: 2 additions & 1 deletion src/anbox/graphics/emugl/RenderControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,15 @@ bool is_layer_blacklisted(const std::string &name) {
return std::find(blacklist.begin(), blacklist.end(), name) != blacklist.end();
}

void rcPostLayer(const char *name, uint32_t color_buffer,
void rcPostLayer(const char *name, uint32_t color_buffer, float alpha,
int32_t sourceCropLeft, int32_t sourceCropTop,
int32_t sourceCropRight, int32_t sourceCropBottom,
int32_t displayFrameLeft, int32_t displayFrameTop,
int32_t displayFrameRight, int32_t displayFrameBottom) {
Renderable r{
name,
color_buffer,
alpha,
{displayFrameLeft, displayFrameTop, displayFrameRight, displayFrameBottom},
{sourceCropLeft, sourceCropTop, sourceCropRight, sourceCropBottom}};
frame_layers.push_back(r);
Expand Down
4 changes: 2 additions & 2 deletions src/anbox/graphics/emugl/Renderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

#include "anbox/graphics/emugl/Renderable.h"

Renderable::Renderable(const std::string &name, const std::uint32_t &buffer,
Renderable::Renderable(const std::string &name, const std::uint32_t &buffer, float alpha,
const anbox::graphics::Rect &screen_position,
const anbox::graphics::Rect &crop,
const glm::mat4 &transformation, const float &alpha)
const glm::mat4 &transformation)
: name_(name),
buffer_(buffer),
screen_position_(screen_position),
Expand Down
4 changes: 2 additions & 2 deletions src/anbox/graphics/emugl/Renderable.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

class Renderable {
public:
Renderable(const std::string &name, const std::uint32_t &buffer,
Renderable(const std::string &name, const std::uint32_t &buffer, float alpha,
const anbox::graphics::Rect &screen_position,
const anbox::graphics::Rect &crop = {},
const glm::mat4 &transformation = {}, const float &alpha = 1.0f);
const glm::mat4 &transformation = {});
~Renderable();

std::string name() const;
Expand Down
26 changes: 13 additions & 13 deletions tests/anbox/graphics/layer_composer_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TEST(LayerComposer, FindsNoSuitableWindowForLayer) {
// A single renderable which has a different task id then the window we know
// about
RenderableList renderables = {
{"org.anbox.surface.2", 0, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
{"org.anbox.surface.2", 0, 1.0f, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
};

// The renderer should not be called for a layer which doesn't exist
Expand Down Expand Up @@ -108,16 +108,16 @@ TEST(LayerComposer, MapsLayersToWindows) {
// A single renderable which has a different task id then the window we know
// about
RenderableList renderables = {
{"org.anbox.surface.1", 0, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
{"org.anbox.surface.2", 1, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
{"org.anbox.surface.1", 0, 1.0f, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
{"org.anbox.surface.2", 1, 1.0f, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
};

RenderableList first_window_renderables{
{"org.anbox.surface.1", 0, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
{"org.anbox.surface.1", 0, 1.0f, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
};

RenderableList second_window_renderables{
{"org.anbox.surface.2", 1, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
{"org.anbox.surface.2", 1, 1.0f, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
};

EXPECT_CALL(*renderer, draw(_, Rect{0, 0, first_window.frame().width(),
Expand Down Expand Up @@ -160,13 +160,13 @@ TEST(LayerComposer, WindowPartiallyOffscreen) {
// but the layer covering the whole window is placed with its top left
// origin outside of the visible display area.
RenderableList renderables = {
{"org.anbox.surface.1", 0, {-100, -100, 924, 668}, {0, 0, 1024, 768}},
{"org.anbox.surface.1", 1, {0, 0, 100, 200}, {0, 0, 100, 200}},
{"org.anbox.surface.1", 0, 1.0f, {-100, -100, 924, 668}, {0, 0, 1024, 768}},
{"org.anbox.surface.1", 1, 1.0f, {0, 0, 100, 200}, {0, 0, 100, 200}},
};

RenderableList expected_renderables{
{"org.anbox.surface.1", 0, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
{"org.anbox.surface.1", 1, {100, 100, 200, 300}, {0, 0, 100, 200}},
{"org.anbox.surface.1", 0, 1.0f, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
{"org.anbox.surface.1", 1, 1.0f, {100, 100, 200, 300}, {0, 0, 100, 200}},
};

EXPECT_CALL(*renderer, draw(_, Rect{0, 0,
Expand Down Expand Up @@ -208,13 +208,13 @@ TEST(LayerComposer, PopupShouldNotCauseWindowLayerOffset) {
// out of the window area. In our case this is not possible as the area the
// window has available is static.
RenderableList renderables = {
{"org.anbox.surface.3", 0, {1120,270,2144,1038}, {0, 0, 1024, 768}},
{"org.anbox.surface.3", 1, {1904, 246, 2164, 406}, {0, 0, 260, 160}},
{"org.anbox.surface.3", 0, 1.0f, {1120,270,2144,1038}, {0, 0, 1024, 768}},
{"org.anbox.surface.3", 1, 1.0f, {1904, 246, 2164, 406}, {0, 0, 260, 160}},
};

RenderableList expected_renderables{
{"org.anbox.surface.3", 0, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
{"org.anbox.surface.3", 1, {784, -24, 1044, 136}, {0, 0, 260, 160}},
{"org.anbox.surface.3", 0, 1.0f, {0, 0, 1024, 768}, {0, 0, 1024, 768}},
{"org.anbox.surface.3", 1, 1.0f, {784, -24, 1044, 136}, {0, 0, 260, 160}},
};

EXPECT_CALL(*renderer, draw(_, Rect{0, 0,
Expand Down

0 comments on commit 1037e8a

Please sign in to comment.