internal/cocoa: remove IsIOS

Use `runtime.GOOS == "ios"` instead.

Closes #1415
This commit is contained in:
Hajime Hoshi 2022-09-15 01:01:25 +09:00
parent 619a2ee4dd
commit 2cbc5e7b60
4 changed files with 8 additions and 46 deletions

View File

@ -1,20 +0,0 @@
// Copyright 2022 The Ebitengine Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build ios
// +build ios
package cocoa
const IsIOS = true

View File

@ -1,20 +0,0 @@
// Copyright 2022 The Ebitengine Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !ios
// +build !ios
package cocoa
const IsIOS = false

View File

@ -22,6 +22,7 @@ package ca
import ( import (
"errors" "errors"
"fmt" "fmt"
"runtime"
"unsafe" "unsafe"
"github.com/ebitengine/purego" "github.com/ebitengine/purego"
@ -59,7 +60,7 @@ var (
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer. // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer.
func MakeMetalLayer() MetalLayer { func MakeMetalLayer() MetalLayer {
layer := objc.ID(objc.GetClass("CAMetalLayer")).Send(objc.RegisterName("new")) layer := objc.ID(objc.GetClass("CAMetalLayer")).Send(objc.RegisterName("new"))
if !cocoa.IsIOS { if runtime.GOOS != "ios" {
colorspace, _, _ := purego.SyscallN(_CGColorSpaceCreateWithName, **(**uintptr)(unsafe.Pointer(&kCGColorSpaceDisplayP3))) // Dlsym returns pointer to symbol so dereference it colorspace, _, _ := purego.SyscallN(_CGColorSpaceCreateWithName, **(**uintptr)(unsafe.Pointer(&kCGColorSpaceDisplayP3))) // Dlsym returns pointer to symbol so dereference it
layer.Send(objc.RegisterName("setColorspace:"), colorspace) layer.Send(objc.RegisterName("setColorspace:"), colorspace)
purego.SyscallN(_CGColorSpaceRelease, colorspace) purego.SyscallN(_CGColorSpaceRelease, colorspace)
@ -125,7 +126,7 @@ func (ml MetalLayer) SetMaximumDrawableCount(count int) {
// //
// Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/2887087-displaysyncenabled. // Reference: https://developer.apple.com/documentation/quartzcore/cametallayer/2887087-displaysyncenabled.
func (ml MetalLayer) SetDisplaySyncEnabled(enabled bool) { func (ml MetalLayer) SetDisplaySyncEnabled(enabled bool) {
if cocoa.IsIOS { if runtime.GOOS == "ios" {
return return
} }
ml.metalLayer.Send(objc.RegisterName("setDisplaySyncEnabled:"), enabled) ml.metalLayer.Send(objc.RegisterName("setDisplaySyncEnabled:"), enabled)

View File

@ -26,6 +26,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"reflect" "reflect"
"runtime"
"unsafe" "unsafe"
"github.com/ebitengine/purego" "github.com/ebitengine/purego"
@ -559,7 +560,7 @@ func CreateSystemDefaultDevice() (Device, bool) {
lowPower bool lowPower bool
name string name string
) )
if !cocoa.IsIOS { if runtime.GOOS != "ios" {
headless = int(objc.ID(d).Send(sel_isHeadless)) != 0 headless = int(objc.ID(d).Send(sel_isHeadless)) != 0
lowPower = int(objc.ID(d).Send(sel_isLowPower)) != 0 lowPower = int(objc.ID(d).Send(sel_isLowPower)) != 0
} }
@ -941,14 +942,14 @@ type BlitCommandEncoder struct {
// //
// Reference: https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400775-synchronize. // Reference: https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400775-synchronize.
func (bce BlitCommandEncoder) Synchronize(resource Resource) { func (bce BlitCommandEncoder) Synchronize(resource Resource) {
if cocoa.IsIOS { if runtime.GOOS == "ios" {
return return
} }
bce.commandEncoder.Send(sel_synchronizeResource, resource.resource()) bce.commandEncoder.Send(sel_synchronizeResource, resource.resource())
} }
func (bce BlitCommandEncoder) SynchronizeTexture(texture Texture, slice int, level int) { func (bce BlitCommandEncoder) SynchronizeTexture(texture Texture, slice int, level int) {
if cocoa.IsIOS { if runtime.GOOS == "ios" {
return return
} }
bce.commandEncoder.Send(sel_synchronizeTexture_slice_level, texture.texture, slice, level) bce.commandEncoder.Send(sel_synchronizeTexture_slice_level, texture.texture, slice, level)
@ -1081,7 +1082,7 @@ func (b Buffer) CopyToContents(data unsafe.Pointer, lengthInBytes uintptr) {
dataHeader.Len = int(lengthInBytes) dataHeader.Len = int(lengthInBytes)
dataHeader.Cap = int(lengthInBytes) dataHeader.Cap = int(lengthInBytes)
copy(contentSlice, dataSlice) copy(contentSlice, dataSlice)
if !cocoa.IsIOS { if runtime.GOOS != "ios" {
b.buffer.Send(sel_didModifyRange, 0, lengthInBytes) b.buffer.Send(sel_didModifyRange, 0, lengthInBytes)
} }
} }