Author: Anton Gulenko <[email protected]>
Branch: storage-display-refactoring
Changeset: r934:2d4fa0b3f3b7
Date: 2014-07-22 15:51 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/2d4fa0b3f3b7/

Log:    Refactoring. The SDLDisplay instance is globally accessible in the
        space. Cleaned up the process for a form to become the display.
        Added model_display.py (forgotten in previous commit). Fixed
        MappingDisplay: handling the case that width is not dividable by 32.

diff --git a/images/Squeak4.5-noBitBlt.changes 
b/images/Squeak4.5-noBitBlt.changes
--- a/images/Squeak4.5-noBitBlt.changes
+++ b/images/Squeak4.5-noBitBlt.changes
@@ -12620,4 +12620,8 @@
        
        1 to: self splayTreeSize do: [:i |
                self insertNewNode.
-       ]! !

----SNAPSHOT----{15 July 2014 . 6:10:56 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894330!
\ No newline at end of file
+       ]! !

----SNAPSHOT----{15 July 2014 . 6:10:56 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894330!
+
+----QUIT/NOSAVE----{21 July 2014 . 7:09:22 pm} Squeak4.5-noBitBlt.image 
priorSource: 15894825!
+
+----QUIT----{21 July 2014 . 7:10:12 pm} Squeak4.5-noBitBlt.image priorSource: 
15894825!

----STARTUP----{22 July 2014 . 10:55:07 am} as 
C:\Dev\lang-smalltalk\images\Squeak4.5-noBitBlt.image!


Smalltalk specialObjectsArray at:15!

(Smalltalk specialObjectsArray at:15) depth!
\ No newline at end of file
diff --git a/spyvm/display.py b/spyvm/display.py
--- a/spyvm/display.py
+++ b/spyvm/display.py
@@ -35,12 +35,13 @@
 WindowEventPaint = 5
 WindowEventStinks = 6
 
+MINIMUM_DEPTH = 8
 
 class SDLDisplay(object):
     _attrs_ = ["screen", "width", "height", "depth", "surface", "has_surface",
                "mouse_position", "button", "key", "interrupt_key", 
"_defer_updates",
-               "_deferred_event", "pixelbuffer"]
-    _immutable_fields_ = ["pixelbuffer?"]
+               "_deferred_event", "bpp", "pitch"]
+    #_immutable_fields_ = ["pixelbuffer?"]
 
     def __init__(self, title):
         assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
@@ -58,26 +59,31 @@
     def set_video_mode(self, w, h, d):
         assert w > 0 and h > 0
         assert d in [1, 2, 4, 8, 16, 32]
+        if d < MINIMUM_DEPTH:
+            d = MINIMUM_DEPTH
         self.width = w
         self.height = h
         self.depth = d
         flags = RSDL.HWPALETTE | RSDL.RESIZABLE | RSDL.ASYNCBLIT | 
RSDL.DOUBLEBUF
-        if d < 8:
-            d = 8
         self.screen = RSDL.SetVideoMode(w, h, d, flags)
         if not self.screen:
             print "Could not open display at depth %d" % d
             raise RuntimeError
-        elif d == 8:
+        elif d == MINIMUM_DEPTH:
             self.set_squeak_colormap(self.screen)
-        self.pixelbuffer = rffi.cast(rffi.UINTP, self.screen.c_pixels)
-
-    def get_pixelbuffer(self):
-        return jit.promote(self.pixelbuffer)
-
+        self.bpp = rffi.getintfield(self.screen.c_format, 'c_BytesPerPixel')
+        self.pitch = rffi.getintfield(self.screen, 'c_pitch')
+    
+    def get_pixelbuffer_UCHAR(self):
+        # return jit.promote(rffi.cast(RSDL.Uint8P, self.screen.c_pixels))
+        return jit.promote(self.screen.c_pixels)
+    
+    def get_pixelbuffer_UINT(self):
+        return jit.promote(rffi.cast(RSDL.Uint32P, self.screen.c_pixels))
+    
     def defer_updates(self, flag):
         self._defer_updates = flag
-
+    
     def flip(self, force=False):
         if (not self._defer_updates) or force:
             RSDL.Flip(self.screen)
diff --git a/spyvm/interpreter_proxy.py b/spyvm/interpreter_proxy.py
--- a/spyvm/interpreter_proxy.py
+++ b/spyvm/interpreter_proxy.py
@@ -560,7 +560,7 @@
     space = IProxy.space
     if w_dest_form.is_same_object(space.objtable['w_display']):
         form = wrapper.FormWrapper(space, w_dest_form)
-        w_display_bitmap = form.get_display_bitmap(IProxy.interp)
+        w_display_bitmap = form.get_display_bitmap()
         w_display_bitmap.update_from_buffer()
         w_display_bitmap.flush_to_screen()
     return 0
@@ -1000,7 +1000,7 @@
         self.argcount = 0
         self.w_method = None
         self.fail_reason = 0
-        self.trace_proxy.unset()
+        self.trace_proxy.deactivate()
 
     def call(self, signature, interp, s_frame, argcount, w_method):
         self.initialize_from_call(signature, interp, s_frame, argcount, 
w_method)
@@ -1042,7 +1042,7 @@
         self.argcount = argcount
         self.w_method = w_method
         self.space = interp.space
-        self.trace_proxy.set_to(interp.trace_proxy.is_set())
+        self.trace_proxy.set(interp.trace_proxy.is_set())
         # ensure that space.w_nil gets the first possible oop
         self.object_to_oop(self.space.w_nil)
 
diff --git a/spyvm/model_display.py b/spyvm/model_display.py
new file mode 100644
--- /dev/null
+++ b/spyvm/model_display.py
@@ -0,0 +1,203 @@
+
+from spyvm import model, constants, display
+from rpython.rlib import jit
+from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rlib.rarithmetic import r_uint
+
+def from_words_object(w_obj, form):
+    depth = form.depth()
+    space = form.space
+    size = w_obj.size()
+    w_class = w_obj.getclass(space)
+    
+    if depth < 8:
+        w_display_bitmap = W_MappingDisplayBitmap(space, w_class, size, depth, 
form.width())
+    elif depth == 8:
+        w_display_bitmap = W_8BitDisplayBitmap(space, w_class, size, depth)
+    elif depth == 16:
+        w_display_bitmap = W_16BitDisplayBitmap(space, w_class, size, depth)
+    else:
+        w_display_bitmap = W_DisplayBitmap(space, w_class, size, depth)
+    
+    for idx in range(size):
+        w_display_bitmap.setword(idx, w_obj.getword(idx))
+    
+    return w_display_bitmap
+
+invert_byte_order = [False]
+
+def invert():
+    inv = invert_byte_order[0]
+    return jit.promote(inv)
+
+class W_DisplayBitmap(model.W_AbstractObjectWithClassReference):
+    _attrs_ = ['pixelbuffer_words', '_real_depth_buffer', '_realsize', 
'display', '_depth']
+    _immutable_fields_ = ['pixelbuffer_words?', '_real_depth_buffer', 
'_realsize', 'display', '_depth']
+    repr_classname = "W_DisplayBitmap"
+    
+    def __init__(self, space, w_class, size, depth):
+        model.W_AbstractObjectWithClassReference.__init__(self, space, w_class)
+        self._real_depth_buffer = lltype.malloc(rffi.CArray(rffi.UINT), size, 
flavor='raw')
+        self._realsize = size
+        self._depth = depth
+        self.display = space.display()
+        self.relinquish_display()
+    
+    # === Object access
+    
+    def at0(self, space, index0):
+        val = self.getword(index0)
+        return space.wrap_uint(val)
+    
+    def atput0(self, space, index0, w_value):
+        word = space.unwrap_uint(w_value)
+        self.setword(index0, word)
+    
+    def getword(self, n):
+        assert self.size() > n >= 0
+        return self._real_depth_buffer[n]
+    
+    def setword(self, n, word):
+        self._real_depth_buffer[n] = word
+        if self.pixelbuffer_words > 0:
+            self.set_pixelbuffer_word(n, word)
+    
+    def size(self):
+        return self._realsize
+    
+    # === Graphics
+    
+    def pixelbuffer_UINT(self):
+        return self.display.get_pixelbuffer_UINT()
+    
+    def pixelbuffer_UCHAR(self):
+        return self.display.get_pixelbuffer_UCHAR()
+    
+    def set_pixelbuffer_word(self, n, word):
+        self.pixelbuffer_UINT()[n] = word
+    
+    def take_over_display(self):
+        # Make sure FrameWrapper.take_over_display() is called first for the 
correct Frame object.
+        pixel_per_word = constants.BYTES_PER_WORD / (self.display.depth / 8)
+        self.pixelbuffer_words = self.display.width * self.display.height / 
pixel_per_word
+        self.update_from_buffer()
+    
+    def relinquish_display(self):
+        self.pixelbuffer_words = 0
+    
+    def flush_to_screen(self):
+        self.display.flip()
+    
+    def update_from_buffer(self):
+        if self.pixelbuffer_words > 0:
+            for i in range(self.size()):
+                self.set_pixelbuffer_word(i, self.getword(i))
+    
+    # === Misc
+    
+    def invariant(self):
+        return False
+
+    def clone(self, space):
+        w_result = model.W_WordsObject(space, self.getclass(space), 
self.size())
+        for n in range(self.size()):
+            w_result.setword(n, self.getword(n))
+        return w_result
+    
+    def is_array_object(self):
+        return True
+
+    def convert_to_c_layout(self):
+        return self._real_depth_buffer
+
+    def can_become(self, w_other):
+        # TODO - implement _become() for this class. Impossible due to 
_immutable_fields_?
+        return False
+    
+    def __del__(self):
+        lltype.free(self._real_depth_buffer, flavor='raw')
+    
+    def repr_content(self):
+        return "len=%d depth=%d %s" % (self.size(), self._depth, 
self.str_content())
+
+class W_16BitDisplayBitmap(W_DisplayBitmap):
+    
+    repr_classname = "W_16BitDisplayBitmap"
+    
+    def set_pixelbuffer_word(self, n, word):
+        mask = 0b11111
+        lsb = (r_uint(word) & r_uint(0xffff0000)) >> 16
+        msb = (r_uint(word) & r_uint(0x0000ffff))
+        
+        # Invert order of rgb-components
+        lsb = (
+            ((lsb >> 10) & mask) |
+            (((lsb >> 5) & mask) << 6) |
+            ((lsb & mask) << 11)
+        )
+        msb = (
+            ((msb >> 10) & mask) |
+            (((msb >> 5) & mask) << 6) |
+            ((msb & mask) << 11)
+        )
+        
+        self.pixelbuffer_UINT()[n] = r_uint(lsb | (msb << 16))
+
+class W_8BitDisplayBitmap(W_DisplayBitmap):
+    
+    repr_classname = "W_8BitDisplayBitmap"
+    
+    def set_pixelbuffer_word(self, n, word):
+        if invert():
+            # Invert the byte-order.
+            self.pixelbuffer_UINT()[n] = r_uint(
+                (word >> 24) |
+                ((word >> 8) & 0x0000ff00) |
+                ((word << 8) & 0x00ff0000) |
+                (word << 24)
+            )
+        else:
+            self.pixelbuffer_UINT()[n] = r_uint(word)
+
+class W_MappingDisplayBitmap(W_DisplayBitmap):
+    
+    repr_classname = "W_MappingDisplayBitmap"
+    _attrs_ = ['mapping_factor', 'words_per_line', 'bits_in_last_word', 
'width']
+    _immutable_fields_ = ['mapping_factor', 'words_per_line', 
'bits_in_last_word', 'width']
+    
+    pixel_per_word = constants.BYTES_PER_WORD
+    
+    def __init__(self, space, w_class, size, depth, width):
+        assert depth in [1, 2, 4]
+        width = r_uint(width)
+        self.width = width
+        self.mapping_factor = display.MINIMUM_DEPTH / depth
+        self.words_per_line = r_uint(width / 32 + 1)
+        self.bits_in_last_word = width % 32
+        W_DisplayBitmap.__init__(self, space, w_class, size, depth)
+    
+    @jit.unroll_safe
+    def set_pixelbuffer_word(self, n, word):
+        n = r_uint(n)
+        word = r_uint(word)
+        pos = self.compute_pos(n)
+        buf = self.display.screen.c_pixels
+        
+        if (n+1) % self.words_per_line == 0:
+            # This is the last word on the line. A few bits are cut off.
+            bits = self.bits_in_last_word
+        else:
+            bits = 32
+        
+        depth = r_uint(self._depth)
+        rshift = 32 - depth
+        for i in range(r_uint(bits) / depth):
+            pixel = word >> rshift
+            buf[pos] = rffi.cast(rffi.UCHAR, pixel)
+            word <<= self._depth
+            pos += 1
+        
+    def compute_pos(self, n):
+        word_on_line = n % self.words_per_line
+        complete_lines = r_uint((n - word_on_line) / self.words_per_line)
+        return complete_lines * self.width + 32*word_on_line
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -1,39 +1,47 @@
 import os
 
-from spyvm import constants, model, model_display, shadow, wrapper, version
+from spyvm import constants, model, model_display, shadow, wrapper, version, 
display
 from spyvm.error import UnwrappingError, WrappingError, PrimitiveFailedError
 from rpython.rlib import jit, rpath
-from rpython.rlib.objectmodel import instantiate, specialize
+from rpython.rlib.objectmodel import instantiate, specialize, import_from_mixin
 from rpython.rlib.rarithmetic import intmask, r_uint, int_between
 
-class ConstantFlag(object):
-    """Boolean flag that can be edited, but will be promoted
+class ConstantMixin(object):
+    """Mixin for constant values that can be edited, but will be promoted
     to a constant when jitting."""
     
-    def __init__(self, set_initially=False):
-        self.flag = [set_initially]
-    
-    def is_set(self):
-        return jit.promote(self.flag[0])
-    
-    def set(self):
-        self.flag[0] = True
-    
-    def unset(self):
-        self.flag[0] = False
-    
-    def set_to(self, flag):
-        self.flag[0] = flag
-
-class ConstantString(object):
-    def __init__(self):
-        self.value = [""]
-    
-    def get(self):
-        return jit.promote(self.value[0])
+    def __init__(self, initial_value = None):
+        if initial_value is None:
+            initial_value = self.default_value
+        self.value = [initial_value]
     
     def set(self, value):
         self.value[0] = value
+    
+    def get(self):
+        value = jit.promote(self.value[0])
+        return value
+
+class ConstantFlag(object):
+    import_from_mixin(ConstantMixin)
+    default_value = False
+    def is_set(self):
+        return self.get()
+    def activate(self):
+        self.set(True)
+    def deactivate(self):
+        self.set(False)
+
+class ConstantString(object):
+    import_from_mixin(ConstantMixin)
+    default_value = ""
+    def get(self):
+        # Promoting does not work on strings...
+        return self.value[0]
+    
+class ConstantObject(object):
+    import_from_mixin(ConstantMixin)
+    default_value = None
 
 class ObjSpace(object):
     def __init__(self):
@@ -49,6 +57,7 @@
         self.objtable = {}
         self._executable_path = ConstantString()
         self._image_name = ConstantString()
+        self._display = ConstantObject()
         
         # Create the nil object.
         # Circumvent the constructor because nil is already referenced there.
@@ -85,12 +94,6 @@
                 self.objtable[name] = specials[idx]
         # XXX this is kind of hacky, but I don't know where else to get 
Metaclass
         self.classtable["w_Metaclass"] = self.w_SmallInteger.w_class.w_class
-        
-    def executable_path(self):
-        return self._executable_path.get()
-    
-    def image_name(self):
-        return self._image_name.get()
     
     def add_bootstrap_class(self, name, cls):
         self.classtable[name] = cls
@@ -138,14 +141,8 @@
             name = "w_" + name
             if not name in self.objtable:
                 self.add_bootstrap_object(name, None)
-    
-    @specialize.arg(1)
-    def get_special_selector(self, selector):
-        i0 = constants.find_selectorindex(selector)
-        self.w_special_selectors.as_cached_object_get_shadow(self)
-        return self.w_special_selectors.fetch(self, i0)
 
-    # methods for wrapping and unwrapping stuff
+    # ============= Methods for wrapping and unwrapping stuff =============
 
     def wrap_int(self, val):
         from spyvm import constants
@@ -247,14 +244,30 @@
 
         return [w_array.at0(self, i) for i in range(w_array.size())]
 
-    def get_display(self):
-        w_display = self.objtable['w_display']
-        if w_display:
-            w_bitmap = w_display.fetch(self, 0)
-            if isinstance(w_bitmap, model_display.W_DisplayBitmap):
-                return w_bitmap.display
-        raise PrimitiveFailedError("No display")
-
+    # ============= Access to static information =============
+    
+    @specialize.arg(1)
+    def get_special_selector(self, selector):
+        i0 = constants.find_selectorindex(selector)
+        self.w_special_selectors.as_cached_object_get_shadow(self)
+        return self.w_special_selectors.fetch(self, i0)
+    
+    def executable_path(self):
+        return self._executable_path.get()
+    
+    def image_name(self):
+        return self._image_name.get()
+    
+    def display(self):
+        disp = self._display.get()
+        if disp is None:
+            # Create lazy to allow headless execution.
+            disp = display.SDLDisplay(self.image_name())
+            self._display.set(disp)
+        return disp
+    
+    # ============= Other Methods =============
+    
     def _freeze_(self):
         return True
 
diff --git a/spyvm/plugins/vmdebugging.py b/spyvm/plugins/vmdebugging.py
--- a/spyvm/plugins/vmdebugging.py
+++ b/spyvm/plugins/vmdebugging.py
@@ -20,12 +20,12 @@
 
 @DebuggingPlugin.expose_primitive(unwrap_spec=[object])
 def trace_proxy(interp, s_frame, w_rcvr):
-    interp.trace_proxy.set()
+    interp.trace_proxy.activate()
     return w_rcvr
 
 @DebuggingPlugin.expose_primitive(unwrap_spec=[object])
 def untrace_proxy(interp, s_frame, w_rcvr):
-    interp.trace_proxy.unset()
+    interp.trace_proxy.deactivate()
     return w_rcvr
 
 @DebuggingPlugin.expose_primitive(unwrap_spec=[object])
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -644,7 +644,7 @@
 
 @expose_primitive(MOUSE_POINT, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
-    x, y = interp.space.get_display().mouse_point()
+    x, y = interp.space.display().mouse_point()
     w_point = model.W_PointersObject(interp.space, interp.space.w_Point, 2)
     w_point.store(interp.space, 0, interp.space.wrap_int(x))
     w_point.store(interp.space, 1, interp.space.wrap_int(y))
@@ -656,7 +656,7 @@
 def func(interp, s_frame, w_rcvr, w_into):
     if not interp.evented:
         raise PrimitiveFailedError()
-    ary = interp.space.get_display().get_next_event(time=interp.time_now())
+    ary = interp.space.display().get_next_event(time=interp.time_now())
     for i in range(8):
         w_into.store(interp.space, i, interp.space.wrap_int(ary[i]))
     # XXX - hack
@@ -731,40 +731,23 @@
 def func(interp, s_frame, w_rcvr):
     if interp.space.headless.is_set():
         exitFromHeadlessExecution(s_frame)
-    
     if not isinstance(w_rcvr, model.W_PointersObject) or w_rcvr.size() < 4:
         raise PrimitiveFailedError
     
+    old_display = interp.space.objtable['w_display']
+    if isinstance(old_display, model_display.W_DisplayBitmap):
+        old_display.relinquish_display()
+    interp.space.objtable['w_display'] = w_rcvr
+    
     # TODO: figure out whether we should decide the width an report it in the 
SCREEN_SIZE primitive
     form = wrapper.FormWrapper(interp.space, w_rcvr)
-    w_bitmap = form.bits()
-    width = form.width()
-    height = form.height()
-    depth = form.depth()
-
-    sdldisplay = None
-
-    w_prev_display = interp.space.objtable['w_display']
-    if w_prev_display:
-        w_prev_bitmap = w_prev_display.fetch(interp.space, 0)
-        if isinstance(w_prev_bitmap, model_display.W_DisplayBitmap):
-            sdldisplay = w_prev_bitmap.display
-            sdldisplay.set_video_mode(width, height, depth)
+    form.take_over_display()
+    w_display_bitmap = form.get_display_bitmap()
+    w_display_bitmap.take_over_display()
+    w_display_bitmap.flush_to_screen()
     
-    if isinstance(w_bitmap, model_display.W_DisplayBitmap):
-        assert (sdldisplay is None) or (sdldisplay is w_bitmap.display)
-        sdldisplay = w_bitmap.display
-        sdldisplay.set_video_mode(width, height, depth)
-        w_display_bitmap = w_bitmap
-    else:
-        assert isinstance(w_bitmap, model.W_WordsObject)
-        w_display_bitmap = form.get_display_bitmap(interp, sdldisplay)
-    
-    w_display_bitmap.flush_to_screen()
     if interp.image:
-        interp.image.lastWindowSize = (width << 16)  + height
-    interp.space.objtable['w_display'] = w_rcvr
-
+        interp.image.lastWindowSize = (form.width() << 16) + form.height()
     return w_rcvr
 
 @expose_primitive(STRING_REPLACE, unwrap_spec=[object, index1_0, index1_0, 
object, index1_0])
@@ -807,12 +790,12 @@
 
 @expose_primitive(MOUSE_BUTTONS, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
-    btn = interp.space.get_display().mouse_button()
+    btn = interp.space.display().mouse_button()
     return interp.space.wrap_int(btn)
 
 @expose_primitive(KBD_NEXT, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
-    code = interp.space.get_display().next_keycode()
+    code = interp.space.display().next_keycode()
     if code & 0xFF == 0:
         return interp.space.w_nil
     else:
@@ -820,7 +803,7 @@
 
 @expose_primitive(KBD_PEEK, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
-    code = interp.space.get_display().peek_keycode()
+    code = interp.space.display().peek_keycode()
     if code & 0xFF == 0:
         return interp.space.w_nil
     else:
@@ -999,7 +982,7 @@
 
 @expose_primitive(DEFER_UPDATES, unwrap_spec=[object, bool])
 def func(interp, s_frame, w_receiver, flag):
-    sdldisplay = interp.space.get_display()
+    sdldisplay = interp.space.display()
     sdldisplay.defer_updates(flag)
     return w_receiver
 
@@ -1053,7 +1036,7 @@
 
 @expose_primitive(SET_INTERRUPT_KEY, unwrap_spec=[object, int])
 def func(interp, s_frame, w_rcvr, encoded_key):
-    interp.space.get_display().set_interrupt_key(interp.space, encoded_key)
+    interp.space.display().set_interrupt_key(interp.space, encoded_key)
     return w_rcvr
 
 @expose_primitive(INTERRUPT_SEMAPHORE, unwrap_spec=[object, object])
@@ -1526,7 +1509,7 @@
 
 @expose_primitive(FORCE_DISPLAY_UPDATE, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
-    interp.space.get_display().flip(force=True)
+    interp.space.display().flip(force=True)
     return w_rcvr
 
 # ___________________________________________________________________________
diff --git a/spyvm/test/test_model.py b/spyvm/test/test_model.py
--- a/spyvm/test/test_model.py
+++ b/spyvm/test/test_model.py
@@ -404,15 +404,7 @@
         assert target.pixelbuffer[i] == 0x0
 
 def test_display_offset_computation():
-
-    def get_pixelbuffer(self):
-        return lltype.malloc(rffi.ULONGP.TO, self.width * self.height * 32, 
flavor='raw')
-    display.SDLDisplay.get_pixelbuffer = get_pixelbuffer
-    d = display.SDLDisplay("test")
-    d.set_video_mode(18, 5, 1)
-
-    dbitmap = model_display.W_DisplayBitmap.create(space, space.w_Array, 5, 1, 
d)
-
+    dbitmap = model_display.W_MappingDisplayBitmap(space, space.w_Array, 5, 1)
     assert dbitmap.compute_pos(0) == 0
     assert dbitmap.compute_pos(1) == 8
     assert dbitmap.size() == 5 * 8
diff --git a/spyvm/test/test_primitives.py b/spyvm/test/test_primitives.py
--- a/spyvm/test/test_primitives.py
+++ b/spyvm/test/test_primitives.py
@@ -765,7 +765,7 @@
         raise DisplayFlush
 
     try:
-        monkeypatch.setattr(space.get_display().__class__, "flip", 
flush_to_screen_mock)
+        monkeypatch.setattr(space.display().__class__, "flip", 
flush_to_screen_mock)
         with py.test.raises(DisplayFlush):
             prim(primitives.FORCE_DISPLAY_UPDATE, [mock_display])
     finally:
diff --git a/spyvm/wrapper.py b/spyvm/wrapper.py
--- a/spyvm/wrapper.py
+++ b/spyvm/wrapper.py
@@ -269,15 +269,24 @@
     height, store_height = make_int_getter_setter(constants.FORM_HEIGHT)
     depth, store_depth = make_int_getter_setter(constants.FORM_DEPTH)
     
-    def get_display_bitmap(self, interp, sdldisplay=None):
+    def create_display_bitmap(self):
+        w_display_bitmap = model_display.from_words_object(self.bits(), self)
+        self.store_bits(w_display_bitmap)
+        return w_display_bitmap
+    
+    def get_display_bitmap(self):
         w_bitmap = self.bits()
         if not isinstance(w_bitmap, model_display.W_DisplayBitmap):
-            w_display_bitmap = model_display.from_words_object(interp, 
w_bitmap, self, sdldisplay)
-            self.store_bits(w_display_bitmap)
+            w_display_bitmap = self.create_display_bitmap()
         else:
             w_display_bitmap = w_bitmap
+            if w_display_bitmap._depth != self.depth():
+                w_display_bitmap = self.create_display_bitmap()
         return w_display_bitmap
-
+    
+    def take_over_display(self):
+        self.space.display().set_video_mode(self.width(), self.height(), 
self.depth())
+    
 # XXX Wrappers below are not used yet.
 class OffsetWrapper(Wrapper):
     offset_x  = make_int_getter(0)
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -121,9 +121,12 @@
             elif arg in ["-P", "--process"]:
                 headless = False
             elif arg in ["--hacks"]:
-                space.run_spy_hacks.set()
+                space.run_spy_hacks.activate()
+            elif arg in ["--invert"]:
+                from spyvm import model_display
+                model_display.invert_byte_order[0] = True
             elif arg in ["-S"]:
-                space.no_specialized_storage.set()
+                space.no_specialized_storage.activate()
             elif arg in ["-u"]:
                 from spyvm.plugins.vmdebugging import stop_ui_process
                 stop_ui_process()
@@ -177,7 +180,7 @@
             selector = compile_code(interp, w_receiver, code)
         s_frame = create_context(interp, w_receiver, selector, stringarg)
         if headless:
-            space.headless.set()
+            space.headless.activate()
             context = s_frame
         else:
             create_process(interp, s_frame)
@@ -206,7 +209,7 @@
     # registered (primitive 136 not called), so the idle process will never be 
left once it is entered.
     # TODO - Find a way to cleanly initialize the image, without executing the 
active_context of the image.
     # Instead, we want to execute our own context. Then remove this flag (and 
all references to it)
-    space.suppress_process_switch.set()
+    space.suppress_process_switch.activate()
     
     w_result = interp.perform(
         w_receiver_class,
@@ -218,7 +221,7 @@
     # TODO - is this expected in every image?
     if not isinstance(w_result, model.W_BytesObject) or w_result.as_string() 
!= selector:
         raise error.Exit("Unexpected compilation result (probably failed to 
compile): %s" % result_string(w_result))
-    space.suppress_process_switch.unset()
+    space.suppress_process_switch.deactivate()
     
     
w_receiver_class.as_class_get_shadow(space).s_methoddict().sync_method_cache()
     return selector
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to