1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #if !defined(__has_feature) || !__has_feature(objc_arc)
6 #error "This file requires ARC support."
9 #import "remoting/ios/ui/desktop_texture.h"
11 @implementation DesktopTexture
13 - (const webrtc::DesktopSize&)textureSize {
17 - (void)setTextureSize:(const webrtc::DesktopSize&)size {
18 if (!_textureSize.equals(size)) {
19 _textureSize.set(size.width(), size.height());
20 _needInitialize = true;
24 - (void)bindToEffect:(GLKEffectPropertyTexture*)effectProperty {
25 glGenTextures(1, &_textureId);
26 [Utility bindTextureForIOS:_textureId];
28 // This is the HOST Desktop layer, and each draw will always replace what is
29 // currently in the draw context
30 effectProperty.target = GLKTextureTarget2D;
31 effectProperty.name = _textureId;
32 effectProperty.envMode = GLKTextureEnvModeReplace;
33 effectProperty.enabled = GL_TRUE;
35 [Utility logGLErrorCode:@"DesktopTexture bindToTexture"];
37 glBindTexture(GL_TEXTURE_2D, 0);
41 return _needInitialize;
44 - (void)drawRegion:(GLRegion*)region rect:(CGRect)rect {
45 if (_textureSize.height() == 0 && _textureSize.width() == 0) {
49 [Utility bindTextureForIOS:_textureId];
51 if (_needInitialize) {
52 glTexImage2D(GL_TEXTURE_2D,
56 _textureSize.height(),
62 [Utility logGLErrorCode:@"DesktopTexture initializeTextureSurfaceWithSize"];
63 _needInitialize = false;
66 [Utility drawSubRectToGLFromRectOfSize:_textureSize
67 subRect:webrtc::DesktopRect::MakeXYWH(
70 region->image->size().width(),
71 region->image->size().height())
72 data:region->image->data()];
74 [Utility logGLErrorCode:@"DesktopTexture drawRegion"];
76 glBindTexture(GL_TEXTURE_2D, 0);
79 - (void)releaseTexture {
80 glDeleteTextures(1, &_textureId);