Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: media/gpu/gles2_decoder_helper.cc

Issue 2938543005: media: Add GLES2DecoderHelper (Closed)
Patch Set: Remove unneeded #includes. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/gpu/gles2_decoder_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/service/gles2_cmd_decoder.h"
12 #include "gpu/command_buffer/service/mailbox_manager.h"
13 #include "gpu/command_buffer/service/texture_manager.h"
14
15 namespace media {
16
17 class GLES2DecoderHelperImpl : public GLES2DecoderHelper {
18 public:
19 explicit GLES2DecoderHelperImpl(gpu::gles2::GLES2Decoder* decoder)
20 : decoder_(decoder) {}
21
22 bool MakeContextCurrent() override {
23 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
24 return decoder_->MakeCurrent();
25 }
26
27 scoped_refptr<gpu::gles2::TextureRef> CreateTexture(GLenum target,
28 GLenum internal_format,
29 GLsizei width,
30 GLsizei height,
31 GLenum format,
32 GLenum type) override {
33 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
sunnyps 2017/06/30 01:01:07 nit: dcheck if context is current
sandersd (OOO until July 31) 2017/07/06 22:09:06 Done.
34 gpu::gles2::ContextGroup* group = decoder_->GetContextGroup();
35 if (!group)
piman 2017/07/06 22:30:50 nit: This will always be non-null
36 return nullptr;
37 gpu::gles2::TextureManager* texture_manager = group->texture_manager();
38 if (!texture_manager)
piman 2017/07/06 22:30:50 So, today this would never be null in production.
sandersd (OOO until July 31) 2017/07/06 22:47:11 Done. In general, the purpose of VDAs is not just
39 return nullptr;
40
41 // We can't use texture_manager->CreateTexture(), since it requires a unique
42 // |client_id|. Instead we create the texture directly, and create our own
43 // TextureRef for it.
44 GLuint texture_id;
45 glGenTextures(1, &texture_id);
46 glBindTexture(target, texture_id);
47
48 scoped_refptr<gpu::gles2::TextureRef> texture_ref =
49 gpu::gles2::TextureRef::Create(texture_manager, 0, texture_id);
50 texture_manager->SetTarget(texture_ref.get(), target);
51 texture_manager->SetLevelInfo(texture_ref.get(), // ref
52 target, // target
53 0, // level
54 internal_format, // internal_format
55 width, // width
56 height, // height
57 1, // depth
58 0, // border
59 format, // format
60 type, // type
61 gfx::Rect()); // cleared_rect
62
63 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
64 texture_ref.get(), GL_TEXTURE_MAG_FILTER,
65 GL_LINEAR);
66 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
67 texture_ref.get(), GL_TEXTURE_MIN_FILTER,
68 GL_LINEAR);
69
70 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
71 texture_ref.get(), GL_TEXTURE_WRAP_S,
72 GL_CLAMP_TO_EDGE);
73 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
74 texture_ref.get(), GL_TEXTURE_WRAP_T,
75 GL_CLAMP_TO_EDGE);
76
77 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
78 texture_ref.get(), GL_TEXTURE_BASE_LEVEL, 0);
79 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
80 texture_ref.get(), GL_TEXTURE_MAX_LEVEL, 0);
81
82 // TODO(sandersd): Do we always want to allocate for GL_TEXTURE_2D?
83 if (target == GL_TEXTURE_2D) {
84 glTexImage2D(target, // target
85 0, // level
86 internal_format, // internal_format
87 width, // width
88 height, // height
89 0, // border
90 format, // format
91 type, // type
92 nullptr); // data
93 }
94
95 decoder_->RestoreActiveTextureUnitBinding(target);
96 return texture_ref;
97 }
98
99 base::Optional<gpu::Mailbox> CreateMailbox(
100 gpu::gles2::TextureRef* texture_ref) override {
101 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
102 gpu::gles2::ContextGroup* group = decoder_->GetContextGroup();
103 if (!group)
piman 2017/07/06 22:30:50 nit: ditto
sandersd (OOO until July 31) 2017/07/06 22:47:11 Done.
104 return base::nullopt;
105 gpu::gles2::MailboxManager* mailbox_manager = group->mailbox_manager();
106 if (!mailbox_manager)
piman 2017/07/06 22:30:50 nit: also never null Which means, you don't need
sandersd (OOO until July 31) 2017/07/06 22:47:11 Done.
107 return base::nullopt;
108 gpu::Mailbox mailbox = gpu::Mailbox::Generate();
109 mailbox_manager->ProduceTexture(mailbox, texture_ref->texture());
110 return mailbox;
111 }
112
113 private:
114 gpu::gles2::GLES2Decoder* decoder_;
115 THREAD_CHECKER(thread_checker_);
116
117 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderHelperImpl);
118 };
119
120 // static
121 std::unique_ptr<GLES2DecoderHelper> GLES2DecoderHelper::Create(
122 gpu::gles2::GLES2Decoder* decoder) {
123 if (!decoder)
124 return nullptr;
125 return base::MakeUnique<GLES2DecoderHelperImpl>(decoder);
126 }
127
128 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/gles2_decoder_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698