Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use a shared cache for average colors
Before the average color for video backgrounds was locally stored in
each VideoBackground instance. During a call different VideoBackground
instances can be mounted and destroyed for the same participant (for
example, when switching between speaker mode and grid view, or when a
promoted speaker changes), so the previously calculated value was lost
and the average color had to be recalculated every time that happened.

Now the average colors are globally cached and shared between
VideoBackground instances, so previously calculated values can be used
by new VideoBackground instances.

The global cache is cleared each time a call ends.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Jan 25, 2021
commit 2d9723694eef5a9185f80a977e66e869d84d1a21
13 changes: 11 additions & 2 deletions src/components/CallView/shared/VideoBackground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export default {
hasPicture: false,
useCssBlurFilter: true,
useAverageColor: false,
backgroundImageAverageColor: '',
blur: 0,
blurredBackgroundImage: null,
blurredBackgroundImageCache: {},
Expand All @@ -108,6 +107,13 @@ export default {
},

computed: {
backgroundImageAverageColor() {
if (!this.backgroundImageUrlToAverage) {
return ''
}

return this.$store.getters.getCachedBackgroundImageAverageColor(this.backgroundImageUrlToAverage)
},
backgroundColor() {
if (this.hasPicture && this.useAverageColor) {
return this.backgroundImageAverageColor
Expand Down Expand Up @@ -191,7 +197,10 @@ export default {
}

average(this.backgroundImageUrlToAverage, { format: 'hex' }).then(color => {
this.backgroundImageAverageColor = color
this.$store.dispatch('setCachedBackgroundImageAverageColor', {
videoBackgroundId: this.backgroundImageUrlToAverage,
backgroundImageAverageColor: color,
})
})
},
},
Expand Down
20 changes: 20 additions & 0 deletions src/store/callViewStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
*
*/

import Vue from 'vue'

const state = {
isGrid: false,
selectedVideoPeerId: null,
videoBackgroundBlur: 1,
backgroundImageAverageColorCache: {},
}

const getters = {
Expand All @@ -40,6 +43,9 @@ const getters = {
getBlurRadius: (state) => (width, height) => {
return (width * height * state.videoBackgroundBlur) / 1000
},
getCachedBackgroundImageAverageColor: (state) => (videoBackgroundId) => {
return state.backgroundImageAverageColorCache[videoBackgroundId]
},
}

const mutations = {
Expand All @@ -50,6 +56,12 @@ const mutations = {
selectedVideoPeerId(state, value) {
state.selectedVideoPeerId = value
},
setCachedBackgroundImageAverageColor(state, { videoBackgroundId, backgroundImageAverageColor }) {
Vue.set(state.backgroundImageAverageColorCache, videoBackgroundId, backgroundImageAverageColor)
},
clearBackgroundImageAverageColorCache(state) {
state.backgroundImageAverageColorCache = {}
},
}

const actions = {
Expand All @@ -59,6 +71,14 @@ const actions = {
selectedVideoPeerId(context, value) {
context.commit('selectedVideoPeerId', value)
},

leaveCall(context) {
context.commit('clearBackgroundImageAverageColorCache')
},

setCachedBackgroundImageAverageColor(context, { videoBackgroundId, backgroundImageAverageColor }) {
context.commit('setCachedBackgroundImageAverageColor', { videoBackgroundId, backgroundImageAverageColor })
},
}

export default { state, mutations, getters, actions }