github.com/as/shiny@v0.8.2/driver/windriver/buffer.go (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build windows
     6  
     7  package windriver
     8  
     9  import (
    10  	"image"
    11  	"image/draw"
    12  	"syscall"
    13  
    14  	"github.com/as/shiny/driver/win32"
    15  )
    16  
    17  type bufferImpl struct {
    18  	hbitmap   syscall.Handle
    19  	buf, buf2 []byte
    20  	rgba      image.RGBA
    21  	size      image.Point
    22  }
    23  
    24  //func (b *bufferImpl) Resize(size image.Point) *bufferImpl       {
    25  //	real := b.rgba.Bounds().Size()
    26  //	curr := b.size
    27  //	if size.X > real.X || size.Y > real.Y{
    28  //		// Client wants a larger rectangle than we can provide
    29  //		return nil
    30  //	}
    31  //	if curr.X*curr.Y / 3 > size.X*size.Y{
    32  //		// Very small rectangle
    33  //		returnnil
    34  //	}
    35  //}
    36  func (b *bufferImpl) Size() image.Point       { return b.size }
    37  func (b *bufferImpl) Bounds() image.Rectangle { return image.Rectangle{Max: b.size} }
    38  func (b *bufferImpl) RGBA() *image.RGBA       { return &b.rgba }
    39  func (b *bufferImpl) Release() {
    40  	go b.cleanUp()
    41  }
    42  
    43  func (b *bufferImpl) cleanUp() {
    44  	if b.rgba.Pix != nil {
    45  		b.rgba.Pix = nil
    46  		win32.DeleteObject(b.hbitmap)
    47  	}
    48  }
    49  
    50  func (b *bufferImpl) blitToDC(dc syscall.Handle, dp image.Point, sr image.Rectangle) error {
    51  	return copyBitmapToDC(dc, sr.Add(dp.Sub(sr.Min)), b.hbitmap, sr, draw.Src)
    52  }