Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "media/gpu/gles2_decoder_helper.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "base/threading/thread_checker.h" | |
| 10 #include "gpu/command_buffer/common/mailbox.h" | |
| 11 #include "gpu/command_buffer/common/sync_token.h" | |
|
watk
2017/06/29 18:39:07
potentially unneeded now
sandersd (OOO until July 31)
2017/06/29 23:13:00
Done.
| |
| 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | |
| 13 #include "gpu/command_buffer/service/mailbox_manager.h" | |
| 14 #include "gpu/command_buffer/service/texture_manager.h" | |
| 15 #include "gpu/ipc/service/gpu_command_buffer_stub.h" | |
|
watk
2017/06/29 18:39:07
potentially unneeded
sandersd (OOO until July 31)
2017/06/29 23:13:00
Done.
| |
| 16 | |
| 17 namespace media { | |
| 18 | |
| 19 class GLES2DecoderHelperImpl : public GLES2DecoderHelper { | |
| 20 public: | |
| 21 explicit GLES2DecoderHelperImpl(gpu::gles2::GLES2Decoder* decoder) | |
| 22 : decoder_(decoder) {} | |
| 23 | |
| 24 bool MakeContextCurrent() override { | |
| 25 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 26 return decoder_->MakeCurrent(); | |
| 27 } | |
| 28 | |
| 29 scoped_refptr<gpu::gles2::TextureRef> CreateTexture(GLenum target, | |
| 30 GLenum internal_format, | |
| 31 GLsizei width, | |
| 32 GLsizei height, | |
| 33 GLenum format, | |
| 34 GLenum type) override { | |
| 35 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 36 gpu::gles2::ContextGroup* group = decoder_->GetContextGroup(); | |
| 37 if (!group) | |
| 38 return nullptr; | |
| 39 gpu::gles2::TextureManager* texture_manager = group->texture_manager(); | |
| 40 if (!texture_manager) | |
| 41 return nullptr; | |
| 42 | |
| 43 // We can't use texture_manager->CreateTexture(), since it requires a unique | |
| 44 // |client_id|. Instead we create the texture directly, and create our own | |
| 45 // TextureRef for it. | |
| 46 GLuint texture_id; | |
| 47 glGenTextures(1, &texture_id); | |
| 48 glBindTexture(target, texture_id); | |
| 49 | |
| 50 scoped_refptr<gpu::gles2::TextureRef> texture_ref = | |
| 51 gpu::gles2::TextureRef::Create(texture_manager, 0, texture_id); | |
| 52 texture_manager->SetTarget(texture_ref.get(), target); | |
| 53 texture_manager->SetLevelInfo(texture_ref.get(), // ref | |
| 54 target, // target | |
| 55 0, // level | |
| 56 internal_format, // internal_format | |
| 57 width, // width | |
| 58 height, // height | |
| 59 1, // depth | |
| 60 0, // border | |
| 61 format, // format | |
| 62 type, // type | |
| 63 gfx::Rect()); // cleared_rect | |
| 64 | |
| 65 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(), | |
| 66 texture_ref.get(), GL_TEXTURE_MAG_FILTER, | |
| 67 GL_LINEAR); | |
| 68 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(), | |
| 69 texture_ref.get(), GL_TEXTURE_MIN_FILTER, | |
| 70 GL_LINEAR); | |
| 71 | |
| 72 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(), | |
| 73 texture_ref.get(), GL_TEXTURE_WRAP_S, | |
| 74 GL_CLAMP_TO_EDGE); | |
| 75 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(), | |
| 76 texture_ref.get(), GL_TEXTURE_WRAP_T, | |
| 77 GL_CLAMP_TO_EDGE); | |
| 78 | |
| 79 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(), | |
| 80 texture_ref.get(), GL_TEXTURE_BASE_LEVEL, 0); | |
| 81 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(), | |
| 82 texture_ref.get(), GL_TEXTURE_MAX_LEVEL, 0); | |
| 83 | |
| 84 // TODO(sandersd): Do we always want to allocate for GL_TEXTURE_2D? | |
| 85 if (target == GL_TEXTURE_2D) { | |
| 86 glTexImage2D(target, // target | |
| 87 0, // level | |
| 88 internal_format, // internal_format | |
| 89 width, // width | |
| 90 height, // height | |
| 91 0, // border | |
| 92 format, // format | |
| 93 type, // type | |
| 94 nullptr); // data | |
| 95 } | |
| 96 | |
| 97 decoder_->RestoreActiveTextureUnitBinding(target); | |
| 98 return texture_ref; | |
| 99 } | |
| 100 | |
| 101 base::Optional<gpu::Mailbox> CreateMailbox( | |
| 102 gpu::gles2::TextureRef* texture_ref) override { | |
| 103 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
| 104 gpu::gles2::ContextGroup* group = decoder_->GetContextGroup(); | |
| 105 if (!group) | |
| 106 return base::nullopt; | |
| 107 gpu::gles2::MailboxManager* mailbox_manager = group->mailbox_manager(); | |
| 108 if (!mailbox_manager) | |
| 109 return base::nullopt; | |
| 110 gpu::Mailbox mailbox = gpu::Mailbox::Generate(); | |
| 111 mailbox_manager->ProduceTexture(mailbox, texture_ref->texture()); | |
| 112 return mailbox; | |
| 113 } | |
| 114 | |
| 115 private: | |
| 116 gpu::gles2::GLES2Decoder* decoder_; | |
| 117 THREAD_CHECKER(thread_checker_); | |
| 118 | |
| 119 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderHelperImpl); | |
| 120 }; | |
| 121 | |
| 122 // static | |
| 123 std::unique_ptr<GLES2DecoderHelper> GLES2DecoderHelper::Create( | |
| 124 gpu::gles2::GLES2Decoder* decoder) { | |
| 125 if (!decoder) | |
| 126 return nullptr; | |
| 127 return base::MakeUnique<GLES2DecoderHelperImpl>(decoder); | |
| 128 } | |
| 129 | |
| 130 } // namespace media | |
| OLD | NEW |