OLD | NEW |
---|---|
(Empty) | |
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 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include <android/native_window_jni.h> | |
9 | |
10 namespace content { | |
11 | |
12 GpuMemoryBufferImplSurfaceTexture::GpuMemoryBufferImplSurfaceTexture( | |
13 gfx::Size size, | |
14 unsigned internalformat) | |
15 : GpuMemoryBufferImpl(size, internalformat), | |
16 texture_id_(0), | |
17 native_window_(NULL), | |
18 stride_(0), | |
19 stride_updated_(false) {} | |
20 | |
21 GpuMemoryBufferImplSurfaceTexture::~GpuMemoryBufferImplSurfaceTexture() {} | |
22 | |
23 bool GpuMemoryBufferImplSurfaceTexture::Initialize( | |
24 gfx::GpuMemoryBufferHandle handle) { | |
25 texture_id_ = handle.texture_id; | |
26 surface_texture_ = | |
27 reinterpret_cast<gfx::SurfaceTexture*>(handle.surface_texture_handle); | |
28 stride_ = GpuMemoryBufferImpl::GetStride(); | |
29 return true; | |
30 } | |
31 | |
32 void GpuMemoryBufferImplSurfaceTexture::setNativeWindow(ANativeWindow* window) { | |
33 native_window_ = window; | |
34 if (native_window_) { | |
35 if (ANativeWindow_setBuffersGeometry(native_window_, | |
36 size_.width(), | |
37 size_.height(), | |
38 WINDOW_FORMAT_RGBA_8888)) | |
39 return; | |
Hongbo Min
2014/03/18 06:10:03
Error log if ANativeWindow_setBuffersGeometry fail
| |
40 } | |
41 } | |
42 | |
43 void GpuMemoryBufferImplSurfaceTexture::Map(AccessMode mode, void** vaddr) { | |
44 DCHECK(!mapped_); | |
45 *vaddr = NULL; | |
46 if (!native_window_) | |
Hongbo Min
2014/03/18 06:10:03
Need to return if it is already mapped.
| |
47 return; | |
48 ANativeWindow_Buffer buffer; | |
49 if (ANativeWindow_lock(native_window_, &buffer, 0)) | |
Hongbo Min
2014/03/18 06:10:03
It may need to have a pair calling of ANativeWindo
| |
50 return; | |
51 | |
52 *vaddr = reinterpret_cast<void*>(buffer.bits); | |
53 stride_ = buffer.stride * 4; | |
54 stride_updated_ = true; | |
55 mapped_ = true; | |
56 } | |
57 | |
58 uint32 GpuMemoryBufferImplSurfaceTexture::GetStride() const { | |
59 if (!stride_updated_) { | |
60 LOG(WARNING) << "stride is not updated, a default stride is returned."; | |
61 LOG(WARNING) << "stride is: " << stride_ << ", width is " << size_.width(); | |
62 } | |
63 return stride_; | |
64 } | |
65 | |
66 void GpuMemoryBufferImplSurfaceTexture::Unmap() { | |
67 DCHECK(mapped_); | |
68 if (!native_window_) | |
Hongbo Min
2014/03/18 06:10:03
Does it also need to return if 'mapped' is false?
| |
69 return; | |
70 ANativeWindow_unlockAndPost(native_window_); | |
71 mapped_ = false; | |
72 } | |
73 | |
74 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSurfaceTexture::GetHandle() | |
75 const { | |
76 gfx::GpuMemoryBufferHandle handle; | |
77 handle.type = gfx::SURFACE_TEXTURE_BUFFER; | |
78 handle.texture_id = texture_id_; | |
79 handle.surface_texture_handle = reinterpret_cast<void*>(surface_texture_); | |
80 return handle; | |
81 } | |
82 | |
83 } // namespace content | |
OLD | NEW |