Bug 424387

Summary: Node.setOpacity(int) fails to visually update
Product: [Applications] krita Reporter: RKS <rkspsm>
Component: ScriptingAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED INTENTIONAL    
Severity: minor CC: lynx.mw+kde
Priority: NOR    
Version First Reported In: nightly build (please specify the git hash!)   
Target Milestone: ---   
Platform: Appimage   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description RKS 2020-07-18 20:58:42 UTC
SUMMARY

The function setOpacity(int) of class Node (tested only on Paint Layer), fails to visually update on its own, although it does get reflected in layers docker (it shows new opacity). If I try to paint on the layer, the new strokes are of new opacity whereas old strokes stay with old opacity value. But it fixes if i try to change opacity manually via layers docker.

STEPS TO REPRODUCE
1. Make sure a paint layer is selected, with something painted on it, I assume its 255 (100%).
2. Run a script which changes the active node's opacity by node.setOpacity(int) to some new value, say 128 (50%).

OBSERVED RESULT

Layers docker updates the current layer's opacity to 50% but nothing happens visually on the canvas. Trying to paint will paint new strokes with 50% but older strokes stay at 100%. Trying to change opacity of the layer manually fixes this.

EXPECTED RESULT

The canvas should update to new opacity.

NOTE :

- If I am expected to call some function to notify canvas after I call setOpacity(int) then it should be mentioned in the document. Currently nothing is mentioned.

- As a workaround, I just call node.rotateNode(0.0) after changing opacity. This fixes the problem, the canvas gets updated with new opacity value.


SOFTWARE/OS VERSIONS
Krita

 Version: 4.3.1-alpha (git f119f41)
 Languages: en_US, en
 Hidpi: false

Qt

  Version (compiled): 5.12.9
  Version (loaded): 5.12.9

OS Information

  Build ABI: x86_64-little_endian-lp64
  Build CPU: x86_64
  CPU: x86_64
  Kernel Type: linux
  Kernel Version: 5.7.9-arch1-1
  Pretty Productname: Arch Linux
  Product Type: arch
  Product Version: unknown
  Desktop: X-Cinnamon

OpenGL Info
 
  Vendor:  "NVIDIA Corporation" 
  Renderer:  "GeForce GTX 960/PCIe/SSE2" 
  Version:  "4.6.0 NVIDIA 450.57" 
  Shading language:  "4.60 NVIDIA" 
  Requested format:  QSurfaceFormat(version 3.0, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::DoubleBuffer, swapInterval 0, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::CompatibilityProfile) 
  Current format:    QSurfaceFormat(version 4.6, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::DoubleBuffer, swapInterval 0, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::CompatibilityProfile) 
     Version: 4.6
     Supports deprecated functions true 
     is OpenGL ES: false 

QPA OpenGL Detection Info 
  supportsDesktopGL: true 
  supportsOpenGLES: true 
  isQtPreferOpenGLES: false 

Hardware Information

  GPU Acceleration: auto
  Memory: 15935 Mb
  Number of Cores: 4
  Swap Location: /tmp

Current Settings

  Current Swap Location: /tmp
  Current Swap Location writable: true
  Undo Enabled: true
  Undo Stack Limit: 30
  Use OpenGL: true
  Use OpenGL Texture Buffer: false
  Use AMD Vectorization Workaround: false
  Canvas State: OPENGL_SUCCESS
  Autosave Interval: 180
  Use Backup Files: false
  Number of Backups Kept: 20
  Backup File Suffix: _backup
  Backup Location: Same Folder as the File
  Backup Location writable: false
  Use Win8 Pointer Input: false
  Use RightMiddleTabletButton Workaround: false
  Levels of Detail Enabled: false
  Use Zip64: false


Display Information
Number of screens: 1
	Screen: 0
		Name: HDMI-0
		Depth: 24
		Scale: 1
		Resolution in pixels: 1920x1080
		Manufacturer: BNQ
		Model: BenQ GW2760HS
		Refresh Rate: 60




ADDITIONAL INFORMATION
Comment 1 Lynx3d 2020-07-19 17:33:01 UTC
I'm not the scripting expert here, but isn't this intentional?
You probably just should call document.refreshProjection()

If every property change would forcefully update the projection, doing several changes would waste a lot of CPU time.
Comment 2 RKS 2020-07-19 18:34:05 UTC
(In reply to Lynx3d from comment #1)
> I'm not the scripting expert here, but isn't this intentional?
> You probably just should call document.refreshProjection()
> 
> If every property change would forcefully update the projection, doing
> several changes would waste a lot of CPU time.

Thanks, document.refreshProjection() works.

I actually expected that there might be some step to notify the change. But it is not necessary that doing multiple updates waste CPU in general sense. Some APIs may use some mechanism to mark the current state as dirty and will update during next refresh. In that case, there will not be any need to manually notify.