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

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

Issue 2938543005: media: Add GLES2DecoderHelper (Closed)
Patch Set: Don't check for guaranteed non-nulls. 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/context_group.h"
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 "ui/gl/gl_context.h"
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 DCHECK(decoder_->GetGLContext()->IsCurrent(nullptr));
37 gpu::gles2::ContextGroup* group = decoder_->GetContextGroup();
38 gpu::gles2::TextureManager* texture_manager = group->texture_manager();
39 // TODO(sandersd): Support GLES2DecoderPassthroughImpl.
40 DCHECK(texture_manager);
41
42 // We can't use texture_manager->CreateTexture(), since it requires a unique
43 // |client_id|. Instead we create the texture directly, and create our own
44 // TextureRef for it.
45 GLuint texture_id;
46 glGenTextures(1, &texture_id);
47 glBindTexture(target, texture_id);
48
49 scoped_refptr<gpu::gles2::TextureRef> texture_ref =
50 gpu::gles2::TextureRef::Create(texture_manager, 0, texture_id);
51 texture_manager->SetTarget(texture_ref.get(), target);
52 texture_manager->SetLevelInfo(texture_ref.get(), // ref
53 target, // target
54 0, // level
55 internal_format, // internal_format
56 width, // width
57 height, // height
58 1, // depth
59 0, // border
60 format, // format
61 type, // type
62 gfx::Rect()); // cleared_rect
63
64 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
65 texture_ref.get(), GL_TEXTURE_MAG_FILTER,
66 GL_LINEAR);
67 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
68 texture_ref.get(), GL_TEXTURE_MIN_FILTER,
69 GL_LINEAR);
70
71 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
72 texture_ref.get(), GL_TEXTURE_WRAP_S,
73 GL_CLAMP_TO_EDGE);
74 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
75 texture_ref.get(), GL_TEXTURE_WRAP_T,
76 GL_CLAMP_TO_EDGE);
77
78 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
79 texture_ref.get(), GL_TEXTURE_BASE_LEVEL, 0);
80 texture_manager->SetParameteri(__func__, decoder_->GetErrorState(),
81 texture_ref.get(), GL_TEXTURE_MAX_LEVEL, 0);
82
83 // TODO(sandersd): Do we always want to allocate for GL_TEXTURE_2D?
84 if (target == GL_TEXTURE_2D) {
85 glTexImage2D(target, // target
86 0, // level
87 internal_format, // internal_format
88 width, // width
89 height, // height
90 0, // border
91 format, // format
92 type, // type
93 nullptr); // data
94 }
95
96 decoder_->RestoreActiveTextureUnitBinding(target);
97 return texture_ref;
98 }
99
100 gpu::Mailbox CreateMailbox(gpu::gles2::TextureRef* texture_ref) override {
101 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
102 gpu::gles2::ContextGroup* group = decoder_->GetContextGroup();
103 gpu::gles2::MailboxManager* mailbox_manager = group->mailbox_manager();
104 gpu::Mailbox mailbox = gpu::Mailbox::Generate();
105 mailbox_manager->ProduceTexture(mailbox, texture_ref->texture());
106 return mailbox;
107 }
108
109 private:
110 gpu::gles2::GLES2Decoder* decoder_;
111 THREAD_CHECKER(thread_checker_);
112
113 DISALLOW_COPY_AND_ASSIGN(GLES2DecoderHelperImpl);
114 };
115
116 // static
117 std::unique_ptr<GLES2DecoderHelper> GLES2DecoderHelper::Create(
118 gpu::gles2::GLES2Decoder* decoder) {
119 if (!decoder)
120 return nullptr;
121 return base::MakeUnique<GLES2DecoderHelperImpl>(decoder);
122 }
123
124 } // 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