<commit_before>// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "impeller/renderer/backend/gles/surface_gles.h"

#include "flutter/fml/trace_event.h"
#include "impeller/base/config.h"
#include "impeller/renderer/backend/gles/context_gles.h"
#include "impeller/renderer/backend/gles/texture_gles.h"

namespace impeller {

std::unique_ptr<Surface> SurfaceGLES::WrapFBO(std::shared_ptr<Context> context,
                                              SwapCallback swap_callback,
                                              GLuint fbo,
                                              PixelFormat color_format,
                                              ISize fbo_size) {
  TRACE_EVENT0("impeller", "SurfaceGLES::WrapOnScreenFBO");

  if (context == nullptr || !context->IsValid() || !swap_callback) {
    return nullptr;
  }

  const auto& gl_context = ContextGLES::Cast(*context);

  TextureDescriptor color0_tex;
  color0_tex.type = TextureType::kTexture2D;
  color0_tex.format = color_format;
  color0_tex.size = fbo_size;
  color0_tex.usage = static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
  color0_tex.sample_count = SampleCount::kCount1;

  ColorAttachment color0;
  color0.texture = std::make_shared<TextureGLES>(
      gl_context.GetReactor(), std::move(color0_tex),
      TextureGLES::IsWrapped::kWrapped);
  color0.clear_color = Color::DarkSlateGray();
  color0.load_action = LoadAction::kClear;
  color0.store_action = StoreAction::kStore;

  TextureDescriptor stencil0_tex;
  stencil0_tex.type = TextureType::kTexture2D;
  stencil0_tex.format = color_format;
  stencil0_tex.size = fbo_size;
  stencil0_tex.usage =
      static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
  stencil0_tex.sample_count = SampleCount::kCount1;

  StencilAttachment stencil0;
  stencil0.clear_stencil = 0;
  stencil0.texture = std::make_shared<TextureGLES>(
      gl_context.GetReactor(), std::move(stencil0_tex),
      TextureGLES::IsWrapped::kWrapped);
  stencil0.load_action = LoadAction::kClear;
  stencil0.store_action = StoreAction::kDontCare;

  RenderTarget render_target_desc;

  render_target_desc.SetColorAttachment(color0, 0u);
  render_target_desc.SetStencilAttachment(stencil0);

  return std::unique_ptr<SurfaceGLES>(
      new SurfaceGLES(std::move(swap_callback), std::move(render_target_desc)));
}

SurfaceGLES::SurfaceGLES(SwapCallback swap_callback, RenderTarget target_desc)
    : Surface(std::move(target_desc)),
      swap_callback_(std::move(swap_callback)) {}

// |Surface|
SurfaceGLES::~SurfaceGLES() = default;

// |Surface|
bool SurfaceGLES::Present() const {
  return swap_callback_ ? swap_callback_() : false;
}

}  // namespace impeller
<commit_msg>[Impeller] Make 'SurfaceGLES::WrapFBO' pass attachment validation (#35881)<commit_after>// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "impeller/renderer/backend/gles/surface_gles.h"

#include "flutter/fml/trace_event.h"
#include "impeller/base/config.h"
#include "impeller/renderer/backend/gles/context_gles.h"
#include "impeller/renderer/backend/gles/texture_gles.h"

namespace impeller {

std::unique_ptr<Surface> SurfaceGLES::WrapFBO(std::shared_ptr<Context> context,
                                              SwapCallback swap_callback,
                                              GLuint fbo,
                                              PixelFormat color_format,
                                              ISize fbo_size) {
  TRACE_EVENT0("impeller", "SurfaceGLES::WrapOnScreenFBO");

  if (context == nullptr || !context->IsValid() || !swap_callback) {
    return nullptr;
  }

  const auto& gl_context = ContextGLES::Cast(*context);

  TextureDescriptor color0_tex;
  color0_tex.type = TextureType::kTexture2D;
  color0_tex.format = color_format;
  color0_tex.size = fbo_size;
  color0_tex.usage = static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
  color0_tex.sample_count = SampleCount::kCount1;
  color0_tex.storage_mode = StorageMode::kDevicePrivate;

  ColorAttachment color0;
  color0.texture = std::make_shared<TextureGLES>(
      gl_context.GetReactor(), std::move(color0_tex),
      TextureGLES::IsWrapped::kWrapped);
  color0.clear_color = Color::DarkSlateGray();
  color0.load_action = LoadAction::kClear;
  color0.store_action = StoreAction::kStore;

  TextureDescriptor stencil0_tex;
  stencil0_tex.type = TextureType::kTexture2D;
  stencil0_tex.format = color_format;
  stencil0_tex.size = fbo_size;
  stencil0_tex.usage =
      static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
  stencil0_tex.sample_count = SampleCount::kCount1;

  StencilAttachment stencil0;
  stencil0.clear_stencil = 0;
  stencil0.texture = std::make_shared<TextureGLES>(
      gl_context.GetReactor(), std::move(stencil0_tex),
      TextureGLES::IsWrapped::kWrapped);
  stencil0.load_action = LoadAction::kClear;
  stencil0.store_action = StoreAction::kDontCare;

  RenderTarget render_target_desc;

  render_target_desc.SetColorAttachment(color0, 0u);
  render_target_desc.SetStencilAttachment(stencil0);

  return std::unique_ptr<SurfaceGLES>(
      new SurfaceGLES(std::move(swap_callback), std::move(render_target_desc)));
}

SurfaceGLES::SurfaceGLES(SwapCallback swap_callback, RenderTarget target_desc)
    : Surface(std::move(target_desc)),
      swap_callback_(std::move(swap_callback)) {}

// |Surface|
SurfaceGLES::~SurfaceGLES() = default;

// |Surface|
bool SurfaceGLES::Present() const {
  return swap_callback_ ? swap_callback_() : false;
}

}  // namespace impeller

{'fraction_non_alphanumeric': 0.10995128740431455, 'fraction_numerical': 0.013917884481558803, 'mean_word_length': 4.101153504880213, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1553218', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1812, 'n_words': 294}