1// Copyright (c) 2012 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#include "ui/gl/gl_image.h"
6
7#include "base/debug/trace_event.h"
8#include "ui/gl/gl_image_egl.h"
9#include "ui/gl/gl_image_shm.h"
10#include "ui/gl/gl_image_stub.h"
11#include "ui/gl/gl_implementation.h"
12
13namespace gfx {
14
15scoped_refptr<GLImage> GLImage::CreateGLImage(gfx::PluginWindowHandle window) {
16  TRACE_EVENT0("gpu", "GLImage::CreateGLImage");
17  switch (GetGLImplementation()) {
18    case kGLImplementationEGLGLES2:
19      return NULL;
20    case kGLImplementationMockGL:
21      return new GLImageStub;
22    default:
23      NOTREACHED();
24      return NULL;
25  }
26}
27
28scoped_refptr<GLImage> GLImage::CreateGLImageForGpuMemoryBuffer(
29    gfx::GpuMemoryBufferHandle buffer,
30    gfx::Size size,
31    unsigned internalformat) {
32  TRACE_EVENT0("gpu", "GLImage::CreateGLImageForGpuMemoryBuffer");
33  switch (GetGLImplementation()) {
34    case kGLImplementationEGLGLES2:
35      switch (buffer.type) {
36        case SHARED_MEMORY_BUFFER: {
37          scoped_refptr<GLImageShm> image(
38              new GLImageShm(size, internalformat));
39          if (!image->Initialize(buffer))
40            return NULL;
41
42          return image;
43        }
44        case EGL_CLIENT_BUFFER: {
45          scoped_refptr<GLImageEGL> image(new GLImageEGL(size));
46          if (!image->Initialize(buffer))
47            return NULL;
48
49          return image;
50        }
51        default:
52          NOTREACHED();
53          return NULL;
54      }
55    case kGLImplementationMockGL:
56      return new GLImageStub;
57    default:
58      NOTREACHED();
59      return NULL;
60  }
61}
62
63}  // namespace gfx
64