diff --git a/common/compositor/compositor.cpp b/common/compositor/compositor.cpp index 4a2d812d7..84dfd6f1d 100644 --- a/common/compositor/compositor.cpp +++ b/common/compositor/compositor.cpp @@ -312,10 +312,25 @@ static std::vector SetBitsToVector( void Compositor::SeparateLayers(const std::vector &dedicated_layers, const std::vector &source_layers, - const std::vector> &display_frame, + const std::vector> &display_frames, const HwcRect &damage_region, std::vector &comp_regions) { CTRACE(); + +#if 1 + // we just need to return layers with damage region into com_regions + int index = 0; + while (index < source_layers.size()) { + CompositionRegion comp; + size_t layer_index = source_layers.at(index); + comp.frame = display_frames.at(layer_index); + comp.source_layers.emplace_back(layer_index); + index++; + comp_regions.emplace_back(comp); + } +#else + // legacy seprate layers logic + if (source_layers.size() > 64) { ETRACE("Failed to separate layers because there are more than 64"); return; @@ -381,6 +396,7 @@ void Compositor::SeparateLayers(const std::vector &dedicated_layers, region.rect, SetBitsToVector(region.id_set.getBits() >> layer_offset, source_layers)}); } +#endif } } // namespace hwcomposer diff --git a/common/compositor/gl/egloffscreencontext.cpp b/common/compositor/gl/egloffscreencontext.cpp index 5bbd6e1c5..f46c5f991 100644 --- a/common/compositor/gl/egloffscreencontext.cpp +++ b/common/compositor/gl/egloffscreencontext.cpp @@ -87,23 +87,27 @@ bool EGLOffScreenContext::MakeCurrent() { return true; } -EGLint EGLOffScreenContext::GetSyncFD() { +EGLint EGLOffScreenContext::GetSyncFD(bool onScreen) { EGLint sync_fd = -1; - EGLSyncKHR egl_sync = - eglCreateSyncKHR(egl_display_, EGL_SYNC_NATIVE_FENCE_ANDROID, NULL); - if (egl_sync == EGL_NO_SYNC_KHR) { - ETRACE("Failed to make sync object."); - return -1; - } + if (onScreen) + glFlush(); + else { + EGLSyncKHR egl_sync = + eglCreateSyncKHR(egl_display_, EGL_SYNC_NATIVE_FENCE_ANDROID, NULL); + if (egl_sync == EGL_NO_SYNC_KHR) { + ETRACE("Failed to make sync object."); + return -1; + } - sync_fd = eglDupNativeFenceFDANDROID(egl_display_, egl_sync); - if (sync_fd == EGL_NO_NATIVE_FENCE_FD_ANDROID) { - ETRACE("Failed to duplicate native fence object."); - sync_fd = -1; - } + sync_fd = eglDupNativeFenceFDANDROID(egl_display_, egl_sync); + if (sync_fd == EGL_NO_NATIVE_FENCE_FD_ANDROID) { + ETRACE("Failed to duplicate native fence object."); + sync_fd = -1; + } - eglDestroySyncKHR(egl_display_, egl_sync); + eglDestroySyncKHR(egl_display_, egl_sync); + } return sync_fd; } diff --git a/common/compositor/gl/egloffscreencontext.h b/common/compositor/gl/egloffscreencontext.h index 464a32145..7ad1d3ce2 100644 --- a/common/compositor/gl/egloffscreencontext.h +++ b/common/compositor/gl/egloffscreencontext.h @@ -28,7 +28,7 @@ class EGLOffScreenContext { bool Init(); - EGLint GetSyncFD(); + EGLint GetSyncFD(bool onScreen); EGLDisplay GetDisplay() const { return egl_display_; diff --git a/common/compositor/gl/glprogram.cpp b/common/compositor/gl/glprogram.cpp index db30446e5..4ee976c9a 100644 --- a/common/compositor/gl/glprogram.cpp +++ b/common/compositor/gl/glprogram.cpp @@ -65,17 +65,15 @@ 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" @@ -85,53 +83,39 @@ static std::string GenerateVertexShader(int layer_count) { static std::string GenerateFragmentShader(int layer_count) { std::ostringstream fragment_shader_stream; - fragment_shader_stream << "#version 300 es\n" - << "#define LAYER_COUNT " << layer_count << "\n" - << "#extension GL_OES_EGL_image_external : require\n" - << "precision mediump float;\n"; - for (int i = 0; i < layer_count; ++i) { - fragment_shader_stream << "uniform samplerExternalOES uLayerTexture" << i - << ";\n"; - } - fragment_shader_stream << "uniform float uLayerAlpha[LAYER_COUNT];\n" - << "uniform float uLayerPremult[LAYER_COUNT];\n" - << "uniform vec4 uLayerColor[LAYER_COUNT];\n" - << "in vec2 fTexCoords[LAYER_COUNT];\n" - << "out vec4 oFragColor;\n" + 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 = vec3(0.0, 0.0, 0.0);\n" - << " float alphaCover = 1.0;\n" + << " vec3 color = oFragColor.rgb;\n" + << " float alphaCover = 1.0 - oFragColor.a;\n" << " vec4 texSample;\n" << " vec3 multRgb;\n" - << " float tempAlpha;\n"; - for (int i = 0; i < layer_count; ++i) { - if (i > 0) - fragment_shader_stream << " if (alphaCover > 0.5/255.0) {\n"; - // clang-format off - fragment_shader_stream << " texSample = texture2D(uLayerTexture" << i - << ",\n" - << " fTexCoords[" << i - << "]);\n" - << " texSample.rgb = texSample.rgb + uLayerColor[" << i - << "].rgb;\n" - << " tempAlpha = min(texSample.a, uLayerColor[" << i - << "].a);\n" - << " multRgb = texSample.rgb *\n" - << " max(tempAlpha, uLayerPremult[" << i - << "]);\n" - << " color += multRgb * uLayerAlpha[" << i - << "] * alphaCover;\n" - << " alphaCover *= 1.0 - texSample.a * uLayerAlpha[" - << i << "];\n"; - // clang-format on - } - for (int i = 0; i < layer_count - 1; ++i) - fragment_shader_stream << " }\n"; - fragment_shader_stream << " oFragColor = vec4(color, 1.0 - alphaCover);\n" - << "}\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(); } + #if defined(LOAD_PREBUILT_SHADER_FILE) || defined(USE_PREBUILT_SHADER_BIN_ARRAY) static GLint LoadPreBuiltBinary(GLint gl_program, void *binary, long size) { GLint status; @@ -311,7 +295,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; @@ -331,38 +315,35 @@ 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 = + + 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; } - glUniform4f(viewport_loc_, state.x_ / (float)viewport_width, + glUniform4f(viewport_loc_, state.x_ / (float)viewport_width, state.y_ / (float)viewport_height, (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], + 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 diff --git a/common/compositor/gl/glrenderer.cpp b/common/compositor/gl/glrenderer.cpp index 7ada3d043..1031afaf7 100644 --- a/common/compositor/gl/glrenderer.cpp +++ b/common/compositor/gl/glrenderer.cpp @@ -105,6 +105,7 @@ bool GLRenderer::Draw(const std::vector &render_states, surface->SetClearSurface(NativeSurface::kNone); glViewport(left, top, frame_width, frame_height); + glClearColor(0.0, 0.0, 0.0, 0.0); if (clear_surface || partial_clear) { const HwcRect &damage = surface->GetSurfaceDamage(); @@ -121,6 +122,7 @@ bool GLRenderer::Draw(const std::vector &render_states, } } else { glEnable(GL_SCISSOR_TEST); + glClear(GL_COLOR_BUFFER_BIT); } #ifdef COMPOSITOR_TRACING @@ -135,19 +137,24 @@ bool GLRenderer::Draw(const std::vector &render_states, damage.left, damage.top, damage.right - damage.left, damage.bottom - damage.top); #endif - for (const RenderState &state : render_states) { + int state_index = 0; + while (state_index < render_states.size()) { + const RenderState &state = render_states.at(state_index++); unsigned size = state.layer_state_.size(); - GLProgram *program = GetProgram(size); + ETRACE("renderstate layer size %d, layer index %d", size, + state.layer_state_[0].layer_index_); + GLProgram *program = GetProgram(1); if (!program) continue; program->UseProgram(state, frame_width, frame_height); #ifdef COMPOSITOR_TRACING - ICOMPOSITORTRACE( + ETRACE( "scissor_x_: %d state.scissor_y_: %d scissor_width_: %d " "scissor_height_: %d \n", state.scissor_x_, state.scissor_y_, state.scissor_width_, state.scissor_height_); + total_width += std::max(total_width, state.scissor_width_); total_height += state.scissor_height_; const HwcRect &damage = surface->GetSurfaceDamage(); @@ -173,7 +180,7 @@ bool GLRenderer::Draw(const std::vector &render_states, glDisable(GL_SCISSOR_TEST); if (!disable_explicit_sync_) - surface->SetNativeFence(context_.GetSyncFD()); + surface->SetNativeFence(context_.GetSyncFD(surface->IsOnScreen())); surface->ResetDamage(); #ifdef COMPOSITOR_TRACING diff --git a/common/core/gpudevice.cpp b/common/core/gpudevice.cpp index 7ceaf5164..59c3d25e0 100644 --- a/common/core/gpudevice.cpp +++ b/common/core/gpudevice.cpp @@ -81,7 +81,8 @@ bool GpuDevice::Initialize() { ETRACE("Failed to open %s", HWC_LOCK_FILE); // HWC should become drm master and start to commit. // if hwc.lock is not available - display_manager_->setDrmMaster(true); + if (!display_manager_->IsDrmMasterByDefault()) + display_manager_->setDrmMaster(true); ResetAllDisplayCommit(true); } @@ -129,6 +130,15 @@ bool GpuDevice::EnableDRMCommit(bool enable, uint32_t display_id) { return ret; } +void GpuDevice::MarkDisplayForFirstCommit() { + size_t size = total_displays_.size(); + for (size_t i = 0; i < size; i++) { + if (total_displays_.at(i)->IsConnected()) { + total_displays_.at(i)->MarkFirstCommit(); + } + } +} + bool GpuDevice::ResetDrmMaster(bool drop_master) { bool ret = true; if (drop_master) { @@ -148,6 +158,7 @@ bool GpuDevice::ResetDrmMaster(bool drop_master) { // In case of setDrmMaster or the lock file is not exist. // Re-set DRM Master true. display_manager_->setDrmMaster(false); + MarkDisplayForFirstCommit(); ResetAllDisplayCommit(true); DisableWatch(); diff --git a/common/core/overlaylayer.h b/common/core/overlaylayer.h index 40b62580a..7c9fd9197 100644 --- a/common/core/overlaylayer.h +++ b/common/core/overlaylayer.h @@ -293,7 +293,7 @@ struct OverlayLayer { uint8_t alpha_ = 0xff; uint32_t dataspace_ = 0; - uint32_t solid_color_ = 0; + uint32_t solid_color_ = 255; HwcRect source_crop_; HwcRect display_frame_; diff --git a/common/display/displayplanemanager.cpp b/common/display/displayplanemanager.cpp index 5104c66df..92c9ef73b 100644 --- a/common/display/displayplanemanager.cpp +++ b/common/display/displayplanemanager.cpp @@ -1248,7 +1248,8 @@ bool DisplayPlaneManager::SquashPlanesAsNeeded( const HwcRect &display_frame = scanout_plane.GetDisplayFrame(); const HwcRect &target_frame = last_plane.GetDisplayFrame(); if (!scanout_plane.IsCursorPlane() && !scanout_plane.IsVideoPlane() && - (AnalyseOverlap(display_frame, target_frame) != kOutside)) { + ((AnalyseOverlap(display_frame, target_frame) != kOutside) /*|| + scanout_plane.NeedsOffScreenComposition()*/)) { if (!ForceSeparatePlane(layers, last_plane, NULL)) { ISURFACETRACE("Squasing planes. \n"); const std::vector &new_layers = last_plane.GetSourceLayers(); diff --git a/common/display/displayqueue.cpp b/common/display/displayqueue.cpp index 011027ebf..0ca19a1a8 100644 --- a/common/display/displayqueue.cpp +++ b/common/display/displayqueue.cpp @@ -19,7 +19,7 @@ #include #include #include - +#include #include #include "displayplanemanager.h" @@ -639,6 +639,14 @@ void DisplayQueue::InitializeOverlayLayers( } } +void DisplayQueue::TraceFirstCommit() { + struct timeval te; + gettimeofday(&te, NULL); // get current time + long long milliseconds = + te.tv_sec * 1000LL + te.tv_usec / 1000; // calculate milliseconds + ITRACE("First frame is Committed at %lld.", milliseconds); +} + bool DisplayQueue::QueueUpdate(std::vector& source_layers, int32_t* retire_fence, bool* ignore_clone_update, PixelUploaderCallback* call_back, @@ -899,10 +907,15 @@ bool DisplayQueue::QueueUpdate(std::vector& source_layers, int32_t fence = 0; bool fence_released = false; - if (!IsIgnoreUpdates()) + if (!IsIgnoreUpdates()) { composition_passed = display_->Commit( current_composition_planes, previous_plane_state_, disable_explictsync, kms_fence_, &fence, &fence_released); + if (first_commit_) { + TraceFirstCommit(); + first_commit_ = false; + } + } if (fence_released) { kms_fence_ = 0; diff --git a/common/display/displayqueue.h b/common/display/displayqueue.h index cfadabc17..1223ca01d 100644 --- a/common/display/displayqueue.h +++ b/common/display/displayqueue.h @@ -104,6 +104,10 @@ class DisplayQueue { void UpdateScalingRatio(uint32_t primary_width, uint32_t primary_height, uint32_t display_width, uint32_t display_height); + void MarkFirstCommit() { + first_commit_ = true; + } + void SetCloneMode(bool cloned); void RotateDisplay(HWCRotation rotation); @@ -353,9 +357,12 @@ class DisplayQueue { bool& has_video_layer, bool& has_cursor_layer, bool& re_validate_commit, bool& idle_frame); + void TraceFirstCommit(); + Compositor compositor_; uint32_t gpu_fd_; uint32_t brightness_; + bool first_commit_ = false; float color_transform_matrix_[16]; HWCColorTransform color_transform_hint_; uint32_t contrast_; diff --git a/os/android/hwcservice.cpp b/os/android/hwcservice.cpp index b032fb567..f6116ac40 100644 --- a/os/android/hwcservice.cpp +++ b/os/android/hwcservice.cpp @@ -409,6 +409,10 @@ bool HwcService::Controls::EnableDRMCommit(bool enable, uint32_t display_id) { return mHwc.EnableDRMCommit(enable, display_id); } +bool HwcService::Controls::ResetDrmMaster(bool drop_master) { + return mHwc.ResetDrmMaster(drop_master); +} + status_t HwcService::Controls::VideoEnableEncryptedSession( uint32_t sessionID, uint32_t instanceID) { mHwc.SetPAVPSessionStatus(true, sessionID, instanceID); diff --git a/os/android/hwcservice.h b/os/android/hwcservice.h index 481b9a262..bb8ecaf31 100644 --- a/os/android/hwcservice.h +++ b/os/android/hwcservice.h @@ -108,6 +108,7 @@ class HwcService : public BnService { uint32_t SRMLength); uint32_t GetDisplayIDFromConnectorID(uint32_t connector_id); bool EnableDRMCommit(bool enable, uint32_t display_id); + bool ResetDrmMaster(bool drop_master); status_t VideoEnableEncryptedSession(uint32_t sessionID, uint32_t instanceID); status_t VideoDisableAllEncryptedSessions(uint32_t sessionID); diff --git a/os/android/iahwc2.cpp b/os/android/iahwc2.cpp index bae818b11..b10e07ca4 100644 --- a/os/android/iahwc2.cpp +++ b/os/android/iahwc2.cpp @@ -1311,6 +1311,10 @@ bool IAHWC2::EnableDRMCommit(bool enable, uint32_t display_id) { return device_.EnableDRMCommit(enable, display_id); } +bool IAHWC2::ResetDrmMaster(bool drop_master) { + return device_.ResetDrmMaster(drop_master); +} + void IAHWC2::SetHDCPSRMForDisplay(uint32_t connector, const int8_t *SRM, uint32_t SRMLength) { if (SRM == NULL) { diff --git a/os/android/iahwc2.h b/os/android/iahwc2.h index 1062860e2..82cea0e13 100644 --- a/os/android/iahwc2.h +++ b/os/android/iahwc2.h @@ -74,6 +74,8 @@ class IAHWC2 : public hwc2_device_t { bool EnableDRMCommit(bool enable, uint32_t display_id); + bool ResetDrmMaster(bool drop_master); + public: class Hwc2Layer { public: diff --git a/os/android/libhwcservice/hwcserviceapi.cpp b/os/android/libhwcservice/hwcserviceapi.cpp index 45960424c..7366abb00 100644 --- a/os/android/libhwcservice/hwcserviceapi.cpp +++ b/os/android/libhwcservice/hwcserviceapi.cpp @@ -315,6 +315,15 @@ status_t HwcService_EnableDRMCommit(HWCSHANDLE hwcs, uint32_t enable, return pContext->mControls->EnableDRMCommit(enable, display_id); } +status_t HwcService_ResetDrmMaster(HWCSHANDLE hwcs, uint32_t drop_master) { + HwcsContext* pContext = static_cast(hwcs); + if (!pContext) { + return android::BAD_VALUE; + } + + return pContext->mControls->ResetDrmMaster(drop_master); +} + status_t HwcService_Video_DisableHDCPSession_AllDisplays(HWCSHANDLE hwcs) { HwcsContext* pContext = static_cast(hwcs); if (!pContext) { diff --git a/os/android/libhwcservice/hwcserviceapi.h b/os/android/libhwcservice/hwcserviceapi.h index e0f6e2e96..68c5dd2fd 100644 --- a/os/android/libhwcservice/hwcserviceapi.h +++ b/os/android/libhwcservice/hwcserviceapi.h @@ -224,6 +224,8 @@ uint32_t HwcService_GetDisplayIDFromConnectorID(HWCSHANDLE hwcs, status_t HwcService_EnableDRMCommit(HWCSHANDLE hwcs, uint32_t enable, uint32_t display_id); +status_t HwcService_ResetDrmMaster(HWCSHANDLE hwcs, uint32_t drop_master); + // The control enables a the protected video subsystem to control when to // replace any // encrypted content with a default bitmap (usually black). diff --git a/os/android/libhwcservice/icontrols.cpp b/os/android/libhwcservice/icontrols.cpp index 9a59aef12..ec1f93a44 100644 --- a/os/android/libhwcservice/icontrols.cpp +++ b/os/android/libhwcservice/icontrols.cpp @@ -58,6 +58,7 @@ class BpControls : public BpInterface { TRANSACT_VIDEO_SET_HDCP_SRM_FOR_DISPLAY, TRANSACT_GET_DISPLAYID_FROM_CONNECTORID, TRANSACT_ENABLE_DRM_COMMIT, + TRANSACT_RESET_DRM_MASTER, TRANSACT_VIDEO_ENABLE_ENCRYPTED_SESSION, TRANSACT_VIDEO_DISABLE_ENCRYPTED_SESSION, TRANSACT_VIDEO_DISABLE_ALL_ENCRYPTED_SESSIONS, @@ -458,6 +459,19 @@ class BpControls : public BpInterface { return (uint32_t)(reply.readInt32()); } + bool ResetDrmMaster(bool drop_master) override { + Parcel data; + Parcel reply; + data.writeInterfaceToken(IControls::getInterfaceDescriptor()); + data.writeInt32(drop_master); + + status_t ret = remote()->transact(TRANSACT_RESET_DRM_MASTER, data, &reply); + if (ret != NO_ERROR) { + ALOGW("%s() transact failed: %d", __FUNCTION__, ret); + } + return (uint32_t)(reply.readInt32()); + } + status_t VideoEnableEncryptedSession(uint32_t sessionID, uint32_t instanceID) override { Parcel data; @@ -801,6 +815,13 @@ status_t BnControls::onTransact(uint32_t code, const Parcel &data, reply->writeInt32(ret); return NO_ERROR; } + case BpControls::TRANSACT_RESET_DRM_MASTER: { + CHECK_INTERFACE(IControls, data, reply); + bool drop_master = data.readInt32(); + bool ret = this->ResetDrmMaster(drop_master); + reply->writeInt32(ret); + return NO_ERROR; + } case BpControls::TRANSACT_VIDEO_ENABLE_ENCRYPTED_SESSION: { CHECK_INTERFACE(IControls, data, reply); uint32_t sessionID = data.readInt32(); diff --git a/os/android/libhwcservice/icontrols.h b/os/android/libhwcservice/icontrols.h index c8c0c49f0..db8f90c31 100644 --- a/os/android/libhwcservice/icontrols.h +++ b/os/android/libhwcservice/icontrols.h @@ -81,6 +81,8 @@ class IControls : public android::IInterface { virtual bool EnableDRMCommit(bool enable, uint32_t display_id) = 0; + virtual bool ResetDrmMaster(bool drop_master) = 0; + virtual status_t VideoEnableEncryptedSession(uint32_t sessionID, uint32_t instanceID) = 0; virtual status_t VideoDisableAllEncryptedSessions(uint32_t sessionID) = 0; diff --git a/public/gpudevice.h b/public/gpudevice.h index b8ff7d407..9d113d225 100644 --- a/public/gpudevice.h +++ b/public/gpudevice.h @@ -117,6 +117,8 @@ class GpuDevice : public HWCThread { void ResetAllDisplayCommit(bool enable); + void MarkDisplayForFirstCommit(); + enum InitializationType { kUnInitialized = 0, // Nothing Initialized. kInitialized = 1 << 1 // Everything Initialized diff --git a/public/hwclayer.h b/public/hwclayer.h index f2dc0b3be..81ec2e06a 100644 --- a/public/hwclayer.h +++ b/public/hwclayer.h @@ -348,7 +348,7 @@ struct HwcLayer { kVisible | kSurfaceDamageChanged | kVisibleRegionChanged | kZorderChanged; int layer_cache_ = kLayerAttributesChanged | kDisplayFrameRectChanged; bool is_cursor_layer_ = false; - uint32_t solid_color_ = 0; + uint32_t solid_color_ = 255; HWCLayerCompositionType composition_type_ = Composition_Device; }; diff --git a/public/nativedisplay.h b/public/nativedisplay.h index c43bcf921..bad3251c3 100644 --- a/public/nativedisplay.h +++ b/public/nativedisplay.h @@ -428,6 +428,9 @@ class NativeDisplay { return false; } + virtual void MarkFirstCommit() { + } + protected: friend class PhysicalDisplay; friend class GpuDevice; diff --git a/wsi/displaymanager.h b/wsi/displaymanager.h index 3ed0542d2..98eff2256 100644 --- a/wsi/displaymanager.h +++ b/wsi/displaymanager.h @@ -53,6 +53,8 @@ class DisplayManager { // manager until ForceRefresh is called. virtual void IgnoreUpdates() = 0; + virtual bool IsDrmMasterByDefault() = 0; + virtual void setDrmMaster(bool must_set) = 0; virtual void DropDrmMaster() = 0; diff --git a/wsi/drm/drmdisplay.cpp b/wsi/drm/drmdisplay.cpp index a98e89fa0..252951fb9 100644 --- a/wsi/drm/drmdisplay.cpp +++ b/wsi/drm/drmdisplay.cpp @@ -77,6 +77,10 @@ bool DrmDisplay::InitializeDisplay() { return true; } +void DrmDisplay::MarkFirstCommit() { + display_queue_->MarkFirstCommit(); +} + std::vector DrmDisplay::FindExtendedBlocksForTag(uint8_t *edid, uint8_t block_tag) { int current_block; @@ -588,7 +592,6 @@ bool DrmDisplay::CommitFrame( DrmPlane *plane = static_cast(comp_plane.GetDisplayPlane()); if (plane->InUse()) continue; - plane->Disable(pset); } diff --git a/wsi/drm/drmdisplay.h b/wsi/drm/drmdisplay.h index d02cb3eb7..181b3e9ee 100644 --- a/wsi/drm/drmdisplay.h +++ b/wsi/drm/drmdisplay.h @@ -129,6 +129,8 @@ class DrmDisplay : public PhysicalDisplay { return planes_updated_; } + void MarkFirstCommit() override; + private: void ShutDownPipe(); void GetDrmObjectPropertyValue(const char *name, diff --git a/wsi/drm/drmdisplaymanager.cpp b/wsi/drm/drmdisplaymanager.cpp index c4c11993e..b21bf00f7 100644 --- a/wsi/drm/drmdisplaymanager.cpp +++ b/wsi/drm/drmdisplaymanager.cpp @@ -75,7 +75,7 @@ bool DrmDisplayManager::Initialize() { } ScopedDrmResourcesPtr res(drmModeGetResources(fd_)); - if (res->count_crtcs == 0) + if (res && res->count_crtcs == 0) return false; for (int32_t i = 0; i < res->count_crtcs; ++i) { @@ -444,6 +444,28 @@ void DrmDisplayManager::IgnoreUpdates() { } } +bool DrmDisplayManager::IsDrmMasterByDefault() { + spin_lock_.lock(); + if (drm_master_) { + spin_lock_.unlock(); + return drm_master_; + } + drm_magic_t magic = 0; + int ret = 0; + ret = drmGetMagic(fd_, &magic); + if (ret) + ETRACE("Failed to call drmGetMagic : %s", PRINTERROR()); + else { + ret = drmAuthMagic(fd_, magic); + if (ret) + ETRACE("Failed to call drmAuthMagic : %s", PRINTERROR()); + else + drm_master_ = true; + } + spin_lock_.unlock(); + return drm_master_; +} + void DrmDisplayManager::setDrmMaster(bool must_set) { spin_lock_.lock(); if (drm_master_) { diff --git a/wsi/drm/drmdisplaymanager.h b/wsi/drm/drmdisplaymanager.h index 1b95f5191..0ae6cf180 100644 --- a/wsi/drm/drmdisplaymanager.h +++ b/wsi/drm/drmdisplaymanager.h @@ -71,6 +71,8 @@ class DrmDisplayManager : public HWCThread, public DisplayManager { void IgnoreUpdates() override; + bool IsDrmMasterByDefault() override; + void setDrmMaster(bool must_set) override; void DropDrmMaster() override;