[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / content / common / gpu / client / gpu_memory_buffer_impl_surface_texture.cc
blobf6080506caadab0bfbdbb6aba88c7ee5a1289ec9
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 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
7 #include "base/debug/trace_event.h"
8 #include "base/logging.h"
9 #include "content/common/android/surface_texture_lookup.h"
10 #include "ui/gl/gl_bindings.h"
12 namespace content {
14 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture(
15 const gfx::Size& size,
16 unsigned internalformat)
17 : GpuMemoryBufferImpl(size, internalformat),
18 native_window_(NULL),
19 stride_(0u) {}
21 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() {
22 if (native_window_)
23 ANativeWindow_release(native_window_);
26 // static
27 bool GpuMemoryBufferImplSurfaceTexture::IsFormatSupported(
28 unsigned internalformat) {
29 switch (internalformat) {
30 case GL_RGBA8_OES:
31 return true;
32 default:
33 return false;
37 // static
38 bool GpuMemoryBufferImplSurfaceTexture::IsUsageSupported(unsigned usage) {
39 switch (usage) {
40 case GL_IMAGE_MAP_CHROMIUM:
41 return true;
42 default:
43 return false;
47 // static
48 bool GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(
49 unsigned internalformat,
50 unsigned usage) {
51 return IsFormatSupported(internalformat) && IsUsageSupported(usage);
54 // static
55 int GpuMemoryBufferImplSurfaceTexture::WindowFormat(unsigned internalformat) {
56 switch (internalformat) {
57 case GL_RGBA8_OES:
58 return WINDOW_FORMAT_RGBA_8888;
59 default:
60 NOTREACHED();
61 return 0;
65 bool GpuMemoryBufferImplSurfaceTexture::InitializeFromHandle(
66 gfx::GpuMemoryBufferHandle handle) {
67 TRACE_EVENT0("gpu",
68 "GpuMemoryBufferImplSurfaceTexture::InitializeFromHandle");
70 DCHECK(IsFormatSupported(internalformat_));
71 DCHECK(!native_window_);
72 native_window_ = SurfaceTextureLookup::GetInstance()->AcquireNativeWidget(
73 handle.surface_texture_id.primary_id,
74 handle.surface_texture_id.secondary_id);
75 if (!native_window_)
76 return false;
78 ANativeWindow_setBuffersGeometry(native_window_,
79 size_.width(),
80 size_.height(),
81 WindowFormat(internalformat_));
83 surface_texture_id_ = handle.surface_texture_id;
84 return true;
87 void* GpuMemoryBufferImplSurfaceTexture::Map() {
88 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Map");
90 DCHECK(!mapped_);
91 DCHECK(native_window_);
92 ANativeWindow_Buffer buffer;
93 int status = ANativeWindow_lock(native_window_, &buffer, NULL);
94 if (status) {
95 VLOG(1) << "ANativeWindow_lock failed with error code: " << status;
96 return NULL;
99 DCHECK_LE(size_.width(), buffer.stride);
100 stride_ = buffer.stride * BytesPerPixel(internalformat_);
101 mapped_ = true;
102 return buffer.bits;
105 void GpuMemoryBufferImplSurfaceTexture::Unmap() {
106 TRACE_EVENT0("gpu", "GpuMemoryBufferImplSurfaceTexture::Unmap");
108 DCHECK(mapped_);
109 ANativeWindow_unlockAndPost(native_window_);
110 mapped_ = false;
113 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const { return stride_; }
115 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle()
116 const {
117 gfx::GpuMemoryBufferHandle handle;
118 handle.type = gfx::SURFACE_TEXTURE_BUFFER;
119 handle.surface_texture_id = surface_texture_id_;
120 return handle;
123 } // namespace content