Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
A experiment to swtich to SF composition
Browse files Browse the repository at this point in the history
Change-Id: I5f76c30116bc9fd8695a3ce6882302a4dabc3fd2
Signed-off-by: Lin Johnson <[email protected]>
  • Loading branch information
js0701 committed May 14, 2019
1 parent e9ecf2d commit 936d086
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 27 deletions.
14 changes: 14 additions & 0 deletions common/compositor/compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@ void Compositor::SeparateLayers(const std::vector<size_t> &dedicated_layers,
const HwcRect<int> &damage_region,
std::vector<CompositionRegion> &comp_regions) {
CTRACE();

#if 1
// we just need to return layers with damage region into com_regions
size_t layer_index = 0;
for (auto &frame : display_frame) {
CompositionRegion comp;
comp.frame = frame;
comp.source_layers.emplace_back(layer_index);
comp_regions.emplace_back(comp);
layer_index++;
}
#else
if (source_layers.size() > 64) {
ETRACE("Failed to separate layers because there are more than 64");
return;
Expand Down Expand Up @@ -381,6 +394,7 @@ void Compositor::SeparateLayers(const std::vector<size_t> &dedicated_layers,
region.rect, SetBitsToVector(region.id_set.getBits() >> layer_offset,
source_layers)});
}
#endif
}

} // namespace hwcomposer
86 changes: 61 additions & 25 deletions common/compositor/gl/glprogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,23 @@ static std::string GenerateVertexShader(int layer_count) {
<< "#define LAYER_COUNT " << layer_count << "\n"
<< "precision mediump int;\n"
<< "uniform vec4 uViewport;\n"
<< "uniform vec4 uLayerCrop[LAYER_COUNT];\n"
<< "uniform mat2 uTexMatrix[LAYER_COUNT];\n"
<< "uniform vec4 uLayerCrop;\n"
<< "uniform mat2 uTexMatrix;\n"
<< "in vec2 vPosition;\n"
<< "in vec2 vTexCoords;\n"
<< "out vec2 fTexCoords[LAYER_COUNT];\n"
<< "out vec2 fTexCoords;\n"
<< "void main() {\n"
<< " for (int i = 0; i < LAYER_COUNT; i++) {\n"
<< " vec2 tempCoords = vTexCoords * uTexMatrix[i];\n"
<< " fTexCoords[i] =\n"
<< " uLayerCrop[i].xy + tempCoords * uLayerCrop[i].zw;\n"
<< " }\n"
<< " vec2 tempCoords = vTexCoords * uTexMatrix;\n"
<< " fTexCoords =\n"
<< " uLayerCrop.xy + tempCoords * uLayerCrop.zw;\n"
<< " vec2 scaledPosition = uViewport.xy + vPosition * uViewport.zw;\n"
<< " gl_Position =\n"
<< " vec4(scaledPosition * vec2(2.0) - vec2(1.0), 0.0, 1.0);\n"
<< "}\n";
return vertex_shader_stream.str();
}

#if 0
static std::string GenerateFragmentShader(int layer_count) {
std::ostringstream fragment_shader_stream;
fragment_shader_stream << "#version 300 es\n"
Expand All @@ -99,7 +98,7 @@ static std::string GenerateFragmentShader(int layer_count) {
<< "in vec2 fTexCoords[LAYER_COUNT];\n"
<< "out vec4 oFragColor;\n"
<< "void main() {\n"
<< " vec3 color = vec3(0.0, 0.0, 0.0);\n"
<< " vec3 color = gl_LastFragData[0].rgb;\n"
<< " float alphaCover = 1.0;\n"
<< " vec4 texSample;\n"
<< " vec3 multRgb;\n"
Expand Down Expand Up @@ -132,6 +131,43 @@ static std::string GenerateFragmentShader(int layer_count) {
return fragment_shader_stream.str();
}

#else
static std::string GenerateFragmentShader(int layer_count) {
std::ostringstream fragment_shader_stream;
fragment_shader_stream
<< "#version 300 es\n"
<< "#define LAYER_COUNT " << 1 << "\n"
<< "#extension GL_OES_EGL_image_external : require\n"
<< "#extension GL_EXT_shader_framebuffer_fetch : require\n" 
<< "precision mediump float;\n";
fragment_shader_stream << "uniform samplerExternalOES uLayerTexture;\n";

fragment_shader_stream << "uniform float uLayerAlpha;\n"
<< "uniform float uLayerPremult;\n"
<< "uniform vec4 uLayerColor;\n"
<< "in vec2 fTexCoords;\n"
<< "inout vec4 oFragColor;\n"
<< "void main() {\n"
<< " vec3 color = oFragColor.rgb;\n"
<< " float alphaCover = 1.0 - oFragColor.a;\n"
<< " vec4 texSample;\n"
<< " vec3 multRgb;\n"
<< " float tempAlpha;\n"
<< " if (alphaCover > 0.5/255.0) { \n";
// clang-format off
fragment_shader_stream << " texSample = texture2D(uLayerTexture, fTexCoords); \n"
<< " texSample.rgb = texSample.rgb + uLayerColor.rgb; \n"
<< " tempAlpha = min(texSample.a, uLayerColor.a); \n"
<< " multRgb = texSample.rgb *max(tempAlpha, uLayerPremult); \n"
<< " color += multRgb * uLayerAlpha * alphaCover; \n"
<< " alphaCover *= (1.0 - texSample.a - uLayerAlpha);\n"
<< " oFragColor = vec4(color, 1.0 - alphaCover);\n"
<< " }}\n";
return fragment_shader_stream.str();
}
#endif


#if defined(LOAD_PREBUILT_SHADER_FILE) || defined(USE_PREBUILT_SHADER_BIN_ARRAY)
static GLint LoadPreBuiltBinary(GLint gl_program, void *binary, long size) {
GLint status;
Expand Down Expand Up @@ -311,7 +347,7 @@ GLProgram::~GLProgram() {

bool GLProgram::Init(unsigned texture_count) {
std::ostringstream shader_log;
program_ = GenerateProgram(texture_count, &shader_log);
program_ = GenerateProgram(1, &shader_log);
if (!program_) {
ETRACE("%s", shader_log.str().c_str());
return false;
Expand All @@ -331,13 +367,13 @@ void GLProgram::UseProgram(const RenderState &state, GLuint viewport_width,
premult_loc_ = glGetUniformLocation(program_, "uLayerPremult");
tex_matrix_loc_ = glGetUniformLocation(program_, "uTexMatrix");
solid_color_loc_ = glGetUniformLocation(program_, "uLayerColor");
for (unsigned src_index = 0; src_index < size; src_index++) {
std::ostringstream texture_name_formatter;
texture_name_formatter << "uLayerTexture" << src_index;
GLuint tex_loc =
//for (unsigned src_index = 0; src_index < size; src_index++) {
std::ostringstream texture_name_formatter;
texture_name_formatter << "uLayerTexture";
GLuint tex_loc =
glGetUniformLocation(program_, texture_name_formatter.str().c_str());
glUniform1i(tex_loc, src_index);
}
glUniform1i(tex_loc, 0);
//}

initialized_ = true;
}
Expand All @@ -347,22 +383,22 @@ void GLProgram::UseProgram(const RenderState &state, GLuint viewport_width,
(state.width_) / (float)viewport_width,
(state.height_) / (float)viewport_height);

for (unsigned src_index = 0; src_index < size; src_index++) {
const RenderState::LayerState &src = state.layer_state_[src_index];
glUniform1f(alpha_loc_ + src_index, src.alpha_);
glUniform1f(premult_loc_ + src_index, src.premult_);
glUniform4f(crop_loc_ + src_index, src.crop_bounds_[0], src.crop_bounds_[1],
//for (unsigned src_index = 0; src_index < size; src_index++) {
const RenderState::LayerState &src = state.layer_state_[0];
glUniform1f(alpha_loc_, src.alpha_);
glUniform1f(premult_loc_, src.premult_);
glUniform4f(crop_loc_, src.crop_bounds_[0], src.crop_bounds_[1],
src.crop_bounds_[2] - src.crop_bounds_[0],
src.crop_bounds_[3] - src.crop_bounds_[1]);
glUniformMatrix2fv(tex_matrix_loc_ + src_index, 1, GL_FALSE,
glUniformMatrix2fv(tex_matrix_loc_, 1, GL_FALSE,
src.texture_matrix_);
glActiveTexture(GL_TEXTURE0 + src_index);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, src.handle_);
glUniform4f(solid_color_loc_ + src_index, (float)src.solid_color_array_[3],
glUniform4f(solid_color_loc_, (float)src.solid_color_array_[3],
(float)src.solid_color_array_[2],
(float)src.solid_color_array_[1],
(float)src.solid_color_array_[0]);
}
//}
}

} // namespace hwcomposer
3 changes: 2 additions & 1 deletion common/compositor/gl/glrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ bool GLRenderer::Draw(const std::vector<RenderState> &render_states,
surface->SetClearSurface(NativeSurface::kNone);

glViewport(left, top, frame_width, frame_height);
glClearColor(0.0, 0.0, 0.0, 1.0);

if (clear_surface || partial_clear) {
const HwcRect<int> &damage = surface->GetSurfaceDamage();
Expand Down Expand Up @@ -137,7 +138,7 @@ bool GLRenderer::Draw(const std::vector<RenderState> &render_states,
#endif
for (const RenderState &state : render_states) {
unsigned size = state.layer_state_.size();
GLProgram *program = GetProgram(size);
GLProgram *program = GetProgram(1);
if (!program)
continue;

Expand Down
2 changes: 1 addition & 1 deletion common/core/overlaylayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct OverlayLayer {
}

const HwcRect<int>& GetSurfaceDamage() const {
return surface_damage_;
return display_frame_;
}

HwcRect<int>& GetSurfaceDamage() {
Expand Down

0 comments on commit 936d086

Please sign in to comment.