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

Side by Side Diff: media/renderers/skcanvas_video_renderer.cc

Issue 1508903002: Use GrGLTextureInfo for Skia texture handles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ignore_gl_target
Patch Set: Set target type in from mailbox in skcanvas_video_renderer Created 4 years, 9 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 | « content/renderer/media/android/webmediaplayer_android.cc ('k') | skia/config/SkUserConfig.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/renderers/skcanvas_video_renderer.h" 5 #include "media/renderers/skcanvas_video_renderer.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "gpu/GLES2/gl2extchromium.h" 10 #include "gpu/GLES2/gl2extchromium.h"
11 #include "gpu/command_buffer/client/gles2_interface.h" 11 #include "gpu/command_buffer/client/gles2_interface.h"
12 #include "gpu/command_buffer/common/mailbox_holder.h" 12 #include "gpu/command_buffer/common/mailbox_holder.h"
13 #include "media/base/video_frame.h" 13 #include "media/base/video_frame.h"
14 #include "media/base/yuv_convert.h" 14 #include "media/base/yuv_convert.h"
15 #include "skia/ext/refptr.h" 15 #include "skia/ext/refptr.h"
16 #include "skia/ext/texture_handle.h"
16 #include "third_party/libyuv/include/libyuv.h" 17 #include "third_party/libyuv/include/libyuv.h"
17 #include "third_party/skia/include/core/SkCanvas.h" 18 #include "third_party/skia/include/core/SkCanvas.h"
18 #include "third_party/skia/include/core/SkImage.h" 19 #include "third_party/skia/include/core/SkImage.h"
19 #include "third_party/skia/include/core/SkImageGenerator.h" 20 #include "third_party/skia/include/core/SkImageGenerator.h"
20 #include "third_party/skia/include/gpu/GrContext.h" 21 #include "third_party/skia/include/gpu/GrContext.h"
21 #include "third_party/skia/include/gpu/GrPaint.h" 22 #include "third_party/skia/include/gpu/GrPaint.h"
22 #include "third_party/skia/include/gpu/GrTexture.h" 23 #include "third_party/skia/include/gpu/GrTexture.h"
23 #include "third_party/skia/include/gpu/GrTextureProvider.h" 24 #include "third_party/skia/include/gpu/GrTextureProvider.h"
24 #include "third_party/skia/include/gpu/SkGr.h" 25 #include "third_party/skia/include/gpu/SkGr.h"
26 #include "third_party/skia/include/gpu/gl/GrGLTypes.h"
25 #include "ui/gfx/geometry/rect_f.h" 27 #include "ui/gfx/geometry/rect_f.h"
26 #include "ui/gfx/skia_util.h" 28 #include "ui/gfx/skia_util.h"
27 29
28 // Skia internal format depends on a platform. On Android it is ABGR, on others 30 // Skia internal format depends on a platform. On Android it is ABGR, on others
29 // it is ARGB. 31 // it is ARGB.
30 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \ 32 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \
31 SK_A32_SHIFT == 24 33 SK_A32_SHIFT == 24
32 #define LIBYUV_I420_TO_ARGB libyuv::I420ToARGB 34 #define LIBYUV_I420_TO_ARGB libyuv::I420ToARGB
33 #define LIBYUV_I422_TO_ARGB libyuv::I422ToARGB 35 #define LIBYUV_I422_TO_ARGB libyuv::I422ToARGB
34 #define LIBYUV_I444_TO_ARGB libyuv::I444ToARGB 36 #define LIBYUV_I444_TO_ARGB libyuv::I444ToARGB
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 DCHECK(video_frame->HasTextures()); 90 DCHECK(video_frame->HasTextures());
89 DCHECK_EQ(media::PIXEL_FORMAT_I420, video_frame->format()); 91 DCHECK_EQ(media::PIXEL_FORMAT_I420, video_frame->format());
90 DCHECK_EQ(3u, media::VideoFrame::NumPlanes(video_frame->format())); 92 DCHECK_EQ(3u, media::VideoFrame::NumPlanes(video_frame->format()));
91 93
92 gpu::gles2::GLES2Interface* gl = context_3d.gl; 94 gpu::gles2::GLES2Interface* gl = context_3d.gl;
93 DCHECK(gl); 95 DCHECK(gl);
94 gfx::Size ya_tex_size = video_frame->coded_size(); 96 gfx::Size ya_tex_size = video_frame->coded_size();
95 gfx::Size uv_tex_size((ya_tex_size.width() + 1) / 2, 97 gfx::Size uv_tex_size((ya_tex_size.width() + 1) / 2,
96 (ya_tex_size.height() + 1) / 2); 98 (ya_tex_size.height() + 1) / 2);
97 99
98 unsigned source_textures[3] = {0}; 100 GrGLTextureInfo source_textures[] = {{0, 0}, {0, 0}, {0, 0}};
99 for (size_t i = 0; i < media::VideoFrame::NumPlanes(video_frame->format()); 101 for (size_t i = 0; i < media::VideoFrame::NumPlanes(video_frame->format());
100 ++i) { 102 ++i) {
101 // Get the texture from the mailbox and wrap it in a GrTexture. 103 // Get the texture from the mailbox and wrap it in a GrTexture.
102 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); 104 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i);
103 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D || 105 DCHECK(mailbox_holder.texture_target == GL_TEXTURE_2D ||
104 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES || 106 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES ||
105 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB); 107 mailbox_holder.texture_target == GL_TEXTURE_RECTANGLE_ARB);
106 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); 108 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData());
107 source_textures[i] = gl->CreateAndConsumeTextureCHROMIUM( 109 source_textures[i].fID = gl->CreateAndConsumeTextureCHROMIUM(
108 mailbox_holder.texture_target, mailbox_holder.mailbox.name); 110 mailbox_holder.texture_target, mailbox_holder.mailbox.name);
111 source_textures[i].fTarget = mailbox_holder.texture_target;
109 112
110 // TODO(dcastagna): avoid this copy once Skia supports native textures 113 // TODO(dcastagna): avoid this copy once Skia supports native textures
111 // with a texture target different than TEXTURE_2D. 114 // with a texture target different than TEXTURE_2D.
112 // crbug.com/505026 115 // crbug.com/505026
113 if (mailbox_holder.texture_target != GL_TEXTURE_2D) { 116 if (mailbox_holder.texture_target != GL_TEXTURE_2D) {
114 unsigned texture_copy = 0; 117 unsigned texture_copy = 0;
115 gl->GenTextures(1, &texture_copy); 118 gl->GenTextures(1, &texture_copy);
116 DCHECK(texture_copy); 119 DCHECK(texture_copy);
117 gl->BindTexture(GL_TEXTURE_2D, texture_copy); 120 gl->BindTexture(GL_TEXTURE_2D, texture_copy);
118 gl->CopyTextureCHROMIUM(source_textures[i], texture_copy, GL_RGB, 121 gl->CopyTextureCHROMIUM(source_textures[i].fID, texture_copy, GL_RGB,
119 GL_UNSIGNED_BYTE, false, true, false); 122 GL_UNSIGNED_BYTE, false, true, false);
120 123
121 gl->DeleteTextures(1, &source_textures[i]); 124 gl->DeleteTextures(1, &source_textures[i].fID);
122 source_textures[i] = texture_copy; 125 source_textures[i].fID = texture_copy;
126 source_textures[i].fTarget = GL_TEXTURE_2D;
123 } 127 }
124 } 128 }
125 DCHECK_LE(source_textures[0], 129 GrBackendObject handles[3] = {
126 static_cast<unsigned>(std::numeric_limits<int>::max())); 130 skia::GrGLTextureInfoToGrBackendObject(source_textures[0]),
127 DCHECK_LE(source_textures[1], 131 skia::GrGLTextureInfoToGrBackendObject(source_textures[1]),
128 static_cast<unsigned>(std::numeric_limits<int>::max())); 132 skia::GrGLTextureInfoToGrBackendObject(source_textures[2])};
129 DCHECK_LE(source_textures[2],
130 static_cast<unsigned>(std::numeric_limits<int>::max()));
131 GrBackendObject handles[3] = {static_cast<int>(source_textures[0]),
132 static_cast<int>(source_textures[1]),
133 static_cast<int>(source_textures[2])};
134 133
135 SkISize yuvSizes[] = { 134 SkISize yuvSizes[] = {
136 {ya_tex_size.width(), ya_tex_size.height()}, 135 {ya_tex_size.width(), ya_tex_size.height()},
137 {uv_tex_size.width(), uv_tex_size.height()}, 136 {uv_tex_size.width(), uv_tex_size.height()},
138 {uv_tex_size.width(), uv_tex_size.height()}, 137 {uv_tex_size.width(), uv_tex_size.height()},
139 }; 138 };
140 139
141 SkYUVColorSpace color_space = kRec601_SkYUVColorSpace; 140 SkYUVColorSpace color_space = kRec601_SkYUVColorSpace;
142 if (CheckColorSpace(video_frame, media::COLOR_SPACE_JPEG)) 141 if (CheckColorSpace(video_frame, media::COLOR_SPACE_JPEG))
143 color_space = kJPEG_SkYUVColorSpace; 142 color_space = kJPEG_SkYUVColorSpace;
144 else if (CheckColorSpace(video_frame, media::COLOR_SPACE_HD_REC709)) 143 else if (CheckColorSpace(video_frame, media::COLOR_SPACE_HD_REC709))
145 color_space = kRec709_SkYUVColorSpace; 144 color_space = kRec709_SkYUVColorSpace;
146 145
147 SkImage* img = SkImage::NewFromYUVTexturesCopy(context_3d.gr_context, 146 SkImage* img = SkImage::NewFromYUVTexturesCopy(context_3d.gr_context,
148 color_space, handles, yuvSizes, 147 color_space, handles, yuvSizes,
149 kTopLeft_GrSurfaceOrigin); 148 kTopLeft_GrSurfaceOrigin);
150 gl->DeleteTextures(3, source_textures); 149 for (size_t i = 0; i < media::VideoFrame::NumPlanes(video_frame->format());
150 ++i) {
151 gl->DeleteTextures(1, &source_textures[i].fID);
152 }
151 return skia::AdoptRef(img); 153 return skia::AdoptRef(img);
152 } 154 }
153 155
154 // Creates a SkImage from a |video_frame| backed by native resources. 156 // Creates a SkImage from a |video_frame| backed by native resources.
155 // The SkImage will take ownership of the underlying resource. 157 // The SkImage will take ownership of the underlying resource.
156 skia::RefPtr<SkImage> NewSkImageFromVideoFrameNative( 158 skia::RefPtr<SkImage> NewSkImageFromVideoFrameNative(
157 VideoFrame* video_frame, 159 VideoFrame* video_frame,
158 const Context3D& context_3d) { 160 const Context3D& context_3d) {
159 DCHECK(PIXEL_FORMAT_ARGB == video_frame->format() || 161 DCHECK(PIXEL_FORMAT_ARGB == video_frame->format() ||
160 PIXEL_FORMAT_XRGB == video_frame->format() || 162 PIXEL_FORMAT_XRGB == video_frame->format() ||
(...skipping 22 matching lines...) Expand all
183 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData()); 185 gl->WaitSyncTokenCHROMIUM(mailbox_holder.sync_token.GetConstData());
184 source_texture = gl->CreateAndConsumeTextureCHROMIUM( 186 source_texture = gl->CreateAndConsumeTextureCHROMIUM(
185 mailbox_holder.texture_target, mailbox_holder.mailbox.name); 187 mailbox_holder.texture_target, mailbox_holder.mailbox.name);
186 } 188 }
187 GrBackendTextureDesc desc; 189 GrBackendTextureDesc desc;
188 desc.fFlags = kRenderTarget_GrBackendTextureFlag; 190 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
189 desc.fOrigin = kTopLeft_GrSurfaceOrigin; 191 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
190 desc.fWidth = video_frame->coded_size().width(); 192 desc.fWidth = video_frame->coded_size().width();
191 desc.fHeight = video_frame->coded_size().height(); 193 desc.fHeight = video_frame->coded_size().height();
192 desc.fConfig = kRGBA_8888_GrPixelConfig; 194 desc.fConfig = kRGBA_8888_GrPixelConfig;
193 DCHECK_LE(source_texture, 195 GrGLTextureInfo source_texture_info;
194 static_cast<unsigned>(std::numeric_limits<int>::max())); 196 source_texture_info.fID = source_texture;
195 desc.fTextureHandle = static_cast<int>(source_texture); 197 source_texture_info.fTarget = GL_TEXTURE_2D;
198 desc.fTextureHandle =
199 skia::GrGLTextureInfoToGrBackendObject(source_texture_info);
196 return skia::AdoptRef( 200 return skia::AdoptRef(
197 SkImage::NewFromAdoptedTexture(context_3d.gr_context, desc)); 201 SkImage::NewFromAdoptedTexture(context_3d.gr_context, desc));
198 } 202 }
199 203
200 } // anonymous namespace 204 } // anonymous namespace
201 205
202 // Generates an RGB image from a VideoFrame. Convert YUV to RGB plain on GPU. 206 // Generates an RGB image from a VideoFrame. Convert YUV to RGB plain on GPU.
203 class VideoImageGenerator : public SkImageGenerator { 207 class VideoImageGenerator : public SkImageGenerator {
204 public: 208 public:
205 VideoImageGenerator(const scoped_refptr<VideoFrame>& frame) 209 VideoImageGenerator(const scoped_refptr<VideoFrame>& frame)
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 } 663 }
660 664
661 void SkCanvasVideoRenderer::ResetCache() { 665 void SkCanvasVideoRenderer::ResetCache() {
662 DCHECK(thread_checker_.CalledOnValidThread()); 666 DCHECK(thread_checker_.CalledOnValidThread());
663 // Clear cached values. 667 // Clear cached values.
664 last_image_ = nullptr; 668 last_image_ = nullptr;
665 last_timestamp_ = kNoTimestamp(); 669 last_timestamp_ = kNoTimestamp();
666 } 670 }
667 671
668 } // namespace media 672 } // namespace media
OLDNEW
« no previous file with comments | « content/renderer/media/android/webmediaplayer_android.cc ('k') | skia/config/SkUserConfig.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698