forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathios_gl_context.mm
More file actions
67 lines (53 loc) · 2.38 KB
/
ios_gl_context.mm
File metadata and controls
67 lines (53 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/darwin/ios/ios_gl_context.h"
#include <UIKit/UIKit.h>
#include "flutter/fml/trace_event.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
namespace flutter {
IOSGLContext::IOSGLContext() : IOSGLContext(nullptr) {}
IOSGLContext::IOSGLContext(EAGLSharegroup* sharegroup)
: weak_factory_(std::make_unique<fml::WeakPtrFactory<IOSGLContext>>(this)) {
context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3
sharegroup:sharegroup]);
if (!context_) {
context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2
sharegroup:sharegroup]);
}
// TODO:
// iOS displays are more variable than just P3 or sRGB. Reading the display
// gamut just tells us what color space it makes sense to render into. We
// should use iOS APIs to perform the final correction step based on the
// device properties. Ex: We can indicate that we have rendered in P3, and
// the framework will do the final adjustment for us.
color_space_ = SkColorSpace::MakeSRGB();
if (@available(iOS 10, *)) {
UIDisplayGamut displayGamut = [UIScreen mainScreen].traitCollection.displayGamut;
switch (displayGamut) {
case UIDisplayGamutP3:
// Should we consider using more than 8-bits of precision given that
// P3 specifies a wider range of colors?
color_space_ = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
break;
default:
break;
}
}
}
fml::WeakPtr<IOSGLContext> IOSGLContext::GetWeakPtr() {
return weak_factory_->GetWeakPtr();
}
bool IOSGLContext::BindRenderbufferStorage(NSUInteger target,
fml::scoped_nsobject<CAEAGLLayer> layer) {
return [context_.get() renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer.get()];
}
IOSGLContext::~IOSGLContext() = default;
bool IOSGLContext::MakeCurrent() {
return [EAGLContext setCurrentContext:context_.get()];
}
std::unique_ptr<IOSGLContext> IOSGLContext::MakeSharedContext() {
return std::make_unique<IOSGLContext>(context_.get().sharegroup);
}
} // namespace flutter