Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EGL/GLES graphics tracing #4020

Draft
wants to merge 4 commits into
base: 23.lts.1+
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cobalt/loader/image/image_data_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,18 @@ std::unique_ptr<render_tree::ImageData> ImageDataDecoder::AllocateImageData(
size, pixel_format(),
has_alpha ? render_tree::kAlphaFormatPremultiplied
: render_tree::kAlphaFormatOpaque);
DLOG_IF(ERROR, !image_data) << "Failed to allocate image data ("
LOG_IF(ERROR, !image_data) << "Failed to allocate image data ("
<< size.width() << "x" << size.height() << ").";
return image_data;
}

scoped_refptr<Image> ImageDataDecoder::CreateStaticImage(
std::unique_ptr<render_tree::ImageData> image_data) {
DCHECK(image_data);
return new StaticImage(
resource_provider()->CreateImage(std::move(image_data)));
auto img = resource_provider()->CreateImage(std::move(image_data));
auto sz = img->GetEstimatedSizeInBytes();
LOG(WARNING) << "Allocated " << sz << " bytes StaticImage";
return new StaticImage(std::move(img));
}

void ImageDataDecoder::CalculatePixelFormat() {
Expand Down
2 changes: 1 addition & 1 deletion cobalt/loader/resource_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ void ResourceCache<CacheType>::ReclaimMemory(uint32 bytes_to_reclaim_down_to,
// Log a warning if we're still over |bytes_to_reclaim_down_to| after
// attempting to reclaim memory. This can occur validly when the size of
// the referenced images exceeds the target size.
DLOG_IF(WARNING, memory_size_in_bytes_ > bytes_to_reclaim_down_to)
LOG_IF(WARNING, memory_size_in_bytes_ > bytes_to_reclaim_down_to)
<< "cached size: " << memory_size_in_bytes_
<< ", target size: " << bytes_to_reclaim_down_to;
}
Expand Down
1 change: 1 addition & 0 deletions cobalt/renderer/backend/egl/framebuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ FramebufferEGL::FramebufferEGL(GraphicsContextEGL* graphics_context,
color_texture_.reset(new TextureEGL(graphics_context_, color_handle, size_,
color_format, GL_TEXTURE_2D,
base::Closure()));
LOG(WARNING) << "FramebufferEGL::FramebufferEGL new textureEGL: " << color_texture_->gl_handle();

// Create and attach a depth buffer if requested.
depthbuffer_handle_ = 0;
Expand Down
11 changes: 9 additions & 2 deletions cobalt/renderer/backend/egl/graphics_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,11 @@ void GraphicsContextEGL::ReleaseCurrentContext() {

std::unique_ptr<TextureEGL> GraphicsContextEGL::CreateTexture(
std::unique_ptr<TextureDataEGL> texture_data) {
return std::unique_ptr<TextureEGL>(

auto ret = std::unique_ptr<TextureEGL>(
new TextureEGL(this, std::move(texture_data), bgra_format_supported_));
LOG(WARNING) << "GraphicsContextEGL::CreateTexture:" << ret->gl_handle();
return ret;
}

std::unique_ptr<TextureEGL> GraphicsContextEGL::CreateTextureFromRawMemory(
Expand All @@ -371,9 +374,12 @@ std::unique_ptr<TextureEGL> GraphicsContextEGL::CreateTextureFromRawMemory(
const RawTextureMemoryEGL* texture_memory =
&(raw_texture_memory->raw_texture_memory());

return std::unique_ptr<TextureEGL>(

auto ret = std::unique_ptr<TextureEGL>(
new TextureEGL(this, texture_memory, offset, size, format, pitch_in_bytes,
bgra_format_supported_));
LOG(WARNING) << "GraphicsContextEGL::CreateTextureFromRawMemory: " << ret->gl_handle();
return ret;
}

scoped_refptr<RenderTarget> GraphicsContextEGL::CreateOffscreenRenderTarget(
Expand Down Expand Up @@ -439,6 +445,7 @@ std::unique_ptr<uint8_t[]> GraphicsContextEGL::DownloadPixelDataAsRGBA(
std::unique_ptr<TextureEGL> texture(
new TextureEGL(this, pbuffer_render_target));
DCHECK(texture->GetSize() == render_target->GetSize());
LOG(WARNING) << "GraphicsContextEGL::DownloadPixelDataAsRGBA:" << texture->gl_handle();

// This shouldn't be strictly necessary as glReadPixels() should implicitly
// call glFinish(), however it doesn't hurt to be safe and guard against
Expand Down
4 changes: 4 additions & 0 deletions cobalt/renderer/backend/egl/texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ TextureEGL::TextureEGL(GraphicsContextEGL* graphics_context,
target_(GL_TEXTURE_2D) {
gl_handle_ =
texture_source_data->ConvertToTexture(graphics_context_, bgra_supported);
LOG(WARNING) << "TextureEGL::TextureEGL (ConvertToTexture)" << gl_handle_;
}

TextureEGL::TextureEGL(GraphicsContextEGL* graphics_context,
Expand All @@ -58,6 +59,7 @@ TextureEGL::TextureEGL(GraphicsContextEGL* graphics_context,
target_(GL_TEXTURE_2D) {
gl_handle_ = data->CreateTexture(graphics_context_, offset, size, format,
pitch_in_bytes, bgra_supported);
LOG(WARNING) << "TextureEGL::TextureEGL (CreateTexture)" << gl_handle_;
}

TextureEGL::TextureEGL(GraphicsContextEGL* graphics_context, GLuint gl_handle,
Expand Down Expand Up @@ -98,6 +100,7 @@ TextureEGL::TextureEGL(GraphicsContextEGL* graphics_context,
pbuffer_target->GetSurface(), EGL_BACK_BUFFER));

GL_CALL(glBindTexture(GL_TEXTURE_2D, 0));
LOG(WARNING) << "TextureEGL::TextureEGL (render_target, has surface)" << gl_handle_;
} else {
// This is a FramebufferRenderTargetEGL. Wrap its color texture attachment.
const FramebufferRenderTargetEGL* framebuffer_target =
Expand All @@ -111,6 +114,7 @@ TextureEGL::TextureEGL(GraphicsContextEGL* graphics_context,

// Do not destroy the wrapped texture. Let the render target do that.
delete_function_ = base::Bind(&DoNothing);
LOG(WARNING) << "TextureEGL::TextureEGL (render_target, no surface)" << gl_handle_;
}
}

Expand Down
3 changes: 2 additions & 1 deletion cobalt/renderer/backend/egl/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define COBALT_RENDERER_BACKEND_EGL_TEXTURE_H_

#include <memory>

#include "base/callback.h"
#include "cobalt/renderer/backend/egl/render_target.h"
#include "cobalt/renderer/backend/egl/texture_data.h"
Expand Down Expand Up @@ -83,7 +84,7 @@ class TextureEGL {
GLenum target_;

// The OpenGL handle to the texture that can be passed into OpenGL functions.
GLuint gl_handle_;
GLuint gl_handle_ = 0;

// If the texture was constructed from a render target, we keep a reference
// to the render target.
Expand Down
3 changes: 2 additions & 1 deletion cobalt/renderer/backend/egl/texture_data_cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "cobalt/renderer/backend/egl/texture_data_cpu.h"

#include <memory>

#include "base/memory/aligned_memory.h"
#include "cobalt/renderer/backend/egl/graphics_context.h"
#include "cobalt/renderer/backend/egl/utils.h"
Expand All @@ -31,7 +32,7 @@ GLuint UploadPixelDataToNewTexture(GraphicsContextEGL* graphics_context,
const uint8_t* data, const math::Size& size,
GLenum format, int pitch_in_bytes,
bool bgra_supported) {
GLuint texture_handle;
GLuint texture_handle = 0;

GraphicsContextEGL::ScopedMakeCurrent scoped_make_current(graphics_context);

Expand Down
1 change: 1 addition & 0 deletions cobalt/renderer/rasterizer/egl/software_rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void SoftwareRasterizer::Submit(
// The rasterized pixels are still on the CPU, ship them off to the GPU
// for output to the display. We must first create a backend GPU texture
// with the data so that it is visible to the GPU.
LOG(WARNING) << "SoftwareRasterizer::Submit creating Texture";
std::unique_ptr<backend::TextureEGL> output_texture =
context_->CreateTexture(std::move(bitmap_pixels));

Expand Down
13 changes: 13 additions & 0 deletions cobalt/renderer/rasterizer/skia/hardware_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class HardwareFrontendImage::HardwareBackendImage {
"HardwareBackendImage::InitializeFromImageData()");
backend->texture_ =
cobalt_context->CreateTexture(image_data->PassTextureData());
LOG(WARNING) << "HardwareBackendImage::InitializeFromImageData:" << backend->texture_->gl_handle();
backend->CommonInitialize(gr_context, cobalt_context);
}

Expand All @@ -151,6 +152,7 @@ class HardwareFrontendImage::HardwareBackendImage {
texture_memory, offset, descriptor.size,
ConvertRenderTreeFormatToGL(descriptor.pixel_format),
descriptor.pitch_in_bytes);
LOG(WARNING) << "HardwareBackendImage::InitializeFromRawImageData:" << backend->texture_->gl_handle();
backend->CommonInitialize(gr_context, cobalt_context);
}

Expand All @@ -160,6 +162,7 @@ class HardwareFrontendImage::HardwareBackendImage {
TRACE_EVENT0("cobalt::renderer",
"HardwareBackendImage::InitializeFromTexture()");
backend->texture_ = std::move(texture);
LOG(WARNING) << "HardwareBackendImage::InitializeFromTexture:" << backend->texture_->gl_handle();
backend::GraphicsContextEGL* cobalt_context =
backend->texture_->graphics_context();
backend->CommonInitialize(gr_context, cobalt_context);
Expand Down Expand Up @@ -187,6 +190,7 @@ class HardwareFrontendImage::HardwareBackendImage {

std::unique_ptr<backend::TextureEGL> texture(
new backend::TextureEGL(cobalt_context, render_target));
LOG(WARNING) << "HardwareFrontEndImage::InitializeFromRenderTree: " << texture->gl_handle();

InitializeFromTexture(std::move(texture), gr_context, backend);

Expand Down Expand Up @@ -297,6 +301,11 @@ math::Size AdjustSizeForFormat(
}
} // namespace

#define LHANDLE(message, backend_image) \
{ \
LOG(WARNING) << message; \
}

HardwareFrontendImage::HardwareFrontendImage(
std::unique_ptr<HardwareImageData> image_data,
backend::GraphicsContextEGL* cobalt_context, GrContext* gr_context,
Expand All @@ -311,6 +320,7 @@ HardwareFrontendImage::HardwareFrontendImage(
backend_image_.reset(new HardwareBackendImage(
base::Bind(&HardwareBackendImage::InitializeFromImageData,
base::Passed(&image_data), cobalt_context, gr_context)));
LHANDLE("HardwareFrontendImage::HardwareFrontendImage 1 (HardwareImageData) : ",backend_image_);
InitializeBackend();
}

Expand All @@ -329,6 +339,7 @@ HardwareFrontendImage::HardwareFrontendImage(
backend_image_.reset(new HardwareBackendImage(base::Bind(
&HardwareBackendImage::InitializeFromRawImageData, raw_texture_memory,
offset, descriptor, cobalt_context, gr_context)));
LHANDLE("HardwareFrontendImage::HardwareFrontendImage 2 (ConstRawTextureMemoryEGL) : ",backend_image_);
InitializeBackend();
}

Expand All @@ -353,6 +364,7 @@ HardwareFrontendImage::HardwareFrontendImage(
backend_image_.reset(new HardwareBackendImage(
base::Bind(&HardwareBackendImage::InitializeFromTexture,
base::Passed(&texture), gr_context)));
LHANDLE("HardwareFrontendImage::HardwareFrontendImage 3 (backend::TextureEGL) : ",backend_image_);
InitializeBackend();
}

Expand All @@ -372,6 +384,7 @@ HardwareFrontendImage::HardwareFrontendImage(
backend_image_.reset(new HardwareBackendImage(
base::Bind(&HardwareBackendImage::InitializeFromRenderTree, root, size_,
submit_offscreen_callback, cobalt_context, gr_context)));
LHANDLE("HardwareFrontendImage::HardwareFrontendImage 4 (render_tree::Node) : ",backend_image_);
InitializeBackend();
}

Expand Down
5 changes: 5 additions & 0 deletions cobalt/renderer/rasterizer/skia/hardware_resource_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ scoped_refptr<render_tree::Image> HardwareResourceProvider::CreateImage(
}
#endif

LOG(WARNING) << "HardwareResourceProvider::CreateImage HardwareFrontendImage";
// Construct a frontend image from this data, which internally will send
// a message to the rasterizer thread passing along the image data where the
// backend texture will be constructed, and associated with this frontend
Expand Down Expand Up @@ -307,6 +308,7 @@ HardwareResourceProvider::CreateImageFromSbDecodeTarget(
cobalt_context_, gl_handle, math::Size(plane.width, plane.height),
gl_format, plane.gl_texture_target,
base::BindOnce(&DoNothing, decode_target_ref)));
LOG(WARNING) << "HardwareResourceProvider::CreateImageFromSbDecodeTarget: " << texture->gl_handle();

// If the decode target is specified as UYVY format, then we need to pass
// this in as supplementary data, as the |texture| object only knows that
Expand All @@ -316,6 +318,7 @@ HardwareResourceProvider::CreateImageFromSbDecodeTarget(
alternate_rgba_format = AlternateRgbaFormat_UYVY;
}

LOG(WARNING) << "HardwareResourceProvider::CreateImageFromSbDecodeTarget HardwareFrontendImage";
planes.push_back(base::WrapRefCounted(new HardwareFrontendImage(
std::move(texture), alpha_format, cobalt_context_, gr_context_,
std::move(content_region), rasterizer_task_runner_,
Expand All @@ -325,6 +328,7 @@ HardwareResourceProvider::CreateImageFromSbDecodeTarget(
if (planes_per_format == 1) {
return planes[0];
} else {
LOG(WARNING) << "HardwareResourceProvider::CreateImageFromSbDecodeTarget HardwareMultiPlaneImage";
return new HardwareMultiPlaneImage(
DecodeTargetFormatToRenderTreeMultiPlaneFormat(info.format), planes);
}
Expand Down Expand Up @@ -561,6 +565,7 @@ scoped_refptr<render_tree::Mesh> HardwareResourceProvider::CreateMesh(

scoped_refptr<render_tree::Image> HardwareResourceProvider::DrawOffscreenImage(
const scoped_refptr<render_tree::Node>& root) {
LOG(WARNING) << "HardwareResourceProvider::DrawOffscreenImage HardwareFrontendImage";
return base::WrapRefCounted(new HardwareFrontendImage(
root, submit_offscreen_callback_, cobalt_context_, gr_context_,
rasterizer_task_runner_));
Expand Down
2 changes: 2 additions & 0 deletions cobalt/renderer/rasterizer/skia/software_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ std::unique_ptr<uint8_t[]> SoftwareImageData::PassPixelData() {
}

SoftwareImage::SoftwareImage(std::unique_ptr<SoftwareImageData> source_data) {
LOG(WARNING) << "SoftwareImage::SoftwareImage (SoftwareImageData)";
owned_pixel_data_ = source_data->PassPixelData();
Initialize(owned_pixel_data_.get(), source_data->GetDescriptor());
}

SoftwareImage::SoftwareImage(
uint8_t* source_data, const render_tree::ImageDataDescriptor& descriptor) {
LOG(WARNING) << "SoftwareImage::SoftwareImage (ImageDataDescriptor)";
Initialize(source_data, descriptor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ scoped_refptr<render_tree::Image> SoftwareResourceProvider::CreateImage(
std::unique_ptr<SoftwareImageData> skia_source_data(
base::polymorphic_downcast<SoftwareImageData*>(source_data.release()));

LOG(WARNING) << "SoftwareResourceProvider::CreateImage making SoftwareImage";
return scoped_refptr<render_tree::Image>(
new SoftwareImage(std::move(skia_source_data)));
}
Expand Down
Loading