• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5#if !defined(__has_feature) || !__has_feature(objc_arc)
6#error "This file requires ARC support."
7#endif
8
9#import "remoting/ios/ui/desktop_texture.h"
10
11@implementation DesktopTexture
12
13- (const webrtc::DesktopSize&)textureSize {
14  return _textureSize;
15}
16
17- (void)setTextureSize:(const webrtc::DesktopSize&)size {
18  if (!_textureSize.equals(size)) {
19    _textureSize.set(size.width(), size.height());
20    _needInitialize = true;
21  }
22}
23
24- (void)bindToEffect:(GLKEffectPropertyTexture*)effectProperty {
25  glGenTextures(1, &_textureId);
26  [Utility bindTextureForIOS:_textureId];
27
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;
34
35  [Utility logGLErrorCode:@"DesktopTexture bindToTexture"];
36  // Release context
37  glBindTexture(GL_TEXTURE_2D, 0);
38}
39
40- (BOOL)needDraw {
41  return _needInitialize;
42}
43
44- (void)drawRegion:(GLRegion*)region rect:(CGRect)rect {
45  if (_textureSize.height() == 0 && _textureSize.width() == 0) {
46    return;
47  }
48
49  [Utility bindTextureForIOS:_textureId];
50
51  if (_needInitialize) {
52    glTexImage2D(GL_TEXTURE_2D,
53                 0,
54                 GL_RGBA,
55                 _textureSize.width(),
56                 _textureSize.height(),
57                 0,
58                 GL_RGBA,
59                 GL_UNSIGNED_BYTE,
60                 NULL);
61
62    [Utility logGLErrorCode:@"DesktopTexture initializeTextureSurfaceWithSize"];
63    _needInitialize = false;
64  }
65
66  [Utility drawSubRectToGLFromRectOfSize:_textureSize
67                                 subRect:webrtc::DesktopRect::MakeXYWH(
68                                             region->offset->x(),
69                                             region->offset->y(),
70                                             region->image->size().width(),
71                                             region->image->size().height())
72                                    data:region->image->data()];
73
74  [Utility logGLErrorCode:@"DesktopTexture drawRegion"];
75  // Release context
76  glBindTexture(GL_TEXTURE_2D, 0);
77}
78
79- (void)releaseTexture {
80  glDeleteTextures(1, &_textureId);
81}
82
83@end
84