javauis/lcdui_akn/javalcdui/javasrc/javax/microedition/lcdui/Canvas.java
branchRCL_3
changeset 83 26b2b12093af
parent 77 7cee158cb8cd
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
    59     private static final int ATTRIB_CONTENT_HANDLE_INDEX      = 0;
    59     private static final int ATTRIB_CONTENT_HANDLE_INDEX      = 0;
    60     private static final int ATTRIB_WIDTH_INDEX               = 1;
    60     private static final int ATTRIB_WIDTH_INDEX               = 1;
    61     private static final int ATTRIB_HEIGHT_INDEX              = 2;
    61     private static final int ATTRIB_HEIGHT_INDEX              = 2;
    62     private static final int ATTRIB_NATIVE_FRAME_BUFFER_INDEX = 3;
    62     private static final int ATTRIB_NATIVE_FRAME_BUFFER_INDEX = 3;
    63     private static final int ATTRIB_BACKGROUND_INDEX          = 4;
    63     private static final int ATTRIB_BACKGROUND_INDEX          = 4;
    64     private static final int ATTRIB_VIDEO_OVERLAY_INDEX       = 5;
    64     private static final int ATTRIB_COUNT                     = 5;
    65     private static final int ATTRIB_COUNT                     = 6;
       
    66 
    65 
    67     /**
    66     /**
    68     * Static constants for media key keycodes
    67     * Static constants for media key keycodes
    69     */
    68     */
    70     private static final int MEDIA_KEY_PLAY                   = -20;
    69     private static final int MEDIA_KEY_PLAY                   = -20;
    93     /**
    92     /**
    94      * This member variable is set <code>true</code> if the <code>Nokia-UI-Enhancement</code>
    93      * This member variable is set <code>true</code> if the <code>Nokia-UI-Enhancement</code>
    95      * attribute is "CanvasHasBackground". The attribute may be placed in the JAD or the manifest.
    94      * attribute is "CanvasHasBackground". The attribute may be placed in the JAD or the manifest.
    96      */
    95      */
    97     private boolean iHasBackgroundImage;
    96     private boolean iHasBackgroundImage;
    98     private boolean iVideoOverlayEnabled;
       
    99     private boolean iIsGameCanvas;
    97     private boolean iIsGameCanvas;
   100     private Object iPaintLock;
       
   101 
    98 
   102     protected Canvas()
    99     protected Canvas()
   103     {
   100     {
   104         super();
   101         super();
   105         synchronized (iToolkit)
   102         synchronized (iToolkit)
   133             }
   130             }
   134             // Save the info about background.
   131             // Save the info about background.
   135             iHasBackgroundImage =
   132             iHasBackgroundImage =
   136                 (canvasAttribs[ATTRIB_BACKGROUND_INDEX] != 0);
   133                 (canvasAttribs[ATTRIB_BACKGROUND_INDEX] != 0);
   137 
   134 
   138             iVideoOverlayEnabled = 
       
   139                 (canvasAttribs[ATTRIB_VIDEO_OVERLAY_INDEX] != 0);
       
   140 
       
   141             // If is Toolkit activated, we can add Displayable to Vector
   135             // If is Toolkit activated, we can add Displayable to Vector
   142             // Displayables are removed from Vector when SizeChangedEvent arrives see Displayable.sizeChangedEvent()
   136             // Displayables are removed from Vector when SizeChangedEvent arrives see Displayable.sizeChangedEvent()
   143             if (iToolkit.activated)
   137             if (iToolkit.activated)
   144             {
   138             {
   145                 iToolkit.tmpDisplayables.addElement(this);
   139                 iToolkit.tmpDisplayables.addElement(this);
   146             }
   140             }
   147 
   141 
   148             iM3GContent = false;
   142             iM3GContent = false;
   149             iPaintLock = new Object();
       
   150         }
   143         }
   151     }
   144     }
   152 
   145 
   153     public boolean isDoubleBuffered()
   146     public boolean isDoubleBuffered()
   154     {
   147     {
   402         int     x;
   395         int     x;
   403         int     y;
   396         int     y;
   404         int     w;
   397         int     w;
   405         int     h;
   398         int     h;
   406 
   399 
   407         synchronized (iPaintLock)
   400         synchronized (iCallbackLock)
   408         {
   401         {
   409             synchronized (iCallbackLock)
   402             final int width;
   410             {
   403             final int height;
   411                 final int width;
   404 
   412                 final int height;
   405             //
   413 
   406             // Synchronize to protect the update region from concurrent
   414                 //
   407             // repaint()'s. Note that this is *not* sufficient to ensure
   415                 // Synchronize to protect the update region from concurrent
   408             // that no other callbacks are called by the event thread
   416                 // repaint()'s. Note that this is *not* sufficient to ensure
   409             // whilst the current thread is in the repaint routine, for
   417                 // that no other callbacks are called by the event thread
   410             // that we use the callbacklock below.
   418                 // whilst the current thread is in the repaint routine, for
   411             //
   419                 // that we use the callbacklock below.
   412             synchronized (iToolkit)
   420                 //
   413             {
   421                 synchronized (iToolkit)
   414                 width  = iWidth;
   422                 {
   415                 height = iHeight;
   423                     width  = iWidth;
   416 
   424                     height = iHeight;
   417                 x = iRepaintX1;
   425 
   418                 y = iRepaintY1;
   426                     x = iRepaintX1;
   419                 w = iRepaintX2-iRepaintX1;
   427                     y = iRepaintY1;
   420                 h = iRepaintY2-iRepaintY1;
   428                     w = iRepaintX2-iRepaintX1;
   421 
   429                     h = iRepaintY2-iRepaintY1;
   422                 iRepaintX1 = 0;
   430 
   423                 iRepaintY1 = 0;
   431                     iRepaintX1 = 0;
   424                 iRepaintX2 = 0;
   432                     iRepaintY1 = 0;
   425                 iRepaintY2 = 0;
   433                     iRepaintX2 = 0;
   426 
   434                     iRepaintY2 = 0;
   427                 if (!((w>0) && (h>0) && (IsShown() || forced)))
   435 
   428                 {
   436                     if (!((w>0) && (h>0) && (IsShown() || forced)))
   429                     return;
   437                     {
   430                 }
   438                         return;
   431 
   439                     }
   432                 graphics = GetPaintGraphics();
   440 
   433             }
   441                     graphics = GetPaintGraphics();
   434 
   442                 }
   435             graphics.reset(width, height);
   443 
   436             graphics.setClip(x, y, w, h);
   444                 graphics.reset(width, height);
   437 
   445                 graphics.setClip(x, y, w, h);
   438             // On a non-full-screen (normal) mode Canvas the background
   446 
   439             // image must be initially shown, if the value of the iHasBackgroundImage
   447                 // On a non-full-screen (normal) mode Canvas the background
   440             // is true.
   448                 // image must be initially shown, if the value of the iHasBackgroundImage
   441             if (!iFullScreen && iHasBackgroundImage && !iIsGameCanvas)
   449                 // is true.
   442             {
   450                 if (!iFullScreen && iHasBackgroundImage && !iIsGameCanvas)
   443                 drawBackground(true);
   451                 {
   444             }
   452                     drawBackground(true);
   445             paint(graphics);
   453                 }
       
   454 
       
   455                 if (iVideoOverlayEnabled)
       
   456                 {
       
   457                     // Send op code to native canvas about the start of paint,
       
   458                     // to enable overlays. This is done after 
       
   459                     // drawBackground() so that framebuffer can be cleared
       
   460                     // correctly on native side.
       
   461                     iToolkit.canvasPaintStarted(getContentHandle());
       
   462                 }
       
   463 
       
   464                 paint(graphics);
       
   465             }
       
   466 
       
   467             flush(x, y, w, h);
   446             flush(x, y, w, h);
   468         }
   447         }
       
   448 
       
   449 
       
   450 
       
   451 
   469     }
   452     }
   470 
   453 
   471     void flush(int aX, int aY, int aWidth, int aHeight)
   454     void flush(int aX, int aY, int aWidth, int aHeight)
   472     {
   455     {
   473         final Graphics screenGraphics;
   456         final Graphics screenGraphics;