OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 #ifndef CHROME_RENDERER_MEDIA_GLES2_VIDEO_DECODE_CONTEXT_H_ |
| 6 #define CHROME_RENDERER_MEDIA_GLES2_VIDEO_DECODE_CONTEXT_H_ |
| 7 |
| 8 #include "media/video/video_decode_context.h" |
| 9 |
| 10 namespace WebKit { |
| 11 class WebGLES2Context; |
| 12 } // namespace WebKit |
| 13 |
| 14 // FUNCTIONS |
| 15 // |
| 16 // This is a class that provides a video decode context using a GLES2 backend. |
| 17 // It provides resources for a VideoDecodeEngine to store decoded video frames |
| 18 // in the GLES2 context. |
| 19 // |
| 20 // This class is aware of the command buffer implementation of GLES2 inside the |
| 21 // Chrome renderer and keeps a reference of ggl::Context. It might use GLES2 |
| 22 // commands specific to Chrome's renderer process to provide needed resources. |
| 23 // |
| 24 // There are two different kinds of video frame storage provided by this class: |
| 25 // 1. Memory mapped YUV textures (aka software decoding mode). |
| 26 // Each video frame allocated is backed by 3 luminance textures carrying |
| 27 // the Y, U and V planes. |
| 28 // |
| 29 // Furthermore each texture is memory mapped and appears to the |
| 30 // VideoDecodeEngine as 3 planes backed by system memory. |
| 31 // |
| 32 // The usage of these 3 textures is that the VideoDecodeEngine is performing |
| 33 // software video decoding and use them as if they are allocated in plain |
| 34 // system memory (in fact they are allocated in system memory and shared |
| 35 // bwith the GPU process). An additional step of uploading the content to |
| 36 // video memory is needed. Since VideoDecodeEngine is unaware of the video |
| 37 // memory, this upload operation is performed by video renderer provided by |
| 38 // Chrome. |
| 39 // |
| 40 // After the content is uploaded to video memory, WebKit will see the video |
| 41 // frame as 3 textures and will perform the necessary operations for |
| 42 // rendering. |
| 43 // |
| 44 // 2. RGBA texture (aka hardware decoding mode). |
| 45 // In this mode of operation each video frame is backed by a RGBA texture. |
| 46 // This is used only when hardware video decoding is used. The texture needs |
| 47 // to be generated and allocated inside the renderer process first. This |
| 48 // will establish a translation between texture ID in the renderer process |
| 49 // and the GPU process. |
| 50 // |
| 51 // The texture ID generated is used by IpcVideoDecodeEngine only to be sent |
| 52 // the GPU process. Inside the GPU process the texture ID is translated to |
| 53 // a real texture ID inside the actual GLES context. The real texture ID is |
| 54 // then assigned to the hardware video decoder for storing the video frame. |
| 55 // |
| 56 // WebKit will see the video frame as a normal RGBA texture and perform |
| 57 // necessary render operations. |
| 58 // |
| 59 // In both operation modes, the objective is to have WebKit see the video frames |
| 60 // as regular textures. |
| 61 // |
| 62 // THREAD SEMANTICS |
| 63 // |
| 64 // This class is accessed on two threads, namely the Render Thread and the |
| 65 // Video Decoder Thread. |
| 66 // |
| 67 // GLES2 context and all OpenGL method calls should be accessed on the Render |
| 68 // Thread. |
| 69 // |
| 70 // VideoDecodeContext implementations are accessed on the Video Decoder Thread. |
| 71 // |
| 72 class Gles2VideoDecodeContext : public media::VideoDecodeContext { |
| 73 public: |
| 74 enum StorageType { |
| 75 // This video decode context provides YUV textures as storage. This is used |
| 76 // only in software decoding mode. |
| 77 kMemoryMappedYuvTextures, |
| 78 |
| 79 // This video decode context provides RBGA textures as storage. This is |
| 80 // used in hardware decoding mode. |
| 81 kRgbaTextures, |
| 82 }; |
| 83 |
| 84 //-------------------------------------------------------------------------- |
| 85 // Render Thread |
| 86 Gles2VideoDecodeContext(StorageType type, |
| 87 WebKit::WebGLES2Context* gles2context); |
| 88 |
| 89 // TODO(hclam): Need to figure out which thread destroys this object. |
| 90 virtual ~Gles2VideoDecodeContext(); |
| 91 |
| 92 //-------------------------------------------------------------------------- |
| 93 // Video Decoder Thread |
| 94 |
| 95 // media::VideoDecodeContext implementation. |
| 96 virtual void* GetDevice(); |
| 97 virtual void AllocateVideoFrames(int n, size_t width, size_t height, |
| 98 AllocationCompleteCallback* callback); |
| 99 virtual void ReleaseVideoFrames(int n, media::VideoFrame* frames); |
| 100 virtual void Destroy(DestructionCompleteCallback* callback); |
| 101 |
| 102 //-------------------------------------------------------------------------- |
| 103 // Any thread |
| 104 // Accessor of the current mode of this decode context. |
| 105 bool IsMemoryMapped() const { return type_ == kMemoryMappedYuvTextures; } |
| 106 |
| 107 private: |
| 108 // Type of storage provided by this class. |
| 109 StorageType type_; |
| 110 |
| 111 // TODO(hclam): We should keep a ggl::Context instead. |
| 112 WebKit::WebGLES2Context* context_; |
| 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(Gles2VideoDecodeContext); |
| 115 }; |
| 116 |
| 117 #endif // CHROME_RENDERER_MEDIA_GLES2_VIDEO_DECODE_CONTEXT_H_ |
OLD | NEW |