zorldo

Goofing around with Ebiten
git clone git://bsandro.tech/zorldo
Log | Files | Refs | README

view_ios.go (1898B)


      1 // Copyright 2019 The Ebiten Authors
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 //go:build darwin && ios
     16 // +build darwin,ios
     17 
     18 package metal
     19 
     20 // #cgo CFLAGS: -x objective-c
     21 // #cgo LDFLAGS: -framework UIKit
     22 //
     23 // #import <UIKit/UIKit.h>
     24 //
     25 // static void addSublayer(void* view, void* sublayer) {
     26 //   CALayer* layer = ((UIView*)view).layer;
     27 //   [layer addSublayer:(CALayer*)sublayer];
     28 // }
     29 //
     30 // static void setFrame(void* cametal, void* uiview) {
     31 //   CGSize size = ((UIView*)uiview).frame.size;
     32 //   ((CALayer*)cametal).frame = CGRectMake(0, 0, size.width, size.height);
     33 // }
     34 import "C"
     35 
     36 import (
     37 	"unsafe"
     38 
     39 	"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl"
     40 )
     41 
     42 func (v *view) setWindow(window uintptr) {
     43 	panic("metal: setWindow is not available on iOS")
     44 }
     45 
     46 func (v *view) setUIView(uiview uintptr) {
     47 	v.uiview = uiview
     48 }
     49 
     50 func (v *view) update() {
     51 	v.once.Do(func() {
     52 		if v.ml.Layer() == nil {
     53 			panic("metal: CAMetalLayer is not initialized yet")
     54 		}
     55 		C.addSublayer(unsafe.Pointer(v.uiview), v.ml.Layer())
     56 	})
     57 	C.setFrame(v.ml.Layer(), unsafe.Pointer(v.uiview))
     58 }
     59 
     60 func (v *view) usePresentsWithTransaction() bool {
     61 	// Do not use presentsWithTransaction on iOS (#1799).
     62 	return false
     63 }
     64 
     65 func (v *view) maximumDrawableCount() int {
     66 	return 3
     67 }
     68 
     69 const (
     70 	storageMode         = mtl.StorageModeShared
     71 	resourceStorageMode = mtl.ResourceStorageModeShared
     72 )